/
testmywcdiff
executable file
·77 lines (66 loc) · 2 KB
/
testmywcdiff
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
#!/bin/bash
#---------------------------------------------------------------------
# testmywcdiff
# Author: Bob Dondero
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# testmywcdiff is a testing script for the mywc program.
# To run it, issue the command "./testmywcdiff somefile ",
# where somefile is the name of an input file.
#
# To use it, the working directory must contain:
# (1) mywcc, an executable binary file built from mywc.c, and
# (2) mywcs, an executable binary file built from mywc.s
#
# The script runs the mywcs program and the mywcc program on the
# specified file, and makes sure that the two programs have the
# same exit status and write the same characters to stdout.
#---------------------------------------------------------------------
# Validate the argument.
if [ "$#" != "1" ]; then
echo "Usage: testmywcdiff file"
exit 1
fi
if [ ! -e "$1" ]; then
echo "File $1 does not exist."
exit 1
fi
# Capture the argument.
file=$1
echo "==============================================================="
echo "Test with input file" $file
echo "==============================================================="
# Run mywcc on the input file, and capture its exit status.
./mywcc < $file > __stdout1
ret1=$?
# Run mywcs on the input file, and capture its exit status.
./mywcs < $file > __stdout2
ret2=$?
# Check the exit status.
if [ $ret1 != $ret2 ]; then
echo
echo "***** Exit status is incorrect."
echo
echo "********** This is the correct exit status:"
echo $ret1
echo
echo "********** Your program had this exit status:"
echo $ret2
echo
fi
# Check the stdout streams.
diff -c __stdout1 __stdout2 > __diffout
if [ $? != "0" ]; then
echo
echo "***** stdout is incorrect."
echo
echo "********** This is the correct stdout:"
cat __stdout1
echo
echo "********** This is your program's stdout:"
cat __stdout2
echo
fi
# Clean up.
echo
rm __stdout1 __stdout2 __diffout