func TestSass(t *testing.T) { tp := filepath.Join("src", "github.com", "dshills", "goauto", "testing", "_sub.scss") p, err := goauto.AbsPath(tp) if err != nil { t.Error(err) } css := filepath.Join(filepath.Dir(p), "css") cache := filepath.Join(css, ".sass_cache") st := NewSassTask(css, cache, "compressed") ti := goauto.TaskInfo{ Src: p, Tout: ioutil.Discard, Terr: ioutil.Discard, } err = st.Run(&ti) if err != nil { t.Error(err) } _, err = os.Stat(css) if err != nil { t.Error(err) } _, err = os.Stat(cache) if err != nil { t.Error(err) } nc := filepath.Join(filepath.Dir(p), "css", "main.css") _, err = os.Stat(nc) if err != nil { t.Error(err) } os.Remove(nc) ncm := filepath.Join(filepath.Dir(p), "css", "main.css.map") _, err = os.Stat(ncm) if err != nil { t.Error(err) } os.Remove(ncm) }
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") } }