/
runtest
executable file
·70 lines (53 loc) · 1.54 KB
/
runtest
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
#!/bin/bash
# All tests must pass!
set -o errexit
if [[ ! -f "/lib/sdc/.sdc-test-no-production-data" ]]; then
cat <<EOF
To run this test you must create the file:
/lib/sdc/.sdc-test-no-production-data
after ensuring you have no production data on this machine.
EOF
exit 2
fi
start_time=$(date +%s)
if [[ $(uname -s) != 'SunOS' ]]; then
echo "FATAL: this can only run on SmartOS"
exit 1
fi
if [[ $(zonename) != 'global' ]]; then
echo "FATAL: this can only run in the GZ"
exit 1
fi
if [[ $(id -u) != 0 ]]; then
echo "FATAL: this can only run as root"
exit 1
fi
if [[ -z "$1" ]]; then
echo "FATAL: no test file specified"
exit 1
fi
export TAP=1
NODE_PATH="/usr/vm/test/node-tap/node_modules:${NODE_PATH}" \
/usr/node/bin/node $1 | tee -a /tmp/test.output.$$
end_time=$(date +%s)
elapsed=$((${end_time} - ${start_time}))
tests=$(grep "^# tests [0-9]" /tmp/test.output.$$ | cut -d ' ' -f3 | xargs | tr ' ' '+' | bc)
passed=$(grep "^# pass [0-9]" /tmp/test.output.$$ | tr -s ' ' | cut -d ' ' -f3 | xargs | tr ' ' '+' | bc)
[[ -z ${tests} ]] && tests=0
[[ -z ${passed} ]] && passed=0
fail=$((${tests} - ${passed}))
if [[ -t 0 ]]; then
# We're on a terminal so output the summary
echo "#"
echo "# $1 TEST COMPLETE IN ${elapsed} SECONDS, SUMMARY:"
echo "#"
echo -e '# \E[32;40m'"PASS: ${passed} / ${tests}"; tput sgr0
if [[ ${fail} -gt 0 ]]; then
echo -e '# \E[31;40m'"FAIL: ${fail} / ${tests}"; tput sgr0
fi
echo "#"
fi
if [[ ${tests} != ${pass} ]]; then
exit 1
fi
exit 0