Skip to content
Browse files

Merge pull request #2 from antage/master

Events burst guard. Fixes #1.
  • Loading branch information...
2 parents 325ee96 + 70e25bd commit 4e7727663591c6f5f170c2cde62fa5c56ac234a2 @ryanslade committed Sep 22, 2012
Showing with 33 additions and 24 deletions.
  1. +33 −24 goautotest.go
View
57 goautotest.go
@@ -7,8 +7,36 @@ import (
"os"
"os/exec"
"strings"
+ "time"
)
+func startGoTest() {
+ fmt.Println("Running tests...")
+
+ args := append([]string{"test"}, os.Args[1:]...)
+ cmd := exec.Command("go", args...)
+
+ stdout, err := cmd.StdoutPipe()
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+
+ err = cmd.Start()
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+
+ go io.Copy(os.Stdout, stdout)
+ err = cmd.Wait()
+ if err != nil {
+ fmt.Println(err)
+ }
+
+ fmt.Println()
+}
+
func main() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
@@ -30,38 +58,19 @@ func main() {
defer watcher.Close()
+ burstGuard := make(<-chan time.Time)
for {
select {
case ev := <-watcher.Event:
if strings.HasSuffix(ev.Name, ".go") {
- fmt.Println("Running tests...")
-
- args := append([]string{"test"}, os.Args[1:]...)
- cmd := exec.Command("go", args...)
-
- stdout, err := cmd.StdoutPipe()
- if err != nil {
- fmt.Println(err)
- break
- }
-
- err = cmd.Start()
- if err != nil {
- fmt.Println(err)
- break
- }
-
- go io.Copy(os.Stdout, stdout)
- err = cmd.Wait()
- if err != nil {
- fmt.Println(err)
- }
-
- fmt.Println()
+ burstGuard = time.After(500 * time.Millisecond)
}
case err := <-watcher.Error:
fmt.Println(err)
+
+ case <-burstGuard:
+ startGoTest()
}
}

0 comments on commit 4e77276

Please sign in to comment.
Something went wrong with that request. Please try again.