Skip to content

Commit

Permalink
move condition to reduce complexity of Watch
Browse files Browse the repository at this point in the history
Also add the feature to the README
  • Loading branch information
dnephin committed May 28, 2021
1 parent 77279f7 commit a17a4b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).

Expand Down
6 changes: 3 additions & 3 deletions internal/filewatcher/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a17a4b3

Please sign in to comment.