diff --git a/.travis.yml b/.travis.yml index 52a3a96..adbca21 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: go go: - - 1.4 - 1.5 - 1.6 - tip diff --git a/README.md b/README.md index 7771487..5cf7fb7 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,9 @@ behavior. You can leverage both frameworks to functionally test your application while maintaining all test related source code in **_test.go** files. -**Godog** acts similar compared to **go test** command. It uses -a **TestMain** hook introduced in `go1.4` and clones the package sources -to a temporary build directory. The only change it does is adding a runner -test.go file additionally and ensures to cleanup TestMain func if it was -used in tests. **Godog** uses standard **go** ast and build utils to -generate test suite package and even builds it with **go test -c** -command. It even passes all your environment exported vars. +**Godog** acts similar compared to **go test** command. It uses go +compiler and linker tool in order to produce test executable. Godog +contexts needs to be exported same as Test functions for go test. **Godog** ships gherkin parser dependency as a subpackage. This will ensure that it is always compatible with the installed version of godog. @@ -193,6 +189,12 @@ See implementation examples: ### Changes +**2016-06-14** +- godog now uses **go tool compile** and **go tool link** to support + vendor directory dependencies. It also compiles test executable the same + way as standard **go test** utility. With this change, go only go + versions from **1.5** are now supported. + **2016-06-01** - parse flags in main command, to show version and help without needing to compile test package and buildable go sources. diff --git a/builder.go b/builder.go index 2a2e86e..bfee547 100644 --- a/builder.go +++ b/builder.go @@ -67,7 +67,7 @@ func Build() (string, error) { // go does it better out, err := exec.Command("go", "test", "-i").CombinedOutput() if err != nil { - return bin, fmt.Errorf("failed to compile package %s deps - %v, output - %s", pkg.Name, err, string(out)) + return bin, fmt.Errorf("failed to compile package %s:\n%s", pkg.Name, string(out)) } // let go do the dirty work and compile test @@ -84,7 +84,7 @@ func Build() (string, error) { // go has built. We will reuse it for our suite workdir. out, err = exec.Command("go", "test", "-c", "-work", "-o", temp).CombinedOutput() if err != nil { - return bin, fmt.Errorf("failed to compile tested package %s - %v, output - %s", pkg.Name, err, string(out)) + return bin, fmt.Errorf("failed to compile tested package %s:\n%s", pkg.Name, string(out)) } defer os.Remove(temp) @@ -116,11 +116,11 @@ func Build() (string, error) { return bin, err } + // @TODO: may be a case that godog dependency is not installed. may need to install it pkgDir := filepath.Join(godogPkg.PkgRoot, build.Default.GOOS+"_"+build.Default.GOARCH) pkgDirs := []string{testdir, workdir, pkgDir} // compile godog testmain package archive - var buf bytes.Buffer testMainPkgOut := filepath.Join(testdir, "main.a") args := []string{ "tool", "compile", @@ -129,6 +129,8 @@ func Build() (string, error) { "-p", "main", "-complete", } + // if godog library is in vendor directory + // link it with import map if i := strings.LastIndex(godogPkg.ImportPath, "vendor/"); i != -1 { args = append(args, "-importmap", godogImportPath+"="+godogPkg.ImportPath) } @@ -138,12 +140,9 @@ func Build() (string, error) { args = append(args, "-pack", testmain) cmd := exec.Command("go", args...) cmd.Env = os.Environ() - cmd.Stdout = &buf - cmd.Stderr = &buf - err = cmd.Run() + out, err = cmd.CombinedOutput() if err != nil { - fmt.Println("command:", cmd.Path, cmd.Args) - return bin, fmt.Errorf("failed to compile testmain package %v, output - %s", err, buf.String()) + return bin, fmt.Errorf("failed to compile testmain package:\n%s", string(out)) } // link test suite executable @@ -161,7 +160,7 @@ func Build() (string, error) { cmd.Env = os.Environ() out, err = cmd.CombinedOutput() if err != nil { - return bin, fmt.Errorf("failed to compile testmain package %v, output - %s", err, string(out)) + return bin, fmt.Errorf("failed to link test executable:\n%s", string(out)) } return bin, nil diff --git a/godog.go b/godog.go index 5fdcdbd..5bc9cb1 100644 --- a/godog.go +++ b/godog.go @@ -6,13 +6,9 @@ Godog does not intervene with the standard "go test" command and it's behavior. You can leverage both frameworks to functionally test your application while maintaining all test related source code in *_test.go files. -Godog acts similar compared to go test command. It leverages -a TestMain function introduced in go1.4 and clones the package sources -to a temporary build directory. The only change it does is adding a runner -test.go file and replaces TestMain func if it was used in tests. -Godog uses standard go ast and build utils to generate test suite package, -compiles it with go test -c command. It accepts all your environment exported -build related vars. +Godog acts similar compared to go test command. It uses go +compiler and linker tool in order to produce test executable. Godog +contexts needs to be exported same as Test functions for go test. For example, imagine you’re about to create the famous UNIX ls command. Before you begin, you describe how the feature should work, see the example below..