| 52 | } |
| 53 | |
| 54 | func _testWatch(t *testing.T, modfunc func(), expected []string) { |
| 55 | defer utils.WithTempDir(t)() |
| 56 | |
| 57 | err := os.MkdirAll("a/inner", 0777) |
| 58 | if err != nil { |
| 59 | t.Fatal(err) |
| 60 | } |
| 61 | |
| 62 | err = os.MkdirAll("b", 0777) |
| 63 | if err != nil { |
| 64 | t.Fatal(err) |
| 65 | } |
| 66 | |
| 67 | touch("a/initial") |
| 68 | // There's some race condition in rjeczalik/notify. If we don't wait a bit |
| 69 | // here, we sometimes receive notifications for the change above even |
| 70 | // though we haven't started the watcher. |
| 71 | time.Sleep(200 * time.Millisecond) |
| 72 | |
| 73 | confTxt := ` |
| 74 | @shell = bash |
| 75 | |
| 76 | ** { |
| 77 | prep +onchange: echo ":skipit:" @mods |
| 78 | prep: echo ":all:" @mods |
| 79 | } |
| 80 | a/* { |
| 81 | prep: echo ":a:" @mods |
| 82 | } |
| 83 | b/* { |
| 84 | prep: echo ":b:" @mods |
| 85 | } |
| 86 | a/**/*.xxx { |
| 87 | prep: echo ":c:" @mods |
| 88 | } |
| 89 | a/direct { |
| 90 | prep: echo ":d:" @mods |
| 91 | } |
| 92 | direct { |
| 93 | prep: echo ":e:" @mods |
| 94 | } |
| 95 | ` |
| 96 | cnf, err := conf.Parse("test", confTxt) |
| 97 | if err != nil { |
| 98 | t.Fatal(err) |
| 99 | } |
| 100 | |
| 101 | lt := termlog.NewLogTest() |
| 102 | modchan := make(chan *moddwatch.Mod, 1024) |
| 103 | cback := func() { |
| 104 | start := time.Now() |
| 105 | modfunc() |
| 106 | for { |
| 107 | ret := events(lt.String()) |
| 108 | if reflect.DeepEqual(ret, expected) { |
| 109 | break |
| 110 | } |
| 111 | if time.Now().Sub(start) > timeout { |