-
Notifications
You must be signed in to change notification settings - Fork 132
/
common.sh
128 lines (115 loc) · 2.23 KB
/
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
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
#!/bin/bash
fails=0
tests=0
skips=0
trap assert_report EXIT
function fail() {
local report=$1
local output=$2
fails=$((fails+1))
tests=$((tests+1))
echo "not ok $tests # $report" >&3
echo "# $report" >&2
echo "$output" >&2
}
function ok() {
cmd=$1
tests=$((tests+1))
echo "ok $tests # $cmd" >&3
}
function skip() {
comment=$1
tests=$((tests+1))
echo "ok $tests # SKIP $comment" >&3
}
function comment() {
echo "# $*" >&3
}
function assert_exit() {
expected="$1"
case $expected in
''|*[!0-9]*)
expected=0
cmd="$*"
;;
*)
shift
cmd="$*"
;;
esac
output=`$cmd 2>&1`
result=$?
report="exit $result should be $expected: '$cmd'"
if test $result -ne $expected; then
fail "$report" "$output"
else
ok "$report"
fi
}
function assert_file() {
local fname=$1
if test $# -gt 1; then
shift
found=$(grep -F -e "$*" $fname)
result=$?
if test $result -eq 0; then
ok "needle: '$*' in $fname"
else
fail "needle: '$*' NOT in $fname"
fi
else
report="file exists: $fname"
if test -f $fname; then
ok "$report"
else
fail "$report"
fi
fi
}
function assert_not_file() {
local fname=$1
if test $# -gt 1; then
shift
found=$(grep -F -e "$*" $fname)
result=$?
if test $result -eq 0; then
fail "needle: '$*' in $fname"
else
ok "needle: '$*' NOT in $fname"
fi
else
report="file exists: $fname"
if test -f $fname; then
fail "$report"
else
ok "$report"
fi
fi
}
function bailout() {
fail "$1"
echo "Bail out! $1" >&1
echo "Bail out! $1" >&2
echo "Bail out! $1" >&3
# exit 1
assert_report
}
function assert_report() {
if test -z $reported; then
echo "1..$tests" >&3
reported=1
fi
exit $fails
}
echo 'TAP version 13'
# make fd 3 the new fd 1 and redirect original fd 1 to fd 2
# this allows us to completely isolate the TAP output from these helpers
# to their own stream
if test -z "$DEBUG"; then
exec 3>&1 2>/dev/null 1>&2
comment "suppressing stderr, set DEBUG to restore"
else
exec 3>&1 1>&2
fi
comment "using npm registry $(npm config get registry)"
comment "using $(basename $(node -p process.execPath))-$(node -p process.version)"