-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_test.sh
executable file
·65 lines (53 loc) · 1.17 KB
/
run_test.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
#! /bin/bash
if [ $# -eq 0 ]; then
echo "Usage:"
echo "run_test.sh <name_of_script.js> [input_file] [expected_output]"
exit
fi
script=$1
if [ ! -f ${script} ]; then
echo "Unable to find ${script}"
exit 1
fi
input_file=$2
if [ ! -f ${input_file} ]; then
echo "Unable to find ${input_file}"
exit 1
fi
if [ -z ${input_file} ]; then
input_file="input"
fi
expected_output=$3
if [ ! -f ${expected_output} ]; then
echo "Unable to find ${expected_output}"
exit 1
fi
if [ -z ${expected_output} ]; then
expected_output="expected_out"
fi
actual_output=".actual_out"
rm -f ${actual_output}
IFS=$'\n'
lines=$(cat $input_file)
for line in ${lines[*]}; do
IFS="|"
echo "-------------------------------"
echo "Running test with input ${line}"
output=$(node $script ${line[*]})
echo $output | tee -a ${actual_output}
done
echo "-------------------------------"
RED='\033[0;31m'
NC='\033[0m'
diff_tool="colordiff"
if [ -z $(command -v ${diff_tool}) ]; then
diff_tool="diff"
fi
difference=$(${diff_tool} -y -W40 ${actual_output} ${expected_output})
if [ $? -ne 0 ]; then
echo -e "${RED}Tests failed!${NC}"
echo ${difference}
exit 1
else
echo "Tests passed!"
fi