Skip to content

Commit 2d5b903

Browse files
authored
Merge pull request #11645 from ethereum/slightly-nicer-error-reporting
[Trivial] Provide a better error reporting for failed cmdline tests.
2 parents e18dec8 + dea2018 commit 2d5b903

File tree

3 files changed

+44
-29
lines changed

3 files changed

+44
-29
lines changed

scripts/common_cmdline.sh

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,24 @@ OLDARGS=(--optimize --combined-json "abi,asm,ast,bin,bin-runtime,devdoc,interfac
2525
function compileFull()
2626
{
2727
local expected_exit_code=0
28-
local expect_output=0
29-
if [[ $1 = '-e' ]]; then
30-
expected_exit_code=1
31-
expect_output=1
32-
shift;
33-
fi
34-
if [[ $1 = '-w' ]]; then
35-
expect_output=1
36-
shift;
37-
fi
38-
if [[ $1 = '-o' ]]; then
39-
expect_output=2
40-
shift;
41-
fi
28+
local expect_output='none'
29+
30+
case "$1" in
31+
'--expect-errors')
32+
expected_exit_code=1
33+
expect_output='warnings-or-errors'
34+
shift;
35+
;;
36+
'--expect-warnings')
37+
expect_output='warnings-or-errors'
38+
shift;
39+
;;
40+
'--ignore-warnings')
41+
expect_output='any'
42+
shift;
43+
;;
44+
esac
45+
4246
local args=("${FULLARGS[@]}")
4347
if [[ $1 = '-v' ]]; then
4448
if (echo "$2" | grep -Po '(?<=0.4.)\d+' >/dev/null); then
@@ -71,20 +75,31 @@ function compileFull()
7175
set -e
7276
rm "$stderr_path"
7377

74-
if [[ \
75-
("$exit_code" -ne "$expected_exit_code" || \
76-
( $expect_output -eq 0 && -n "$errors" ) || \
77-
( $expect_output -ne 0 && $expected_exit_code -eq 0 && $expect_output -ne 2 && -z "$errors" ))
78+
if [[
79+
$exit_code != "$expected_exit_code" ||
80+
$errors != "" && $expect_output == 'none' ||
81+
$errors == "" && $expect_output != 'none' && $expect_output != 'any' && $expected_exit_code == 0
7882
]]
7983
then
80-
printError "Unexpected compilation result:"
81-
printError "Expected failure: $expected_exit_code - Expected warning / error output: $expect_output"
82-
printError "Was failure: $exit_code"
84+
printError "TEST FAILURE"
85+
printError "Actual exit code: $exit_code"
86+
printError "Expected exit code: $expected_exit_code"
87+
printError "==== Output ===="
8388
echo "$errors"
89+
printError "== Output end =="
90+
printError ""
91+
case "$expect_output" in
92+
'none') printError "No output was expected." ;;
93+
'warnings-or-errors') printError "Expected warnings or errors." ;;
94+
esac
95+
96+
printError ""
8497
printError "While calling:"
85-
echo "\"$SOLC\" ${args[*]} ${files[*]}"
98+
echo "\"$SOLC\" ${args[*]} ${files[*]}"
8699
printError "Inside directory:"
87-
pwd
100+
echo " $(pwd)"
101+
printError "Input was:"
102+
cat -- "${files[@]}"
88103
false
89104
fi
90105
}

scripts/docs_version_pragma_check.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ SOLTMPDIR=$(mktemp -d)
156156
if ( ! grep -E "This will not compile after" "$f" >/dev/null && \
157157
grep -E "This will not compile|import \"" "$f" >/dev/null )
158158
then
159-
opts=(-e)
159+
opts=(--expect-errors)
160160
fi
161161

162162
# ignore warnings in this case
163-
opts+=(-o)
163+
opts+=(--ignore-warnings)
164164

165165
findMinimalVersion "$f"
166166
if [[ "$version" == "" ]]

test/cmdlineTests.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ printTask "Compiling various other contracts and libraries..."
369369
do
370370
echo " - $dir"
371371
cd "$dir"
372-
compileFull -w ./*.sol ./*/*.sol
372+
compileFull --expect-warnings ./*.sol ./*/*.sol
373373
cd ..
374374
done
375375
)
@@ -397,15 +397,15 @@ SOLTMPDIR=$(mktemp -d)
397397
# are used (in the style guide)
398398
if grep -E "This will not compile|import \"" "$f" >/dev/null
399399
then
400-
opts=(-e)
400+
opts=(--expect-errors)
401401
fi
402402
if grep "This will report a warning" "$f" >/dev/null
403403
then
404-
opts+=(-w)
404+
opts+=(--expect-warnings)
405405
fi
406406
if grep "This may report a warning" "$f" >/dev/null
407407
then
408-
opts+=(-o)
408+
opts+=(--ignore-warnings)
409409
fi
410410

411411
# Disable the version pragma in code snippets that only work with the current development version.

0 commit comments

Comments
 (0)