From d13013938bbc07194d48642599bf247f1b63e2bd Mon Sep 17 00:00:00 2001 From: Valeriy Bdtaev Date: Fri, 4 Mar 2016 15:19:11 +0300 Subject: [PATCH 1/3] fix crash for excludedDirs if run test for dir contains in excludedDirs comes crash goconvey! i added tiny function, checkExcludedDirs, which checks it. in my opinion, if the user specified directory for testing - it should be tested, regardless there is or not in the excludes... --- goconvey.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/goconvey.go b/goconvey.go index 4d5fc0ef..8458ea9c 100644 --- a/goconvey.go +++ b/goconvey.go @@ -64,7 +64,7 @@ func main() { watcherInput := make(chan messaging.WatcherCommand) watcherOutput := make(chan messaging.Folders) - excludedDirItems := strings.Split(excludedDirs, `,`) + excludedDirItems := checkExcludedDirs(excludedDirs, working) watcher := watch.NewWatcher(working, depth, nap, watcherInput, watcherOutput, watchedSuffixes, excludedDirItems) parser := parser.NewParser(parser.ParsePackageResults) @@ -80,6 +80,19 @@ func main() { serveHTTP(server) } +func checkExcludedDirs(s string, working string) []string { + var items []string + dirname := path.Base(working) + + for _, item := range strings.Split(excludedDirs, `,`) { + if item != dirname { + items = append(items, item) + } + } + + return items +} + func browserCmd() (string, bool) { browser := map[string]string{ "darwin": "open", From 19fe80bcaa73971684438ae4638b0b03ce3bb99f Mon Sep 17 00:00:00 2001 From: Valeriy Bdtaev Date: Sat, 5 Mar 2016 17:45:49 +0300 Subject: [PATCH 2/3] Update goconvey.go --- goconvey.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/goconvey.go b/goconvey.go index 8458ea9c..6a1646ef 100644 --- a/goconvey.go +++ b/goconvey.go @@ -82,7 +82,7 @@ func main() { func checkExcludedDirs(s string, working string) []string { var items []string - dirname := path.Base(working) + dirname := filepath.Base(working) for _, item := range strings.Split(excludedDirs, `,`) { if item != dirname { From 1ff2e6958deea47155c0791b0ecf8a143a74137c Mon Sep 17 00:00:00 2001 From: sg3des Date: Sat, 9 Apr 2016 09:22:32 +0300 Subject: [PATCH 3/3] add test for checkExcludedDirs --- examples/vendor/subpackage/subpackage.go | 6 +++++ examples/vendor/subpackage/subpackage_test.go | 14 +++++++++++ goconvey.go | 12 ++++++++- goconvey_test.go | 25 +++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 examples/vendor/subpackage/subpackage.go create mode 100644 examples/vendor/subpackage/subpackage_test.go create mode 100644 goconvey_test.go diff --git a/examples/vendor/subpackage/subpackage.go b/examples/vendor/subpackage/subpackage.go new file mode 100644 index 00000000..be5b41a7 --- /dev/null +++ b/examples/vendor/subpackage/subpackage.go @@ -0,0 +1,6 @@ +package subpackage + +//Echo just returns your string +func Echo(s string) string { + return s +} diff --git a/examples/vendor/subpackage/subpackage_test.go b/examples/vendor/subpackage/subpackage_test.go new file mode 100644 index 00000000..1da5eaac --- /dev/null +++ b/examples/vendor/subpackage/subpackage_test.go @@ -0,0 +1,14 @@ +package subpackage + +import ( + "testing" + + . "github.com/smartystreets/goconvey/convey" +) + +func TestEcho(t *testing.T) { + s := "Hello" + Convey("Test Echo", t, func() { + So(Echo(s), ShouldEqual, s) + }) +} diff --git a/goconvey.go b/goconvey.go index 6a1646ef..8ee01dd5 100644 --- a/goconvey.go +++ b/goconvey.go @@ -73,6 +73,7 @@ func main() { longpollChan := make(chan chan string) executor := executor.NewExecutor(tester, parser, longpollChan) + server := api.NewHTTPServer(working, watcherInput, executor, longpollChan) go runTestOnUpdates(watcherOutput, executor, server) go watcher.Listen() @@ -80,7 +81,9 @@ func main() { serveHTTP(server) } -func checkExcludedDirs(s string, working string) []string { +//checkExcludedDirs checks whether the working directory is contained in the list of excluded +//if is, then drop it from the excludedDirs +func checkExcludedDirs(excludedDirs string, working string) []string { var items []string dirname := filepath.Base(working) @@ -125,6 +128,13 @@ func runTestOnUpdates(queue chan messaging.Folders, executor contract.Executor, for update := range queue { log.Println("Received request from watcher to execute tests...") packages := extractPackages(update) + + //if extractPackages does not return packages + if len(packages) == 0 { + log.Println("Nothing to test, check the working directory") + continue + } + output := executor.ExecuteTests(packages) root := extractRoot(update, packages) server.ReceiveUpdate(root, output) diff --git a/goconvey_test.go b/goconvey_test.go new file mode 100644 index 00000000..f3468356 --- /dev/null +++ b/goconvey_test.go @@ -0,0 +1,25 @@ +package main + +import ( + "testing" + + . "github.com/smartystreets/goconvey/convey" +) + +func TestCheckExcludedDirs(t *testing.T) { + listOfTestExcludedDirs := map[string]string{ + "/go/src/package/vendor": "vendor", + "/go/src/package/vendor/": "vendor", + "/go/src/package/node_modules": "node_modules", + "/go/src/package/node_modules/": "node_modules", + } + + Convey("Exclude excluded directory for fake pathes", t, func() { + for working, excl := range listOfTestExcludedDirs { + excludedDirItems := checkExcludedDirs(excludedDirs, working) + for _, item := range excludedDirItems { + So(item, ShouldNotEqual, excl) + } + } + }) +}