-
Notifications
You must be signed in to change notification settings - Fork 1
/
runTests
executable file
·97 lines (90 loc) · 2.67 KB
/
runTests
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
#!/bin/sh
UPLINE=$(tput cuu1) # Declare the character that moves up one line
ERASELINE=$(tput el) # Declare the character the erases the line
ERRORS=""
TESTEDFILES=0
ERRORCOUNT=0
TESTINGSTRING=""
#Runs the initial collection of all failing and passing tests and prints out a summary
PrepCounts() {
passFiles=(tests/*-pass.kn);
passFileCount=${#passFiles[@]};
failFiles=(tests/*-fail.kn);
failFileCount=${#failFiles[@]};
totalFiles=$((passFileCount+failFileCount));
echo "Commencing testing for $passFileCount passing tests and $failFileCount failing tests for $totalFiles total tests.\n";
}
#Clears the status off of the last two lines and sets the cursor to the beginning of the top of those lines.
ClearStatus() {
echo "$ERASELINE$UPLINE$ERASELINE$UPLINE$ERASELINE\c"
}
#Prints the current status of tests.
PrintStatus() {
ClearStatus
if [ $TESTEDFILES -eq $totalFiles ]
then
if [ $ERRORCOUNT -gt 0 ]
then
echo "Testing Complete. Errors in $ERRORCOUNT of $TESTEDFILES tests."
else
echo "Testing Complete. No Errors."
fi
else
echo "Testing \"$CURRENTFILE\" ($TESTEDFILES of $totalFiles)"
fi
echo $TESTINGSTRING
}
#Runs the knode compiler on $CURRENTFILE, sending output to the test's name.log and the file to name.out
TestFile() {
ERRORS=""
testname=$(echo $CURRENTFILE | sed -nE 's!tests/(.*)-(pass|fail).kn!\1!p');
`$(./knode $CURRENTFILE tests/$testname.out >tests/$testname.log 2>&1 )`;
# Check to see if it compiled (or didn't compile) correctly
if [ $? -eq $1 ]
then # If it did what it was supposed to
if [ $1 -eq 0 ]
then
TESTINGSTRING+="\b\033[33mC\033[0m"; # Mark it as compiling correctly
`./tests/$testname.out >>tests/$testname.log 2>&1`;
if [ $? -eq 0 ]
then
TESTINGSTRING+="\b\033[32m.\033[0m";
else
tmperrors=$(<tests/$testname.log);
ERRORS="\033[34mIn file $testname.out:\033[0m\n$tmperrors\n\n";
ERRORCOUNT=$((ERRORCOUNT+1));
fi
else
TESTINGSTRING+="\b\033[32m.\033[0m"; # Mark it as compiling correctly without trying to run.
fi
else
tmperrors=$(<tests/$testname.log);
ERRORS="\033[34mIn file $CURRENTFILE:\033[0m\n$tmperrors\n\n";
ERRORCOUNT=$((ERRORCOUNT+1));
TESTINGSTRING+="\b\033[31mF\033[0m";
fi
ClearStatus;
echo "$ERRORS\c"
echo "\n"
PrintStatus;
}
PrepCounts
for file in "${passFiles[@]}"
do
TESTINGSTRING+="\033[33m.\033[0m"
CURRENTFILE=$file
TESTEDFILES=$((TESTEDFILES+1))
PrintStatus
TestFile 0
PrintStatus
done
for file in "${failFiles[@]}"
do
TESTINGSTRING+="\033[33m.\033[0m"
CURRENTFILE=$file
TESTEDFILES=$((TESTEDFILES+1))
PrintStatus
TestFile 1
PrintStatus
done
echo "$ERRORS"