Exemple #1
0
func (l *watcherLoop) Run() {
	// Run the tests for the first time.
	execGoTest(l.paths)

	watcher, err := fsnotify.NewWatcher()

	for _, path := range l.paths {
		err = watcher.Watch(path)
		if err != nil {
			application.Fatal(err.Error())
		}
		application.Printf("Start watching path %s", path)
	}

	for {
		select {
		case <-l.pause:
			l.pause <- 0
		case <-l.terminate:
			watcher.Close()
			l.terminate <- 0
			return
		case ev := <-watcher.Event:
			if ev.IsModify() {
				if matches(ev.Name, ".*\\.go$") {
					if application.Verbose {
						application.Logf("Event %s occured for file %s", ev, ev.Name)
					}
					// check if the same event was
					// registered for the same
					// file in the acceptable
					// TIME_DISCARD time window
					event := getEvent(ev.Name)
					if event == nil {
						event = addEvent(&eventOnFile{ev, time.Now()})
						application.Logf("Run the tests")
						execGoTest(l.paths)
					} else if time.Now().Sub(event.time) > DISCARD_TIME {
						event.time = time.Now()
						application.Logf("Run the tests")
						execGoTest(l.paths)
					} else {
						if application.Verbose {
							application.Logf("Event %s was discarded for file %s", ev, ev.Name)
						}
					}
				}
			}
		case err := <-watcher.Error:
			application.Fatal(err.Error())
		}
	}
}
Exemple #2
0
func (h *sigterm) HandleSignal(s os.Signal) {
	switch ss := s.(type) {
	case syscall.Signal:
		switch ss {
		case syscall.SIGTERM, syscall.SIGINT:
			if h.hitCounter > 0 {
				application.Exit()
				return
			}
			application.Printf("Hit CTRL-C again to exit, otherwise tests will run again in %s.", RERUN_TIME)
			h.hitCounter++
			go func() {
				time.Sleep(RERUN_TIME)
				execGoTest(h.paths)
				h.hitCounter = 0
			}()
		}
	}
}