Provide a better error reporting for failed cmdline tests.

This commit is contained in:
Marenz 2021-07-12 16:31:29 +02:00
parent ae519c1278
commit dea201800f
3 changed files with 44 additions and 29 deletions

View File

@ -25,20 +25,24 @@ OLDARGS=(--optimize --combined-json "abi,asm,ast,bin,bin-runtime,devdoc,interfac
function compileFull() function compileFull()
{ {
local expected_exit_code=0 local expected_exit_code=0
local expect_output=0 local expect_output='none'
if [[ $1 = '-e' ]]; then
expected_exit_code=1 case "$1" in
expect_output=1 '--expect-errors')
shift; expected_exit_code=1
fi expect_output='warnings-or-errors'
if [[ $1 = '-w' ]]; then shift;
expect_output=1 ;;
shift; '--expect-warnings')
fi expect_output='warnings-or-errors'
if [[ $1 = '-o' ]]; then shift;
expect_output=2 ;;
shift; '--ignore-warnings')
fi expect_output='any'
shift;
;;
esac
local args=("${FULLARGS[@]}") local args=("${FULLARGS[@]}")
if [[ $1 = '-v' ]]; then if [[ $1 = '-v' ]]; then
if (echo "$2" | grep -Po '(?<=0.4.)\d+' >/dev/null); then if (echo "$2" | grep -Po '(?<=0.4.)\d+' >/dev/null); then
@ -71,20 +75,31 @@ function compileFull()
set -e set -e
rm "$stderr_path" rm "$stderr_path"
if [[ \ if [[
("$exit_code" -ne "$expected_exit_code" || \ $exit_code != "$expected_exit_code" ||
( $expect_output -eq 0 && -n "$errors" ) || \ $errors != "" && $expect_output == 'none' ||
( $expect_output -ne 0 && $expected_exit_code -eq 0 && $expect_output -ne 2 && -z "$errors" )) $errors == "" && $expect_output != 'none' && $expect_output != 'any' && $expected_exit_code == 0
]] ]]
then then
printError "Unexpected compilation result:" printError "TEST FAILURE"
printError "Expected failure: $expected_exit_code - Expected warning / error output: $expect_output" printError "Actual exit code: $exit_code"
printError "Was failure: $exit_code" printError "Expected exit code: $expected_exit_code"
printError "==== Output ===="
echo "$errors" echo "$errors"
printError "== Output end =="
printError ""
case "$expect_output" in
'none') printError "No output was expected." ;;
'warnings-or-errors') printError "Expected warnings or errors." ;;
esac
printError ""
printError "While calling:" printError "While calling:"
echo "\"$SOLC\" ${args[*]} ${files[*]}" echo "\"$SOLC\" ${args[*]} ${files[*]}"
printError "Inside directory:" printError "Inside directory:"
pwd echo " $(pwd)"
printError "Input was:"
cat -- "${files[@]}"
false false
fi fi
} }

View File

@ -156,11 +156,11 @@ SOLTMPDIR=$(mktemp -d)
if ( ! grep -E "This will not compile after" "$f" >/dev/null && \ if ( ! grep -E "This will not compile after" "$f" >/dev/null && \
grep -E "This will not compile|import \"" "$f" >/dev/null ) grep -E "This will not compile|import \"" "$f" >/dev/null )
then then
opts=(-e) opts=(--expect-errors)
fi fi
# ignore warnings in this case # ignore warnings in this case
opts+=(-o) opts+=(--ignore-warnings)
findMinimalVersion "$f" findMinimalVersion "$f"
if [[ "$version" == "" ]] if [[ "$version" == "" ]]

View File

@ -369,7 +369,7 @@ printTask "Compiling various other contracts and libraries..."
do do
echo " - $dir" echo " - $dir"
cd "$dir" cd "$dir"
compileFull -w ./*.sol ./*/*.sol compileFull --expect-warnings ./*.sol ./*/*.sol
cd .. cd ..
done done
) )
@ -397,15 +397,15 @@ SOLTMPDIR=$(mktemp -d)
# are used (in the style guide) # are used (in the style guide)
if grep -E "This will not compile|import \"" "$f" >/dev/null if grep -E "This will not compile|import \"" "$f" >/dev/null
then then
opts=(-e) opts=(--expect-errors)
fi fi
if grep "This will report a warning" "$f" >/dev/null if grep "This will report a warning" "$f" >/dev/null
then then
opts+=(-w) opts+=(--expect-warnings)
fi fi
if grep "This may report a warning" "$f" >/dev/null if grep "This may report a warning" "$f" >/dev/null
then then
opts+=(-o) opts+=(--ignore-warnings)
fi fi
# Disable the version pragma in code snippets that only work with the current development version. # Disable the version pragma in code snippets that only work with the current development version.