-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·94 lines (81 loc) · 2.84 KB
/
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
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
#!/bin/bash
# Show help usage
if [ "$#" -eq "0" ] || [ "$#" -gt "4" ]
then
printf "Usage: \n\t./test.sh executable input [output] [expected]\n"
exit 0
fi
echo ">> -------------------------------------------------"
# Check if theres a variable
if [ -z "$1" ]
then
echo "[ERROR] NOT SPECIFIED EXECUTABLE FILES!"
echo "<< -------------------------------------------------"
exit 1
fi
if [ -z "$2" ]
then
echo "[ERROR] NOT SPECIFIED FILE FOR TEST!"
echo "<< -------------------------------------------------"
exit 1
fi
# Give the default name for out file
OUTPUT_FILE="$2.out"
# If there are a third parameter
if [ ! -z "$3" ]
then
OUTPUT_FILE="$3"
fi
# Check if file exists and can be executed
if [ -e "$1" ] && [ -s "$1" ] && [ -x "$1" ]
then
# Execute compiled code and save the result in a test file
"./$1" "$2" "$OUTPUT_FILE" > /dev/null 2>&1
else
echo "[ERROR] FILE NOT EXIST, IS EMPTY OR CAN'T BE EXECUTABLE!"
echo "<< -------------------------------------------------"
exit 1
fi
# Expected file
EXPECTED_FILE="$2.exp"
# If there are a fourth parameter
if [ ! -z "$4" ]
then
EXPECTED_FILE="$4"
fi
# Check if the other file exist
# Check if file exists and can be executed
if [ -e "$OUTPUT_FILE" ]
then
# File EXIST
echo ">> TESTING $2 WITH BINARY $1"
else
echo "[ERROR] OUTPUT FILE NOT EXIST!"
echo "<< -------------------------------------------------"
exit 1
fi
# Compara os resultados
DIFF=$(diff -q "$OUTPUT_FILE" "$EXPECTED_FILE")
if [ "$DIFF" != "" ]
then
if [ "$(command -v diffchecker)" ]
then
echo "Opening diff between the expected and output"
echo "If it's slow please open test.sh and check the comment bellow"
# Use the following command to make it more faster
# It will disable open browser after create diff
# cat "$(whereis diffchecker | cut -d ":" -f 2 | cut -d " " -f 2- | rev | cut -d "/" -f 2- | rev)/$(readlink -- $(whereis diffchecker) | rev | cut -d "/" -f 2- | rev)/transmit.js" | tr '\n' '\f' | sed -e 's/(0, _opener2.default)(url, function () {\f process.exit();\f });/\/\/(0, _opener2.default)(url, function () {\f \/\/process.exit();\f \/\/});/' | tr '\f' '\n' > transmit.js && sudo mv transmit.js "$(whereis diffchecker | cut -d ":" -f 2 | cut -d " " -f 2- | rev | cut -d "/" -f 2- | rev)/$(readlink -- $(whereis diffchecker) | rev | cut -d "/" -f 2- | rev)/transmit.js"
diffchecker --expires day "$OUTPUT_FILE" "$EXPECTED_FILE"
#vimdiff "$2.out" "$2.exp"
else
#echo "vimdiff isn't installed"
#echo "Install vimdiff to check what's wrong"
echo "Install diffchecker with 'sudo npm install -g diffchecker' to check what's wrong"
fi
echo "[ERROR] RESULT IS DIFFERENT FROM WHAT IS EXPECTED"
echo "<< -------------------------------------------------"
exit 1
fi
echo ">> COMPLETED! EVERYTHING IS CORRECT WITH $2 :)"
echo "<< -------------------------------------------------"
exit 0