Exemplo n.º 1
0
Arquivo: ext.go Projeto: kego/ke
func InitialiseAndGenerate(t *testing.T, cb *tests.ContextBuilder, name string, files map[string]string) (string, error) {
	path, _ := cb.TempPackage(name, files)
	ctx, _, err := process.Initialise(cb.Ctx(), &process.Options{
		Path: path,
	})
	if err != nil {
		return "", err
	}
	cb.SetCtx(ctx)
	source, err := generate.Structs(ctx, cb.Env())
	if err != nil {
		return "", err
	}
	return string(source), nil
}
Exemplo n.º 2
0
func runKe(cb *tests.ContextBuilder, name string, files map[string]string) (string, error) {

	tests := false
	for name, _ := range files {
		if strings.HasSuffix(name, "_test.go") {
			// if we add a xxx_test.go file we should also run "go test"
			tests = true
		}
	}

	path, _ := cb.RealGopath().TempPackage(name, files)

	ctx, _, err := process.Initialise(context.Background(), &process.Options{
		Path: path,
	})
	if err != nil {
		return "", err
	}

	env := envctx.FromContext(ctx)

	if err := process.Generate(ctx, env); err != nil {
		return "", err
	}

	if err := process.RunValidateCommand(ctx); err != nil {
		return "", err
	}

	if tests {
		if out, err := exec.Command("go", "test", path).CombinedOutput(); err != nil {
			return "", fmt.Errorf("%s", string(out))
		}
	}

	return env.Path, nil
}