-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch.d
executable file
·43 lines (36 loc) · 961 Bytes
/
watch.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env dub
/+ dub.sdl:
name "test-watch"
version "1.0.0"
license "public domain"
dependency "fswatch" version="~>0.5"
+/
import core.thread;
import fswatch;
import std.algorithm.searching : any;
import std.datetime;
import std.process;
import std.string;
void main(string[] args)
{
FileWatch sourceWatcher = FileWatch("source/", true);
FileWatch testWatcher = FileWatch("test/", true);
runTests(args);
while (true)
{
FileChangeEvent[] sourceChanges = sourceWatcher.getEvents();
FileChangeEvent[] testChanges = testWatcher.getEvents();
if (sourceChanges.length > 0 || testChanges.length > 0)
{
runTests(args);
}
Thread.sleep(500.msecs);
}
}
private void runTests(string[] args)
{
Pid clearPid = spawnShell("clear");
wait(clearPid);
Pid dubTestPid = spawnProcess(["dub", "test", "--compiler=dmd"] ~ args[1..$]);
wait(dubTestPid);
}