func TestVarCmd(t *testing.T) { b := conf.Block{} b.Include = []string{"tdir/**"} vc := VarCmd{&b, nil, map[string]string{}} ret, err := vc.Render("@mods @dirmods") if err != nil { t.Fatal("unexpected error") } expect := `"./tdir/tfile" "./tdir"` if runtime.GOOS == "windows" { expect = `".\tdir\tfile" ".\tdir"` } if ret != expect { t.Errorf("Unexpected return: %s", ret) } vc = VarCmd{ &b, &watch.Mod{Changed: []string{"foo"}}, map[string]string{}, } ret, err = vc.Render("@mods @dirmods") if err != nil { t.Fatal("unexpected error") } expected := `"./foo" "./."` if runtime.GOOS == "windows" { expected = `".\foo" ".\."` } if ret != expected { t.Errorf("Unexpected return: %s", ret) } }
func TestVarCmd(t *testing.T) { defer utils.WithTempDir(t)() dst := path.Join("./tdir") err := os.MkdirAll(dst, 0777) if err != nil { t.Fatalf("MkdirAll: %v", err) } err = ioutil.WriteFile(path.Join(dst, "tfile"), []byte("test"), 0777) if err != nil { t.Fatalf("WriteFile: %v", err) } b := conf.Block{} b.Include = []string{"tdir/**"} vc := VarCmd{&b, nil, map[string]string{}} ret, err := vc.Render("@mods @dirmods") if err != nil { t.Fatalf("unexpected error: %s", err) } expect := `"./tdir/tfile" "./tdir"` if ret != expect { t.Errorf("Expected: %#v, got %#v", expect, ret) } vc = VarCmd{ &b, &moddwatch.Mod{Changed: []string{"foo"}}, map[string]string{}, } ret, err = vc.Render("@mods @dirmods") if err != nil { t.Fatal("unexpected error") } expected := `"./foo" "./."` if ret != expected { t.Errorf("Expected: %#v, got %#v", expected, ret) } }