Example #1
0
func TestStatuses(t *testing.T) {
	sw := status.NewWriter(80)
	sw.Pending(" Achievement unlocked")
	sw.MkSuccess().Done()

	sw.Pending(" Something is wrong here")
	sw.MkWarning().Done()

	sw.Pending(" Houston we have a problem")
	sw.MkFailure().Done()

	sw.Pending(" I will pass all the statuses and end failing")
	sw.MkSuccess()
	sw.MkWarning()
	sw.MkFailure().Done()

	sw.Pending(" I'll stay pending")
	sw.Done()

	sw.Pending(" This is a very very very very long status message that should normally be truncated to avoir overflows")
	sw.MkSuccess()
	sw.Done()
}
Example #2
0
func main() {
	flag.Parse()

	banner()

	cwd, err := os.Getwd()
	if err != nil {
		die("An error occured while getting the working directory's path, please check your credentials")
	}

	if !strings.HasPrefix(strings.ToLower(cwd), GoPath) {
		die("Gobot must be run within your $GOPATH")
	}

	// FIXME This won't work if golint is installed elsewhere and available on the path.
	golint = filepath.Join(build.Default.GOPATH, "bin", "golint")
	if runtime.GOOS == "windows" {
		golint += ".exe"
	}
	_, lerr := os.Stat(golint)
	if lerr != nil {
		warn("Linter not found, disabling linting for the current session")
	}

	sw := status.NewWriter(termWidth)

	f := func(path string, info os.FileInfo) bool {
		directory := filepath.Dir(path)
		//start := Timestamp()

		fmt.Print("\n")
		sw.Pendingf("Building %v", ToModuleName(directory))
		stdout, stderr, err := Execute(directory, "go", "build")
		if err != nil {
			sw.MkFailure().Done()
			fmt.Fprintln(os.Stderr, stderr.String())
			return true
		}
		sw.MkSuccess().Done()

		stdout.Reset()
		stderr.Reset()
		err = nil

		if len(golint) > 0 {
			sw.Pending("Linting")
			stdout, stderr, err = Execute(directory, golint)
			if err != nil {
				sw.MkFailure().Done()
				warn("An error occured while linting, disabling linting for this session")
				golint = ""
			} else if len(stdout.String()) > 0 {
				sw.MkWarning().Done()
				fmt.Fprintln(os.Stdout, "#"+filepath.Base(directory)+"\n"+stdout.String())
			} else {
				sw.MkSuccess().Done()
			}
		}

		stdout.Reset()
		stderr.Reset()
		err = nil

		sw.Pending("Testing")
		stdout, stderr, err = Execute(directory, "go", "test")
		if err != nil {
			sw.MkFailure().Done()
			fmt.Fprintln(os.Stdout, "Some unit tests failed :\n", stdout.String())
		} else {
			sw.MkSuccess().Done()
		}

		return true
	}

	w, e := fswatcher.NewFsWatcher(cwd, pollInterval)
	if e != nil {
		die(fmt.Sprintf("Cannot monitor %s : %s", cwd, e.Error()))
	}

	w.Skip(".git")
	w.RegisterFileExtension(".go", f)
	w.Watch()

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)
	<-c
	fmt.Println("Exiting")
}