From a17a4b30c53ef21c07e2316c1db30ccce8cf07af Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 28 May 2021 14:22:03 -0400 Subject: [PATCH] move condition to reduce complexity of Watch Also add the feature to the README --- README.md | 3 ++- internal/filewatcher/watch.go | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ac70f274..cc52fe3c 100644 --- a/README.md +++ b/README.md @@ -316,10 +316,11 @@ While in watch mode, pressing some keys will perform an action: * `r` will run tests for the previous event. * `d` will run tests for the previous event using `dlv test`, allowing you to - debug a test failure using [delve] A breakpoint will automatically be added at + debug a test failure using [delve]. A breakpoint will automatically be added at the first line of any tests which failed in the previous run. Additional breakpoints can be added with [`runtime.Breakpoint`](https://golang.org/pkg/runtime/#Breakpoint) or by using the delve command prompt. +* `a` will run tests for all packages, by using `./...` as the package selector. Note that [delve] must be installed in order to use debug (`d`). diff --git a/internal/filewatcher/watch.go b/internal/filewatcher/watch.go index 447c6894..e80c4e5d 100644 --- a/internal/filewatcher/watch.go +++ b/internal/filewatcher/watch.go @@ -56,9 +56,6 @@ func Watch(dirs []string, run func(opts RunOptions) error) error { resetTimer(timer) redo.ResetTerm() - if opts.PkgPath == "" { - opts.PkgPath = h.lastPath - } if err := h.runTests(opts); err != nil { return fmt.Errorf("failed to rerun tests for %v: %v", opts.PkgPath, err) } @@ -225,6 +222,9 @@ func (h *handler) handleEvent(event fsnotify.Event) error { } func (h *handler) runTests(opts RunOptions) error { + if opts.PkgPath == "" { + opts.PkgPath = h.lastPath + } fmt.Printf("\nRunning tests in %v\n", opts.PkgPath) if err := h.fn(opts); err != nil {