-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-script
executable file
·84 lines (73 loc) · 1.65 KB
/
test-script
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
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
diffprog=vimdiff
ask=1
workdir=$(mktemp -d)
cleanup() {
rm -rf $workdir
}
if [ -z ${VIMDIFF+x} ]; then
diffprog=diff
ask=0
fi
trap 'cleanup' ERR
show_diff() {
if [ -z ${NODIFF+x} ]; then
echo "-- start diff output --"
$diffprog $1 $2
echo "-- stop diff output --"
fi
}
set -e
test_file() {
filepath=$1
in_file=$(basename $filepath)
base=${in_file%.c.in}
reference_file=$base.c
out_file=$base.out
reference_err_file=$base.err
err_out_file=$base.out.err
set -e
cp $filepath $workdir
cp ${filepath%.c.in}.err $workdir
outfile=${filepath%.in}
cp $outfile $workdir
set +e
echo "==================="
echo "$(basename $outfile)"
echo "==================="
$workdir/cpp-iw $workdir/$in_file > $workdir/$out_file 2> $workdir/$err_out_file
cmp --silent $workdir/$out_file $workdir/$reference_file
outeq=$?
cmp --silent $workdir/$err_out_file $workdir/$reference_err_file
erreq=$?
if [ $outeq -eq 0 ]; then
echo "stdout: SUCCESS"
else
echo "stdout: FAILED"
show_diff $workdir/$out_file $workdir/$reference_file
fi
if [ $erreq -eq 0 ]; then
echo "stderr: SUCCESS"
else
echo "stderr: FAILED"
show_diff $workdir/$err_out_file $workdir/$reference_err_file
fi
}
cp cpp-iw $workdir
if [ $# -eq 1 ]
then
test_file "tests/$1.c.in"
else
for filepath in tests/*.in; do
test_file $filepath
if [ $ask -eq 1 ]
then
read -p "Continue? " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi
fi
done
fi