Introduce pet-projects dir
[lcapit-junk-code.git] / pet-projects / DLW-1e / das / tests / das-tests
blob0decdad50c6a9a0904e5c8c0dd2695f6a401b4cf
1 #!/bin/bash
3 # Execute DAS' test-suite
5 # Luiz Fernando N. Capitulino
6 # <lcapitulino@gmail.com>
8 # load config file
9 . tests.conf
11 PNAME=$(basename $0)
13 usage()
15 echo "usage: $PNAME [ options ]"
16 echo
17 echo "options:"
18 echo " -h,--help this text"
19 echo " -p1,--pass1 run only first pass tests"
20 echo " -p2,--pass2 run only second pass tests"
21 echo " -err,--error run only error tests"
22 echo " -p,--program run only programs tests"
23 echo
26 compare_files()
28 local expected=$1
29 local output=$2
31 cmp -s $expected $output
32 ret=$?
34 rm -f $output
36 return $ret
39 do_err_test()
41 local file=${1}
42 local ext=$2
43 local input=${file}.asm
44 local output=${file}.out
45 local expected=${file}.${ext}
47 $DAS -o /dev/null $input &> $output
48 if [ $? -ne 1 ]; then
49 return 1
52 compare_files $expected $output
54 return $?
57 do_test()
59 local file=${1}
60 local ext=$2
61 local opt=$3
62 local input=${file}.asm
63 local output=${file}.out
64 local expected=${file}.${ext}
66 $DAS $opt -o $output $input
67 if [ $? -ne 0 ]; then
68 exit 1
71 compare_files $expected $output
73 return $?
76 report_results()
78 local nr_tests=$1
79 local nr_passed=$2
80 local nr_failed=$3
81 local passed_per=0
83 passed_per=$(expr 100 \* $nr_passed)
84 passed_per=$(expr $passed_per / $nr_tests)
86 printf "\n -> %d%% passed" $passed_per
87 printf " [ %d tests %d pass %d error ]\n" $nr_tests \
88 $nr_passed $nr_failed
89 printf "\n"
92 run_test()
94 local message="$1"
95 local asm_files="$2"
96 local ext="$3"
97 local testfunc="$4"
98 local opt=""
99 local nr_tests=0
100 local nr_passed=0
101 local nr_failed=0
102 local file=""
104 if [ "$ext" = "p1" ]; then
105 # das should only execute
106 # first pass
107 opt="-1"
110 printf "* %s tests\n\n" "$message"
112 for file in $asm_files; do
113 ((nr_tests++))
114 printf "\t%-10s " $file
115 $testfunc "$file" "$ext" "$opt"
116 ret=$?
117 if [ $ret -eq 0 ]; then
118 printf "PASSED\n"
119 ((nr_passed++))
120 else
121 printf "FAILED [ %d ]\n" $ret
122 ((nr_failed++))
124 done
126 report_results $nr_tests $nr_passed $nr_failed
129 # Collect command-line options
131 while [ $# -gt 0 ]; do
132 case $1 in
133 -h|--help)
134 usage
135 exit 0
137 -p1|--pass1)
138 P2_TESTS=0
139 ERR_TESTS=0
140 PROG_TESTS=0
142 -p2|--pass2)
143 P1_TESTS=0
144 ERR_TESTS=0
145 PROG_TESTS=0
147 -err|--error)
148 P1_TESTS=0
149 P2_TESTS=0
150 PROG_TESTS=0
152 -p|--program)
153 P1_TESTS=0
154 P2_TESTS=0
155 ERR_TESTS=0
158 echo "ERROR: unknown option '$1'" > /dev/stderr
159 exit 1
161 esac
162 shift
163 done
165 # main program
167 printf "\n"
169 if [ $P1_TESTS -eq 1 ]; then
170 run_test "$P1_NAME" "$P1_FILES" "$P1_EXT" "$P1_TEST"
173 if [ $P2_TESTS -eq 1 ]; then
174 run_test "$P2_NAME" "$P2_FILES" "$P2_EXT" "$P2_TEST"
177 if [ $ERR_TESTS -eq 1 ]; then
178 run_test "$ERR_NAME" "$ERR_FILES" "$ERR_EXT" "$ERR_TEST"
181 if [ $PROG_TESTS -eq 1 ]; then
182 run_test "$PROG_NAME" "$PROG_FILES" "$PROG_EXT" "$PROG_TEST"