From 6e2c1b291a49dd2f7580b14267a0cacf502074c8 Mon Sep 17 00:00:00 2001 From: gedi Date: Fri, 17 Jun 2016 10:01:17 +0300 Subject: [PATCH] look into more vendor directories for godog package, fixes #35 --- builder.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/builder.go b/builder.go index a43fa9a..116fc6d 100644 --- a/builder.go +++ b/builder.go @@ -130,7 +130,7 @@ func Build() (string, error) { // but we need it for our testmain package. // So we look it up in available source paths // including vendor directory, supported since 1.5. - try := []string{filepath.Join(abs, "vendor", godogImportPath)} + try := maybeVendorPaths(abs) for _, d := range build.Default.SrcDirs() { try = append(try, filepath.Join(d, godogImportPath)) } @@ -261,6 +261,23 @@ func buildTestMain(pkg *build.Package) ([]byte, bool, error) { return buf.Bytes(), len(contexts) > 0, nil } +// maybeVendorPaths determines possible vendor paths +// which goes levels down from given directory +// until it reaches GOPATH source dir +func maybeVendorPaths(dir string) []string { + paths := []string{filepath.Join(dir, "vendor", godogImportPath)} + for _, gopath := range gopaths { + if !strings.HasPrefix(dir, gopath) { + continue + } + + for p := filepath.Dir(dir); p != filepath.Join(gopath, "src"); p = filepath.Dir(p) { + paths = append(paths, filepath.Join(p, "vendor", godogImportPath)) + } + } + return paths +} + // processPackageTestFiles runs through ast of each test // file pack and looks for godog suite contexts to register // on run