-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-common.sh
executable file
·47 lines (40 loc) · 1019 Bytes
/
test-common.sh
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
#!/bin/bash
tmpdir=${tmpdir:-$(mktemp -d)}
echo $tmpdir
section (){
echo >> $tmpdir/results
echo "Section $@" >> $tmpdir/results
echo "Section $@" >> $tmpdir/report
}
success (){
echo $'\x1b[32;1m'"TEST: $@"$'\x1b[0m'
if $@
then
echo -n "$results"$'\x1b[32;1m'✔$'\x1b[0m' >> $tmpdir/results
else
echo -n "$results"$'\x1b[31;1m'✘$'\x1b[0m' >> $tmpdir/results
echo $'\x1b[31;1m'"Unexpected Failure:"$'\x1b[0m' $@ >> $tmpdir/report
touch $tmpdir/fail
fi
}
fail (){
echo $'\x1b[32;1m'"TEST: $@"$'\x1b[0m'
if $@
then
echo -n "$results"$'\x1b[31;1m'✘$'\x1b[0m' >> $tmpdir/results
echo $'\x1b[31;1m'"Unexpected Success:"$'\x1b[0m' $@ >> $tmpdir/report
else
echo -n "$results"$'\x1b[32;1m'✔$'\x1b[0m' >> $tmpdir/results
fi
}
report (){
cat $tmpdir/results
echo
echo Details:
cat $tmpdir/report
test -e $tmpdir/fail
status=$?
rm -r $tmpdir
exit $status
}
trap report EXIT