Ejemplo n.º 1
0
// Validate is called by generated code.
func Validate(checksum string) {
	_, file, _, ok := runtime.Caller(1)
	if !ok {
		exit("Unable to resolve the test file from runtime.Caller(...).\n")
	}
	current, err := generate.Checksum(filepath.Dir(file))
	if err != nil {
		exit("Could not calculate checksum of current go files. Error: %s\n", err.Error())
	}
	if checksum != current {
		exit("The checksum provided [%s] does not match the current file listing [%s]. Please re-run the `gunit` command and try again.\n", checksum, current)
	}
}
Ejemplo n.º 2
0
func generateTestFileContents(pkg *build.Package, fixtures []*parse.Fixture) []byte {
	if len(fixtures) == 0 {
		return nil
	}

	checksum, err := generate.Checksum(pkg.Dir)
	fatal(err)

	code, err := generate.CodeListing(pkg.Dir)
	fatal(err)

	importName := pkg.Name
	if len(pkg.XTestGoFiles) > 0 {
		importName = fmt.Sprintf("%s_test", importName)
	}

	generated, err := generate.TestFile(importName, fixtures, checksum, code)
	fatal(err)

	return generated
}