Exemplo n.º 1
0
func (lt *goLintTask) Run(info *goauto.TaskInfo) (err error) {
	t0 := time.Now()
	info.Target = info.Src
	info.Buf.Reset()
	dir := goauto.GoRelSrcDir(info.Src)
	targs := append(lt.args, dir)
	cmd := exec.Command("golint", targs...)
	cmd.Stdout = &info.Buf
	cmd.Stderr = info.Terr
	defer func() {
		fmt.Fprint(info.Tout, info.Buf.String())
		if err == nil && info.Verbose {
			t1 := time.Now()
			fmt.Fprintf(info.Tout, ">>> Go Lint %v %v\n", dir, t1.Sub(t0))
		}
	}()
	if err = cmd.Run(); err != nil {
		return
	}
	if info.Buf.Len() > 0 {
		err = errors.New("FAIL")
		return
	}
	return
}
Exemplo n.º 2
0
func mkdir(info *goauto.TaskInfo) (err error) {
	dir := info.Target
	info.Target = info.Src
	if err = os.Mkdir(dir, 0755); err != nil && !os.IsExist(err) {
		return
	}
	if err != nil && info.Verbose {
		fmt.Fprintf(info.Tout, ">>> mkdir %v\n", dir)
	}
	return
}
Exemplo n.º 3
0
// Run will execute the task
func (st *shellTask) Run(info *goauto.TaskInfo) (err error) {
	t0 := time.Now()
	info.Target = st.transform(info.Src)
	info.Buf.Reset()
	targs := append(st.args, info.Target)
	cmd := exec.Command(st.cmd, targs...)
	cmd.Stdout = &info.Buf
	cmd.Stderr = info.Terr

	defer func() {
		fmt.Fprint(info.Tout, info.Buf.String())
		if err != nil && info.Verbose {
			t1 := time.Now()
			fmt.Fprintf(info.Tout, ">>> %v %v %v\n", st.cmd, st.args, t1.Sub(t0))
		}
	}()
	err = cmd.Run()
	return
}
Exemplo n.º 4
0
func (gt *goPrjTask) Run(info *goauto.TaskInfo) (err error) {
	t0 := time.Now()
	info.Target = info.Src
	info.Buf.Reset()
	dir := goauto.GoRelSrcDir(info.Src)
	targs := append([]string{gt.gocmd}, gt.args...)
	targs = append(targs, dir)
	gocmd := exec.Command("go", targs...)
	gocmd.Stdout = &info.Buf
	gocmd.Stderr = info.Terr
	defer func() {
		fmt.Fprint(info.Tout, info.Buf.String())
		if err == nil && info.Verbose {
			t1 := time.Now()
			fmt.Fprintf(info.Tout, "<< Go %v %v %v\n", strings.Title(gt.gocmd), dir, t1.Sub(t0))
		}
	}()
	return gocmd.Run()
}
Exemplo n.º 5
0
func TestOSTasks(t *testing.T) {
	tp := filepath.Join("src", "github.com", "dshills", "goauto", "testing")
	path, err := goauto.AbsPath(tp)
	if err != nil {
		t.Error(err)
	}
	fname := filepath.Join(path, "testdata")
	f, err := os.Create(fname)
	if err != nil {
		t.Fatal(err)
	}
	defer f.Close()
	f.WriteString("TESTING")
	_, err = os.Stat(fname)
	if err != nil {
		t.Fatal(err)
	}

	info := goauto.TaskInfo{Src: fname, Tout: ioutil.Discard, Terr: ioutil.Discard}

	newPath := filepath.Join(path, "t")
	tsk := NewMkdirTask(func(f string) string { return newPath })
	err = tsk.Run(&info)
	if err != nil {
		t.Error(err)
	}
	_, err = os.Stat(newPath)
	if err != nil {
		t.Error(err)
	}

	info.Src = info.Target

	newfname := filepath.Join(newPath, "testdata2")
	tsk = NewCopyTask(func(string) string { return newfname })
	err = tsk.Run(&info)
	if err != nil {
		t.Error(err)
	}
	if newfname != info.Target {
		t.Errorf("Expected %v got %v\n", newfname, info.Target)
	}
	_, err = os.Stat(newfname)
	if err != nil {
		t.Error(err)
	}

	info.Src = info.Target

	tsk = NewRemoveTask(goauto.Identity)
	err = tsk.Run(&info)
	if err != nil {
		t.Error(err)
	}
	_, err = os.Stat(newfname)
	if err == nil {
		t.Errorf("Expected error, file should be gone\n")
	}

	info.Src = info.Target

	tsk = NewRemoveTask(func(f string) string { return fname })
	err = tsk.Run(&info)
	if err != nil {
		t.Error(err)
	}
	_, err = os.Stat(fname)
	if err == nil {
		t.Errorf("Expected error, file should be gone\n")
	}

	info.Src = info.Target

	tsk = NewRemoveTask(func(f string) string { return newPath })
	err = tsk.Run(&info)
	if err != nil {
		t.Error(err)
	}
	_, err = os.Stat(newPath)
	if err == nil {
		t.Errorf("Expected error, file should be gone\n")
	}
}