7
7
"os/exec"
8
8
"path/filepath"
9
9
"runtime"
10
+ "strings"
10
11
"syscall"
11
12
"testing"
12
13
"time"
@@ -16,10 +17,11 @@ import (
16
17
17
18
func TestCng (t * testing.T ) {
18
19
tests := []struct {
19
- name , stdout , stderr , exclude , pattern string
20
- verbose , kill , init , skip bool
21
- delay int
22
- steps func (write func (string ))
20
+ name , stderr , exclude , pattern string
21
+ stdout []string
22
+ verbose , kill , init , skip bool
23
+ delay int
24
+ steps func (write func (string ))
23
25
}{
24
26
{
25
27
name : "adds newly created files" ,
@@ -29,7 +31,7 @@ func TestCng(t *testing.T) {
29
31
write ("*.txt" )
30
32
}
31
33
},
32
- stdout : "hello\n hello \n hello \n " ,
34
+ stdout : [] string { "hello" , "hello" , "hello" } ,
33
35
},
34
36
{
35
37
name : "called when a file changes" ,
@@ -39,12 +41,12 @@ func TestCng(t *testing.T) {
39
41
write ("foo.txt" )
40
42
}
41
43
},
42
- stdout : "hello\n hello \n hello \n " ,
44
+ stdout : [] string { "hello" , "hello" , "hello" } ,
43
45
},
44
46
{
45
47
name : "init flag: should run on startup" ,
46
48
pattern : "*.txt" ,
47
- stdout : "hello\n " ,
49
+ stdout : [] string { "hello" } ,
48
50
init : true ,
49
51
},
50
52
{
@@ -57,7 +59,7 @@ func TestCng(t *testing.T) {
57
59
// should not be picked up by the watcher
58
60
write ("*.md" )
59
61
},
60
- stdout : "hello\n " ,
62
+ stdout : [] string { "hello" } ,
61
63
},
62
64
{
63
65
name : "ignores default excluded dirs" ,
@@ -66,7 +68,7 @@ func TestCng(t *testing.T) {
66
68
write (".git/foo.txt" )
67
69
write ("node_modules/foo.txt" )
68
70
},
69
- stdout : "" ,
71
+ stdout : [] string { "" } ,
70
72
},
71
73
// todo: should report helpful error if missing pattern
72
74
// {
@@ -147,7 +149,14 @@ func TestCng(t *testing.T) {
147
149
stdout := stdoutBuf .String ()
148
150
stderr := stderrBuf .String ()
149
151
150
- assert .Equal (t , test .stdout , stdout )
152
+ var sep string
153
+ if runtime .GOOS == "windows" {
154
+ sep = "\r "
155
+ } else {
156
+ sep = "\n "
157
+ }
158
+ testStdout := strings .Join (test .stdout , sep )
159
+ assert .Equal (t , testStdout , stdout )
151
160
assert .Equal (t , test .stderr , stderr )
152
161
})
153
162
}
0 commit comments