-
Notifications
You must be signed in to change notification settings - Fork 0
/
grep.test.bats
executable file
·60 lines (46 loc) · 1.2 KB
/
grep.test.bats
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bats
@test "step 1 - empty" {
cd $HOME/workspace
run node grep.js "" test/rockbands.txt | diff test/rockbands.txt -
[ "$lines" = "" ]
}
@test "step 2 - includes J" {
cd $HOME/workspace
run node grep.js J test/rockbands.txt
[ "$status" = 0 ] || {
echo "status wrong" >&2
return 1
}
[ "${#lines[@]}" -eq 3 ] || {
echo "Test case failed: expected 3 lines but got ${#lines[@]} lines" >&2
return 1
}
[ "${lines[0]}" == "Judas Priest" ] || {
echo "Test case failed: should contain Judas Priest" >&2
return 1
}
}
@test "step 3 - recurse " {
cd $HOME/workspace
run node grep.js -r Nirvana test/*
[ "$status" -eq 0 ] || {
echo "status wrong" >&2
return 1
}
[ "${#lines[@]}" -eq 4 ] || {
echo "Test case failed: expected 4 lines but got ${#lines[@]} lines" >&2
return 1
}
}
@test "step 4 - negative " {
cd $HOME/workspace
run "node grep.js -r Nirvana test/rockbands.txt test/test-subdir/BFS1985.txt | node grep.js -v Madonna"
[ $status -eq 0 ] || {
echo "status wrong" >&2
return 1
}
[ "${#lines[@]}" -eq 1 ] || {
echo "Test case failed: expected 1 line but got ${#lines[@]} lines" >&2
return 1
}
}