Skip to content

Commit b9cd2aa

Browse files
committed
update testing infrastructure to avoid per platform expected output where possible
1 parent 8d7d3d0 commit b9cd2aa

File tree

271 files changed

+202
-2677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

271 files changed

+202
-2677
lines changed

docs/assign_function_to_int.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

docs/assign_to_array.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

docs/function-definition-not-allowed-here.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

docs/function-variable-clash.md

Lines changed: 0 additions & 32 deletions
This file was deleted.

docs/stack_use_after_return.md

Lines changed: 0 additions & 43 deletions
This file was deleted.

tests/do_tests.sh

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ cd ../..
3535
clang_version=$($c_compiler -v 2>&1|sed 's/.* version *//;s/ .*//;1q'|cut -d. -f1,2)
3636
platform=$($c_compiler -v 2>&1|sed '1d;s/.* //;2q')
3737

38-
expected_output_dir="$tests_dir/expected_output/clang-$clang_version-$platform"
39-
mkdir -p $expected_output_dir
38+
version_expected_output_dir="$tests_dir/expected_output/clang-$clang_version-$platform"
39+
default_expected_output_dir="$tests_dir/expected_output/default"
40+
mkdir -p "$version_expected_output_dir" "$default_expected_output_dir"
4041
test_failed=0
4142

4243
for src_file in tests/extracted_compile_time_errors/*.c tests/compile_time_errors/*.c tests/run_time_errors/*.* tests/run_time_no_errors/*.* tests/check_output/*.sh
@@ -54,14 +55,14 @@ do
5455
dcc_flags=
5556
suffix=`echo $compile_options|sed 's/^dcc_flags=//;s/ /_/g;s/["$]//g;s/src_file//'`
5657
eval $compile_options
57-
expected_output_file="$expected_output_dir/`basename $src_file .c`$suffix.txt"
58+
expected_output_file="`basename $src_file .c`$suffix.txt"
5859
#echo "$dcc" --c-compiler=$c_compiler $dcc_flags "$src_file"
5960
"$dcc" --c-compiler=$c_compiler $dcc_flags "$src_file" 2>tmp.actual_stderr >/dev/null
6061
test ! -s tmp.actual_stderr && DCC_DEBUG=1 ./a.out </dev/null 2>>tmp.actual_stderr >tmp.actual_stdout
6162
;;
6263

6364
*.sh)
64-
expected_output_file="$expected_output_dir/`basename $src_file .sh`.txt"
65+
expected_output_file="`basename $src_file .sh`.txt"
6566
$src_file </dev/null 2>tmp.actual_stderr >/dev/null
6667
;;
6768

@@ -93,34 +94,58 @@ do
9394
actual_output_file=tmp.actual_stderr
9495
esac
9596

96-
if test ! -e "$expected_output_file"
97+
version_expected_output_dir="$tests_dir/expected_output/clang-$clang_version-$platform"
98+
default_expected_output_dir="$tests_dir/expected_output/default"
99+
100+
default_expected_output="$default_expected_output_dir/$expected_output_file"
101+
version_expected_output="$version_expected_output_dir/$expected_output_file"
102+
103+
sed -e "$REMOVE_NON_DETERMINATE_VALUES" $actual_output_file >tmp.corrected_output
104+
105+
if test ! -e "$default_expected_output"
97106
then
98107
echo
99-
echo "'$expected_output_file' does not exist, creating with these contents:"
108+
echo "'$default_expected_output' does not exist, creating with these contents:"
100109
echo
101110
cat "$actual_output_file"
102-
sed "$REMOVE_NON_DETERMINATE_VALUES" $actual_output_file >"$expected_output_file"
111+
cp tmp.corrected_output "$default_expected_output"
103112
echo
104-
echo "if above is not correct output for this test: rm '$expected_output_file' "
113+
echo "if above is not correct output for this test: rm '$default_expected_output' "
105114
continue
106115
fi
107116

108-
sed -e "$REMOVE_NON_DETERMINATE_VALUES" $actual_output_file >tmp.corrected_output
109-
if diff -iBw "$expected_output_file" tmp.corrected_output >/dev/null
117+
118+
expected="$default_expected_output"
119+
test -r "$version_expected_output" && expected="$default_expected_output"
120+
121+
if diff -iBw "$expected" tmp.corrected_output >/dev/null
110122
then
111123
echo -n .
112-
else
113-
echo
114-
echo "Test dcc $dcc_flags failed output different to expected - rm '$expected_output_file' if output is correct"
115-
echo Differences are:
116-
echo
117-
diff -u -iBw "$expected_output_file" tmp.corrected_output
118-
echo
119-
echo "if output is correct: rm '$expected_output_file'"
120-
test_failed=1
121124
continue
122125
fi
126+
127+
128+
echo
129+
echo "Test dcc $dcc_flags failed - output different to expected"
130+
echo Differences are:
131+
echo
132+
diff -u -iBw "$expected" tmp.corrected_output
133+
echo
134+
echo "Enter u to update expected output."
135+
echo "Enter p to create plaform-specific expected output."
136+
137+
echo -n "Action? "
138+
read response
139+
case "$response" in
140+
u)
141+
cp tmp.corrected_output "$default_expected_output"
142+
;;
143+
p)
144+
cp tmp.corrected_output "$version_expected_output"
145+
;;
146+
*)
147+
exit 1
148+
esac
123149
done
124150
done
125-
test $test_failed = 0 && echo && echo All tests passed
126-
exit $test_failed
151+
echo All tests passed

tests/expected_output/clang-6.0-x86_64-pc-linux-gnu/call_stack_null.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
tests/run_time_errors/call_stack_null.c:5:11: runtime error: load of null pointer of type 'int'
22

3-
Execution stopped here in f3(a=NULL) in tests/run_time_errors/call_stack_null.c at line 5:
3+
Execution stopped in f3(a=NULL) in tests/run_time_errors/call_stack_null.c at line 5:
44

55
int f3(int *a) {
66
int b[] = {0};
77
--> return b[*a];
88
}
9-
int f2(int *a) {
109

1110
Values when execution stopped:
1211

tests/expected_output/clang-6.0-x86_64-pc-linux-gnu/call_stack_uninitialized.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ tests/run_time_errors/call_stack_uninitialized.c:4:9: runtime error: load of mis
22
0x<deleted-hexadecimal-constant>: note: pointer points here
33
<memory cannot be printed>
44

5-
Execution stopped here in f3(a=<uninitialized value>) in tests/run_time_errors/call_stack_uninitialized.c at line 4:
6-
5+
Execution stopped in f3(a=<uninitialized value>) in tests/run_time_errors/call_stack_uninitialized.c at line 4:
76

87
int f3(int *a) {
98
--> return *a;
109
}
11-
int f2(int *a) {
1210

1311
Values when execution stopped:
1412

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
tests/run_time_errors/dereference_null_with_arrow.c:8:8: runtime error: member access within null pointer of type 'struct list_node'
22

3-
Execution stopped here in main() in tests/run_time_errors/dereference_null_with_arrow.c at line 8:
3+
Execution stopped in main() in tests/run_time_errors/dereference_null_with_arrow.c at line 8:
44

5-
int main(void) {
5+
int main(void) {
66
struct list_node *a = NULL;
77
--> a->data = 42;
88
}
99

1010
Values when execution stopped:
1111

1212
a = <deleted-value>
13-
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
tests/run_time_errors/dereference_null_with_arrow_arrow.c:9:14: runtime error: member access within null pointer of type 'struct list_node'
22

3-
Execution stopped here in main() in tests/run_time_errors/dereference_null_with_arrow_arrow.c at line 9:
3+
Execution stopped in main() in tests/run_time_errors/dereference_null_with_arrow_arrow.c at line 9:
44

5+
int main(void) {
56
struct list_node s = {0};
67
struct list_node *a = &s;
78
--> a->next->next->data = 42;
@@ -11,4 +12,3 @@ Values when execution stopped:
1112

1213
s = {next = NULL, data = <deleted-value>
1314
a->next = <deleted-value>
14-

0 commit comments

Comments
 (0)