-
Notifications
You must be signed in to change notification settings - Fork 2
/
tester
executable file
·116 lines (92 loc) · 2.61 KB
/
tester
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
hw=${PWD##*/}
parent=${PWD%/*/*} # TODO not sure why I ha to add this opposed to using ~
# instead but it works.
writeusage () {
echo
echo " tester - UCSD CSE30"
echo " Makes and tests your program simultaneously with the sample program."
echo " The differences in stdout/stderr are shown in a vimdiff."
echo
echo " Usage: tester [program] [solution program] [filename]"
echo
echo " Be sure to run this in a \"pa#\" directory."
echo
}
# If the user doesn't know how to use this
if [[ "$#" < 3 ]]; then
writeusage
exit 1
fi
# First arg is the driver
driver="$1"
my_prog="./$driver"
shift
# Second arg is solution driver name
soldriver="$1"
sample_prog="$parent/public/$soldriver"
shift
#Third arg is the text file
input="$1"
shift
# Make your file
# This makes the default target
make
if [ "$?" -ne 0 ];then
echo
echo
echo " **********************************************"
echo " * Make failed!! Exiting script. *"
echo " **********************************************"
echo " ~ Sorry Dude :( ~"
echo
echo
#Quit script
exit 1
fi
# Remove old output files
rm -f mine sol
count=0 # Count the number of tests performed
passedCount=0 # Count the number of tests passed
OLD_IFS=$IFS # Save the delimiter
IFS=$'\n' # Make the delimiter a newline
# Get lines from file
for line in $(cat $input)
do
# Reset delimiter
IFS=$OLD_IFS
let count++
count_msg="TEST: $count\n"
echo $count_msg
# number test in file to make the results easer to understend
echo "$count_msg: $args" >> mine
echo "$count_msg: $args" >> sol
# Read arguments
args=""
for num in $line; do
args="$args $num"
done
# Create output file taking in stderr & stdout
echo " Attempting to run $my_prog$args ..."
$my_prog$args >> mine 2>&1
# Capture exit code and write it below current test
echo "EXIT CODE: $?\n" >> mine
echo " Running $my_prog$args...\n"
# Save solution output
echo " Attempting to run $sample_prog $args..."
$sample_prog$args >> sol 2>&1
# Capture exit code and write it below current test
echo "EXIT CODE: $?\n" >> sol
echo " Running $sample_prog$args...\n"
if [ "`diff mine sol`" = "" ]; then
let passedCount++
fi
IFS=$'\n'
done < $input
# Compare output files
echo $passedCount/$count tests passed.
echo "Would you like to see the diff file? [y/n]"
read continueKey
if [ "${continueKey}" = "y" ]; then
vimdiff mine sol
fi