-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathunit_test
executable file
·72 lines (61 loc) · 1.26 KB
/
unit_test
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
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
set -u
function usage() {
echo "unit_test <test_name> <generation> "
}
if [[ "$#" -ne 2 ]]; then
usage
exit 1
fi
basename=$1
generation=$2
progname=""
if [[ $generation == "1" ]];then
progname="./minigo"
elif [[ $generation == "2" ]]; then
progname="./minigo2"
elif [[ $generation == "0" ]]; then
progname="go run"
if [[ $basename =~ ^_ ]];then
# skip if basename begin with _
exit 0
fi
else
usage
exit 1
fi
bin_dir=/tmp/out
tmpfs_dir=/tmp/tmpfs/out
mkdir -p $bin_dir $tmpfs_dir
src=t/$basename/*.go
expected=t/expected/${basename}.txt
as_file=$tmpfs_dir/${basename}.${generation}.s
obj_file=$tmpfs_dir/${basename}.o
bin_file=$bin_dir/${basename}.bin
actual=$tmpfs_dir/actual.txt
# for os.Args
ARGS=t/data/sample.txt
# for os.Env
export FOO=BAR
function run_unit_test {
echo -n "./unit_test $progname $basename ... "
rm -f $actual
if [[ $progname == "go run" ]];then
# official go
${progname} $src $ARGS > $actual
else
${progname} $src > $as_file
as -o $obj_file $as_file
ld -o $bin_file $obj_file
$bin_file $ARGS > $actual
fi
diff -u $expected $actual
if [[ $? -ne 0 ]];then
echo failed
return 1
else
echo ok
return 0
fi
}
run_unit_test