Skip to content

Commit

Permalink
Merge pull request #197 from dprotaso/watching-run-all
Browse files Browse the repository at this point in the history
enable running all tests when watching by pressing 'a'
  • Loading branch information
dnephin committed May 28, 2021
2 parents ecb7c69 + a17a4b3 commit 99b2618
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
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
3 changes: 3 additions & 0 deletions internal/filewatcher/term_unix.go
Expand Up @@ -80,6 +80,9 @@ func (r *redoHandler) Run(ctx context.Context) {
case 'd':
chResume = make(chan struct{})
r.ch <- RunOptions{Debug: true, resume: chResume}
case 'a':
chResume = make(chan struct{})
r.ch <- RunOptions{resume: chResume, PkgPath: "./..."}
case '\n':
fmt.Println()
continue
Expand Down
4 changes: 3 additions & 1 deletion internal/filewatcher/watch.go
Expand Up @@ -56,7 +56,6 @@ func Watch(dirs []string, run func(opts RunOptions) error) error {
resetTimer(timer)

redo.ResetTerm()
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 @@ -223,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 99b2618

Please sign in to comment.