forked from glenjamin/mocha-multi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify
executable file
·113 lines (93 loc) · 2.86 KB
/
verify
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
#!/bin/bash
mocha_multi="../../../mocha-multi.js"
normal="\033[0m"
function log {
local color
if [ "$2" = "info" ]; then
color="" # normal
elif [ "$2" = "fail" ]; then
color="\033[01;31m" # red
elif [ "$2" = "pass" ]; then
color="\033[01;32m" # green
else
color="\033[01;30m" # grey
fi
echo -e "${color}VERIFY: $1${normal}" 1>&2
}
function normalise_timers {
local file=$1
cmd="sed -i'.bak' -e 's/[0-9]\{1,\}\(\.[0-9]\{1,\}\)\{0,1\}/0/g' '$file'"
eval $cmd
rm "$file.bak"
}
# pipe through cat to ensure istty = false, but capture exit code
function eval_notty {
log "Running formatter $1: $2"
eval $2 | cat
return ${PIPESTATUS[0]}
}
function compare {
local reporter=$1
log "Running comparison for $reporter" info
local builtin_out=$(mktemp /tmp/mocha-multi.XXXXXXXXX)
local multi_env_out=$(mktemp /tmp/mocha-multi.XXXXXXXXX)
local multi_arg_out=$(mktemp /tmp/mocha-multi.XXXXXXXXX)
local builtin_cmd="mocha -R $reporter &> $builtin_out"
eval_notty "normally" "$builtin_cmd"
local builtin_result=$?
normalise_timers $builtin_out
local multi_env_cmd="multi='$reporter=$multi_env_out' mocha -R $mocha_multi"
eval_notty "via mocha-multi using environment variable" "$multi_env_cmd"
local multi_env_result=$?
normalise_timers $multi_env_out
local multi_arg_cmd="mocha -R $mocha_multi --reporter-options '$reporter=$multi_arg_out'"
eval_notty "via mocha-multi using --reporter-options" "$multi_arg_cmd"
local multi_arg_result=$?
normalise_timers $multi_arg_out
log "Comparing exit codes"
if [ "$builtin_result" = "$multi_arg_result" -a "$builtin_result" = "$multi_env_result" ]; then
log 'Codes match, hooray!' pass
else
log "Codes do not match" fail
log "Result ${normal}$builtin_result"
log "Result (env) ${normal}$multi_env_result"
log "Result (arg) ${normal}$multi_arg_result"
return 1
fi
log "Comparing output"
local diff_cmd_env="diff -U1 -Lbuiltin -Lmulti $builtin_out $multi_env_out"
log "Running $diff_cmd_env"
local difference_env=$($diff_cmd_env)
local diff_cmd_arg="diff -U1 -Lbuiltin -Lmulti $builtin_out $multi_arg_out"
log "Running $diff_cmd_arg"
local difference_arg=$($diff_cmd_arg)
rm "$builtin_out" "$multi_env_out" "$multi_arg_out"
if [ "$difference_env" = "" -a "$difference_arg" = "" ]; then
log 'Output matches, hooray!' pass
return 0
else
log "Output does not match" fail
log "Difference (env)\n${normal}$difference_env"
log "Difference (arg)\n${normal}$difference_arg"
return 1
fi
}
if [ "$1" = "" ]; then
log "No reporter chosen"
exit 1
fi
if [ "$1" = "all" ]; then
reporters=(\
dot doc spec json progress \
list tap landing xunit min \
json-stream markdown nyan\
)
result=0
for reporter in ${reporters[@]}; do
compare $reporter
result=$(($result + $?))
done
exit $result
else
compare $1
fi