aboutsummaryrefslogtreecommitdiffstats
path: root/tests/all.sh
blob: 980ddad35c67a88d02934fade76f068f3b2035d8 (plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#! /bin/sh
#
# Copyright 2018 Gavin D. Howard
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
#

set -e

script="$0"

testdir=$(dirname "$script")

if [ "$#" -ge 1 ]; then
	d="$1"
	shift
else
	printf 'usage: %s dir [run_extended_tests] [run_reference_tests] [generate_tests] [exec args...]\n' "$script"
	exit 1
fi

if [ "$#" -lt 1 ]; then
	extra=1
else
	extra="$1"
	shift
fi

if [ "$#" -lt 1 ]; then
	refs=1
else
	refs="$1"
	shift
fi

if [ "$#" -lt 1 ]; then
	generate_tests=1
else
	generate_tests="$1"
	shift
fi

if [ "$#" -lt 1 ]; then
	exe="$testdir/../bin/$d"
else
	exe="$1"
	shift
fi

stars="***********************************************************************"
printf '%s\n' "$stars"

if [ "$d" = "bc" ]; then
	halt="quit"
else
	halt="q"
fi

printf '\nRunning %s tests...\n\n' "$d"

while read t; do

	if [ "$extra" -eq 0  ]; then
		if [ "$t" = "trunc" -o "$t" = "places" -o "$t" = "shift" -o "$t" = "lib2" \
		     -o "$t" = "scientific" -o "$t" = "engineering" ]
		then
			printf 'Skipping %s %s\n' "$d" "$t"
			continue
		fi
	fi

	sh "$testdir/test.sh" "$d" "$t" "$generate_tests" "$exe" "$@"

done < "$testdir/$d/all.txt"

sh "$testdir/stdin.sh" "$d" "$exe" "$@"

sh "$testdir/scripts.sh" "$d" "$refs" "$generate_tests" "$exe" "$@"
sh "$testdir/errors.sh" "$d" "$exe" "$@"

num=100000000000000000000000000000000000000000000000000000000000000000000000000000
numres="$num"
num70="10000000000000000000000000000000000000000000000000000000000000000000\\
0000000000"

if [ "$d" = "bc" ]; then
	halt="quit"
	opt="x"
	lopt="extended-register"
	line_var="BC_LINE_LENGTH"
else
	halt="q"
	opt="l"
	lopt="mathlib"
	line_var="DC_LINE_LENGTH"
	num="$num pR"
fi

printf '\nRunning %s quit test...\n' "$d"

printf '%s\n' "$halt" | "$exe" "$@" > /dev/null 2>&1

base=$(basename "$exe")

if [ "$base" != "bc" -a "$base" != "dc" ]; then
	exit 0
fi

if [ "$d" = "bc" ]; then
	printf 'Running %s environment var test...\n' "$d"
	export BC_ENV_ARGS=" -l -q"
	printf 's(.02893)\n' | "$exe" "$@" > /dev/null
fi

out1="$testdir/../.log_$d.txt"
out2="$testdir/../.log_${d}_test.txt"

printf 'Running %s line length tests...\n' "$d"

printf '%s\n' "$numres" > "$out1"

export "$line_var"=80
printf '%s\n' "$num" | "$exe" "$@" > "$out2"

diff "$out1" "$out2"

printf '%s\n' "$num70" > "$out1"

export "$line_var"=2147483647
printf '%s\n' "$num" | "$exe" "$@" > "$out2"

diff "$out1" "$out2"

printf 'Running %s arg tests...\n' "$d"

f="$testdir/$d/add.txt"
exprs=$(cat "$f")
results=$(cat "$testdir/$d/add_results.txt")

printf '%s\n%s\n%s\n%s\n' "$results" "$results" "$results" "$results" > "$out1"

"$exe" "$@" -e "$exprs" -f "$f" --expression "$exprs" --file "$f" > "$out2"

diff "$out1" "$out2"

if [ "$d" = "bc" ]; then
	printf '%s\n' "$halt" | "$exe" "$@" -i > /dev/null 2>&1
fi

printf '%s\n' "$halt" | "$exe" "$@" -h > /dev/null
printf '%s\n' "$halt" | "$exe" "$@" -v > /dev/null
printf '%s\n' "$halt" | "$exe" "$@" -V > /dev/null

set +e

"$exe" "$@" -f "saotehasotnehasthistohntnsahxstnhalcrgxgrlpyasxtsaosysxsatnhoy.txt" > /dev/null 2>&1
err="$?"

if [ "$err" -eq 0 ]; then
	printf '%s did not return an error (%d) on invalid file argument test\n' "$d" "$err"
	printf 'exiting...\n'
	exit 1
fi

"$exe" "$@" "-$opt" -e "$exprs" > /dev/null 2>&1
err="$?"

if [ "$err" -eq 0 ]; then
	printf '%s did not return an error (%d) on invalid option argument test\n' "$d" "$err"
	printf 'exiting...\n'
	exit 1
fi

"$exe" "$@" "--$lopt" -e "$exprs" > /dev/null 2>&1
err="$?"

if [ "$err" -eq 0 ]; then
	printf '%s did not return an error (%d) on invalid long option argument test\n' "$d" "$err"
	printf 'exiting...\n'
	exit 1
fi

printf 'Running %s directory test...\n' "$d"

"$exe" "$@" "$testdir" > /dev/null 2>&1
err="$?"

if [ "$err" -eq 0 ]; then
	printf '%s did not return an error (%d) on directory test\n' "$d" "$err"
	printf 'exiting...\n'
	exit 1
fi

printf 'Running %s binary file test...\n' "$d"

bin="/bin/sh"

"$exe" "$@" "$bin" > /dev/null 2>&1
err="$?"

if [ "$err" -eq 0 ]; then
	printf '%s did not return an error (%d) on binary file test\n' "$d" "$err"
	printf 'exiting...\n'
	exit 1
fi

printf 'Running %s binary stdin test...\n' "$d"

cat "$bin" | "$exe" "$@" > /dev/null 2>&1
err="$?"

if [ "$err" -eq 0 ]; then
	printf '%s did not return an error (%d) on binary stdin test\n' "$d" "$err"
	printf 'exiting...\n'
	exit 1
fi

if [ "$d" = "bc" ]; then

	printf 'Running %s limits tests...\n' "$d"
	printf 'limits\n' | "$exe" "$@" > "$out2" /dev/null 2>&1

	if [ ! -s "$out2" ]; then
		printf '%s did not produce output on the limits test\n' "$d"
		printf 'exiting...\n'
		exit 1
	fi

fi

printf '\n%s\n' "$stars"