forked from glenjamin/mocha-multi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify
executable file
·136 lines (114 loc) · 4.05 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/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 multi_file_in=$(mktemp /tmp/mocha-multi.XXXXXXXXX)
local multi_file_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
echo "{\"$reporter\": \"$multi_file_out\"}" > "$multi_file_in"
local multi_file_cmd="mocha -R $mocha_multi --reporter-options 'mocha-multi=$multi_file_in'"
eval_notty "via mocha-multi using file" "$multi_file_cmd"
local multi_file_result=$?
normalise_timers $multi_file_out
log "Comparing exit codes"
if [ "$builtin_result" = "$multi_arg_result" -a "$builtin_result" = "$multi_env_result" -a "$builtin_result" = "$multi_file_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"
log "Result (file) ${normal}$multi_file_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)
local diff_cmd_file="diff -U1 -Lbuiltin -Lmulti $builtin_out $multi_file_out"
log "Running $diff_cmd_file"
local difference_file=$($diff_cmd_file)
rm "$builtin_out" "$multi_env_out" "$multi_arg_out" "$multi_file_out" "$multi_file_in"
if [ "$difference_env" = "" -a "$difference_arg" = "" -a "$difference_file" = "" ]; 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"
log "Difference (file)\n${normal}$difference_file"
return 1
fi
}
badfilecheck="ERROR: Missing or malformed options file 'missing.json' -- Error: ENOENT: no such file or directory, open 'missing.json'"
badfile=`mocha --reporter "$mocha_multi" --reporter-options mocha-multi=missing.json --recursive test 2>&1`
log "$badfile"
if [ "$badfile" != "$badfilecheck" ]; then
log "Wrong error message trying to load missing options file" fail
exit 1
else
log "Correct error message trying to load missing options file" pass
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