forked from BAndysc/Szpital
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·78 lines (62 loc) · 1.59 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
#!/bin/bash
PASSED=0
ALL=0
TOTAL_TIME=0
DEBUG_CHECK=0
PARAMETERS=
OK=$'\e[32;01m [OK]\e[0m'
WRONG=$'\e[31;01m [WRONG]\e[0m'
ILLEGAL_ARGUMENTS="Usage: ./test.sh [-v (optional]) [prog] [tests directory]"
EXECUTABLE_DOESNT_EXIST="Executable file does not exist"
TESTS_DOESNT_EXIST="Test directory does not exist"
if [ $# == 3 ]; then
DEBUG_CHECK=1
PARAMETERS="-v"
EXECUTABLE=$2
DIRECTORY=$3
elif [ $# == 2 ]; then
EXECUTABLE=$1
DIRECTORY=$2
else
echo $ILLEGAL_ARGUMENTS
exit 0
fi
if [ -f $EXECUTABLE ]; then
EXECUTABLE="./$EXECUTABLE"
else
echo $EXECUTABLE_DOESNT_EXIST
exit 0
fi
if [ ! -d $DIRECTORY ]; then
echo $TESTS_DOESNT_EXIST
exit 0
fi
for file in $DIRECTORY/test*.in; do
FILENAME=${file/$DIRECTORY/""}
START=$(date +%s.%N)
$EXECUTABLE $PARAMETERS < $file > out 2> err
END=$(date +%s.%N)
time=$(echo "$END - $START" | bc)
TOTAL_TIME=$(echo "$TOTAL_TIME + $time" | bc)
if diff out "${file%.in}.out" >/dev/null 2>&1; then
echo "Test ${FILENAME} $OK (took $time seconds)"
if [ $DEBUG_CHECK == 1 ]; then
if diff err "${file%.in}.err" >/dev/null 2>&1; then
echo " ...referenced string $OK"
PASSED=$(($PASSED+1))
else
echo " ...but refrenced string $WRONG"
fi
echo ""
else
PASSED=$(($PASSED+1))
fi
else
echo "Test ${FILENAME} $WRONG"
fi
ALL=$(($ALL+1))
done
rm -f out
rm -f err
echo "Your application has passed $PASSED out of $ALL tests!"
echo "It has taken $TOTAL_TIME seconds"