forked from superorbital/golangcookbook.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests
executable file
·57 lines (46 loc) · 1.2 KB
/
run_tests
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
#!/usr/bin/env bash
test_output=/tmp/test_output.$$
touch $test_output
file_list=${@:-$(find chapters -name "test*.go")}
print_success() { echo -n .; }
print_failure() { echo -n x; }
print_pending() { echo -n p; }
print_output() { echo; cat $test_output; }
run_test() { diff <( go run $1 2>&1) $2 > /dev/null; }
record_failure() {
echo "Failed: $1" >> $test_output
echo " To reset, run:" >> $test_output
echo " rm $2" >> $test_output
diff -yW200 <( go run $1 2>&1) $2 >> $test_output
echo "------------------------" >> $test_output
echo >> $test_output
}
generate_expected() {
echo
echo "$2 not found - generating it..."
go run $1 > $2
}
generate_escaped() {
sed 's/&(?!amp;)/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g' < $1 > $1.escaped
}
for file in $file_list; do
expected=${file/.go/.expected}
if [ -s $file ]; then
if [ -f $expected ]; then
if run_test $file $expected; then
print_success
else
record_failure $file $expected
print_failure
fi
else
generate_expected $file $expected
fi
else
print_pending
fi
generate_escaped $expected
generate_escaped $file
done
print_output
rm $test_output