-
Notifications
You must be signed in to change notification settings - Fork 245
/
runtest
executable file
·87 lines (69 loc) · 1.98 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/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
set +o errexit
set -o pipefail
export TAP=1
NODE_PATH="/usr/vm/test/node-tap/node_modules:${NODE_PATH}" \
/usr/node/bin/node $1 | tee -a /tmp/test.output.$$
TEST_EXIT_CODE=$?
set +o pipefail
set -o errexit
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)
skipped=$(grep "^# skip [0-9]" /tmp/test.output.$$ | tr -s ' ' | cut -d ' ' -f3 | xargs | tr ' ' '+' | bc)
[[ -z ${tests} ]] && tests=0
[[ -z ${passed} ]] && passed=0
[[ -z ${skipped} ]] && skipped=0
fail=$((${tests} - ${passed} - ${skipped}))
if [[ ${TEST_EXIT_CODE} != 0 ]]; then
fail=$((${fail} + 1))
tests="?"
fi
if [[ -t 0 ]]; then
# We're on a terminal so output the summary
echo "#"
echo "# $1 TEST COMPLETE IN ${elapsed} SECONDS, SUMMARY:"
echo "#"
if [[ ${tests} != "?" ]]; then
echo -e "# \033[32mPASS: ${passed} / ${tests}\033[39m"
fi
if [[ ${skipped} -gt 0 ]]; then
echo -e "# \033[31mSKIP: ${skipped} / ${tests}\033[39m"
fi
if [[ ${fail} -gt 0 ]]; then
echo -e "# \033[31mFAIL: ${fail} / ${tests}\033[39m"
fi
echo "#"
fi
if [[ ${fail} -gt 0 ]]; then
exit 1
fi
exit 0