Merge pull request #11645 from ethereum/slightly-nicer-error-reporting

[Trivial] Provide a better error reporting for failed cmdline tests.
This commit is contained in:
Kamil Śliwak 2021-08-04 15:47:14 +02:00 committed by GitHub
commit 2d5b9036c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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()
{
local expected_exit_code=0
local expect_output=0
if [[ $1 = '-e' ]]; then
expected_exit_code=1
expect_output=1
shift;
fi
if [[ $1 = '-w' ]]; then
expect_output=1
shift;
fi
if [[ $1 = '-o' ]]; then
expect_output=2
shift;
fi
local expect_output='none'
case "$1" in
'--expect-errors')
expected_exit_code=1
expect_output='warnings-or-errors'
shift;
;;
'--expect-warnings')
expect_output='warnings-or-errors'
shift;
;;
'--ignore-warnings')
expect_output='any'
shift;
;;
esac
local args=("${FULLARGS[@]}")
if [[ $1 = '-v' ]]; then
if (echo "$2" | grep -Po '(?<=0.4.)\d+' >/dev/null); then
@ -71,20 +75,31 @@ function compileFull()
set -e
rm "$stderr_path"
if [[ \
("$exit_code" -ne "$expected_exit_code" || \
( $expect_output -eq 0 && -n "$errors" ) || \
( $expect_output -ne 0 && $expected_exit_code -eq 0 && $expect_output -ne 2 && -z "$errors" ))
if [[
$exit_code != "$expected_exit_code" ||
$errors != "" && $expect_output == 'none' ||
$errors == "" && $expect_output != 'none' && $expect_output != 'any' && $expected_exit_code == 0
]]
then
printError "Unexpected compilation result:"
printError "Expected failure: $expected_exit_code - Expected warning / error output: $expect_output"
printError "Was failure: $exit_code"
printError "TEST FAILURE"
printError "Actual exit code: $exit_code"
printError "Expected exit code: $expected_exit_code"
printError "==== Output ===="
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:"
echo "\"$SOLC\" ${args[*]} ${files[*]}"
echo "\"$SOLC\" ${args[*]} ${files[*]}"
printError "Inside directory:"
pwd
echo " $(pwd)"
printError "Input was:"
cat -- "${files[@]}"
false
fi
}

View File

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

View File

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