forked from lsof-org/lsof
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.bash
executable file
·129 lines (111 loc) · 2.37 KB
/
check.bash
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
set -e
if [ $# = 0 ]; then
echo Usage: $0 DIALECT 1>&2
exit 1
fi
if ! [ -d dialects/$1 ]; then
echo No such dialect: $1 1>&2
exit 1
fi
echo
echo RUNTIME ENVIRONMENT INFORMATION
echo =============================================================================
dialect=$1
echo $dialect
echo $BASH_VERSION
shopt
export
uname
lsof=$(pwd)/lsof
$lsof -v
export CI=1
tdir=dialects/${dialect}/tests
nfailed=0
nsuccessful=0
nskipped=0
ncases=0
REPORTS=
run_one()
{
local x=$1
local d=$2
local name
local prefix
local report
local s
chmod a+x $x
name=$(basename $x .bash)
if [ ${x%%/*} = "dialects" ]; then
prefix=${dialect}-
fi
report=/tmp/${prefix}$name-$$.report
printf "%s ... " $name
set +e
bash ./$x $lsof $report $d $dialect
s=$?
set -e
ncases=$((ncases + 1))
if [ "$s" = 0 ]; then
s=ok
nsuccessful=$(($nsuccessful + 1))
rm -f "$report"
elif [ "$s" = 2 ]; then
s=skipped
nskipped=$((nskipped + 1))
REPORTS="${REPORTS} ${report}"
else
s=failed
nfailed=$((nfailed + 1))
REPORTS="${REPORTS} ${report}"
fi
printf "%s\n" $s
}
echo
echo STARTING TEST '(' dialect neutral ')'
echo =============================================================================
for x in tests/case-*.bash; do
run_one $x ./tests
done
echo
echo STARTING TEST '(' $dialect specific ')'
echo =============================================================================
for x in dialects/${dialect}/tests/case-*.bash; do
run_one $x $tdir
done
report()
{
for r in "$@"; do
echo
echo $r
echo -----------------------------------------------------------------------------
cat $r
rm $r
done
}
echo
echo TEST SUMMARY
echo =============================================================================
printf "successful: %d\n" $nsuccessful
printf "skipped: %d\n" $nskipped
printf "failed: %d\n" $nfailed
if [ $nfailed = 0 ]; then
printf "All %d test cases are passed successfully\n" $ncases
if [ $nskipped = 0 ]; then
:
elif [ $nskipped = 1 ]; then
printf "but 1 case is skipped\n"
report $REPORTS
else
printf "but %d cases are skipped\n" $nskipped
report $REPORTS
fi
exit 0
elif [ $nfailed = 1 ]; then
printf "%d of %d case is failed\n" $nfailed $ncases
report $REPORTS
exit 1
else
printf "%d of %d cases are failed\n" $nfailed $ncases
report $REPORTS
exit 1
fi