Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 1 file changed
  • 0 comments
  • 1 contributor

Showing 1 changed file with 22 additions and 10 deletions. Show diff stats Hide diff stats

  1. +22 10 goautotest.go
32 goautotest.go
@@ -4,7 +4,6 @@ import (
4 4 "fmt"
5 5 "github.com/howeyc/fsnotify"
6 6 "io"
7   - "log"
8 7 "os"
9 8 "os/exec"
10 9 "strings"
@@ -13,44 +12,57 @@ import (
13 12 func main() {
14 13 watcher, err := fsnotify.NewWatcher()
15 14 if err != nil {
16   - log.Fatal(err)
  15 + fmt.Println(err)
  16 + return
17 17 }
18 18
19   - err = watcher.Watch(".")
  19 + wd, err := os.Getwd()
20 20 if err != nil {
21   - log.Fatal(err)
  21 + fmt.Println(err)
  22 + return
22 23 }
23 24
  25 + err = watcher.Watch(wd)
  26 + if err != nil {
  27 + fmt.Println(err)
  28 + return
  29 + }
  30 +
  31 + defer watcher.Close()
  32 +
24 33 for {
25 34 select {
26 35 case ev := <-watcher.Event:
27 36 if strings.HasSuffix(ev.Name, ".go") {
28   - cmd := exec.Command("go", "test")
  37 + fmt.Println("Running tests...")
  38 +
  39 + args := append([]string{"test"}, os.Args[1:]...)
  40 + cmd := exec.Command("go", args...)
  41 +
29 42 stdout, err := cmd.StdoutPipe()
30 43 if err != nil {
31   - log.Println("Error: ", err)
  44 + fmt.Println(err)
32 45 break
33 46 }
34 47
35 48 err = cmd.Start()
36 49 if err != nil {
37   - log.Println("Error running test: ", err)
  50 + fmt.Println(err)
38 51 break
39 52 }
40 53
41 54 go io.Copy(os.Stdout, stdout)
42 55 err = cmd.Wait()
43 56 if err != nil {
44   - log.Println("Error:", err)
  57 + fmt.Println(err)
45 58 }
46 59
47 60 fmt.Println()
48 61 }
49 62
50 63 case err := <-watcher.Error:
51   - log.Println("Error:", err)
  64 + fmt.Println(err)
52 65 }
53 66 }
54 67
55   - watcher.Close()
56 68 }

No commit comments for this range

Something went wrong with that request. Please try again.