UNPKG

1.83 kBPlain TextView Raw
1#!/bin/bash
2
3mocha_multi="../../../mocha-multi.js"
4normal="\033[0m"
5
6function log {
7 local color
8 if [ "$2" = "info" ]; then
9 color="" # normal
10 elif [ "$2" = "fail" ]; then
11 color="\033[01;31m" # red
12 elif [ "$2" = "pass" ]; then
13 color="\033[01;32m" # green
14 else
15 color="\033[01;30m" # grey
16 fi
17 echo -e "${color}VERIFY: $1${normal}" 1>&2
18}
19
20function normalise_timers {
21 local file=$1
22 cmd="sed -i'.bak' -e 's/[0-9]\{1,\}\(\.[0-9]\{1,\}\)\{0,1\}/0/g' '$file'"
23 eval $cmd
24 rm "$file.bak"
25}
26
27function compare {
28 local reporter=$1
29
30 log "Running comparison for $reporter" info
31
32 local builtin_out=$(mktemp /tmp/mocha-multi.XXXXXXXXX)
33 local multi_out=$(mktemp /tmp/mocha-multi.XXXXXXXXX)
34
35 local builtin_cmd="mocha -R $reporter &> $builtin_out"
36 log "Running formatter normally: $builtin_cmd"
37 eval $builtin_cmd
38 normalise_timers $builtin_out
39
40 # pipe through cat to ensure istty = false
41 local multi_cmd="multi='$reporter=$multi_out' mocha -R $mocha_multi | cat"
42 log "Running formatter via mocha-multi: $multi_cmd"
43 eval $multi_cmd
44 normalise_timers $multi_out
45
46 log "Comparing output"
47 local diff_cmd="diff -U1 -Lbuiltin -Lmulti $builtin_out $multi_out"
48 log "Running $diff_cmd"
49 local difference=$($diff_cmd)
50
51 rm "$builtin_out" "$multi_out"
52
53 if [ "$difference" = "" ]; then
54 log 'Output matches, hooray!' pass
55 return 0
56 else
57 log "Output does not match" fail
58 log "Difference\n${normal}$difference"
59 return 1
60 fi
61}
62
63if [ "$1" = "" ]; then
64 log "No reporter chosen"
65 exit 1
66fi
67
68if [ "$1" = "all" ]; then
69 reporters=(\
70 dot doc spec json progress \
71 list tap landing xunit min \
72 json-stream markdown nyan\
73 )
74 result=0
75 for reporter in ${reporters[@]}; do
76 compare $reporter
77 result=$(($result + $?))
78 done
79 exit $result
80else
81 compare $1
82fi