Merge pull request #6488 from sifmelcara/cmdlineTests-auto-update

Auto-correct command line tests
This commit is contained in:
Erik Kundt 2019-04-11 12:17:43 +02:00 committed by GitHub
commit e97d4b4aec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 75 additions and 37 deletions

View File

@ -93,6 +93,27 @@ function compileFull()
fi fi
} }
function ask_expectation_update()
{
local newExpectation="${1}"
local expectationFile="${2}"
while true;
do
set +e
read -t10 -p "(u)pdate expectation/(q)uit? "
if [ $? -gt 128 ];
then
echo -e "\nUser input timed out."
exit 1
fi
set -e
case $REPLY in
u* ) echo "$newExpectation" > $expectationFile ; break;;
q* ) exit 1;;
esac
done
}
# General helper function for testing SOLC behaviour, based on file name, compile opts, exit code, stdout and stderr. # General helper function for testing SOLC behaviour, based on file name, compile opts, exit code, stdout and stderr.
# An failure is expected. # An failure is expected.
function test_solc_behaviour() function test_solc_behaviour()
@ -103,17 +124,22 @@ function test_solc_behaviour()
local stdout_expected="${4}" local stdout_expected="${4}"
local exit_code_expected="${5}" local exit_code_expected="${5}"
local stderr_expected="${6}" local stderr_expected="${6}"
local stdout_expectation_file="${7}" # the file to write to when user chooses to update stdout expectation
local stderr_expectation_file="${8}" # the file to write to when user chooses to update stderr expectation
local stdout_path=`mktemp` local stdout_path=`mktemp`
local stderr_path=`mktemp` local stderr_path=`mktemp`
trap "rm -f $stdout_path $stderr_path" EXIT
if [[ "$exit_code_expected" = "" ]]; then exit_code_expected="0"; fi if [[ "$exit_code_expected" = "" ]]; then exit_code_expected="0"; fi
local solc_command="$SOLC ${filename} ${solc_args}"
if [[ -n "$solc_stdin" ]]; then solc_command+=" <$solc_stdin" ; fi
if [[ -n "$stdout_path" ]]; then solc_command+=" 1>$stdout_path"; fi
if [[ -n "$stderr_path" ]]; then solc_command+=" 2>$stderr_path"; fi
set +e set +e
if [[ "$solc_stdin" = "" ]] eval "$solc_command"
then
"$SOLC" "${filename}" ${solc_args} 1>$stdout_path 2>$stderr_path
else
"$SOLC" "${filename}" ${solc_args} <$solc_stdin 1>$stdout_path 2>$stderr_path
fi
exitCode=$? exitCode=$?
set -e set -e
@ -133,37 +159,44 @@ function test_solc_behaviour()
if [[ $exitCode -ne "$exit_code_expected" ]] if [[ $exitCode -ne "$exit_code_expected" ]]
then then
printError "Incorrect exit code. Expected $exit_code_expected but got $exitCode." printError "Incorrect exit code. Expected $exit_code_expected but got $exitCode."
rm -f $stdout_path $stderr_path
exit 1 exit 1
fi fi
if [[ "$(cat $stdout_path)" != "${stdout_expected}" ]] if [[ "$(cat $stdout_path)" != "${stdout_expected}" ]]
then then
printError "Incorrect output on stdout received. Expected:" printError "Incorrect output on stdout received. Expected:"
echo -e "${stdout_expected}" echo "${stdout_expected}"
printError "But got:" printError "But got:"
cat $stdout_path cat $stdout_path
printError "When running $SOLC ${filename} ${solc_args} <$solc_stdin"
rm -f $stdout_path $stderr_path printError "When running $solc_command"
exit 1
if [ -n "$stdout_expectation_file" ]
then
ask_expectation_update "$(cat $stdout_path)" "$stdout_expectation_file"
else
exit 1
fi
fi fi
if [[ "$(cat $stderr_path)" != "${stderr_expected}" ]] if [[ "$(cat $stderr_path)" != "${stderr_expected}" ]]
then then
printError "Incorrect output on stderr received. Expected:" printError "Incorrect output on stderr received. Expected:"
echo -e "${stderr_expected}" echo "${stderr_expected}"
printError "But got:" printError "But got:"
cat $stderr_path cat $stderr_path
printError "When running $SOLC ${filename} ${solc_args} <$solc_stdin"
rm -f $stdout_path $stderr_path printError "When running $solc_command"
exit 1
if [ -n "$stderr_expectation_file" ]
then
ask_expectation_update "$(cat $stderr_path)" "$stderr_expectation_file"
else
exit 1
fi
fi fi
rm -f $stdout_path $stderr_path
} }
@ -210,14 +243,14 @@ printTask "Testing unknown options..."
printTask "Testing passing files that are not found..." printTask "Testing passing files that are not found..."
test_solc_behaviour "file_not_found.sol" "" "" "" 1 "\"file_not_found.sol\" is not found." test_solc_behaviour "file_not_found.sol" "" "" "" 1 "\"file_not_found.sol\" is not found." "" ""
printTask "Testing passing files that are not files..." printTask "Testing passing files that are not files..."
test_solc_behaviour "." "" "" "" 1 "\".\" is not a valid file." test_solc_behaviour "." "" "" "" 1 "\".\" is not a valid file." "" ""
printTask "Testing passing empty remappings..." printTask "Testing passing empty remappings..."
test_solc_behaviour "${0}" "=/some/remapping/target" "" "" 1 "Invalid remapping: \"=/some/remapping/target\"." test_solc_behaviour "${0}" "=/some/remapping/target" "" "" 1 "Invalid remapping: \"=/some/remapping/target\"." "" ""
test_solc_behaviour "${0}" "ctx:=/some/remapping/target" "" "" 1 "Invalid remapping: \"ctx:=/some/remapping/target\"." test_solc_behaviour "${0}" "ctx:=/some/remapping/target" "" "" 1 "Invalid remapping: \"ctx:=/some/remapping/target\"." "" ""
printTask "Running general commandline tests..." printTask "Running general commandline tests..."
( (
@ -228,18 +261,28 @@ printTask "Running general commandline tests..."
then then
inputFile="" inputFile=""
stdin="${tdir}/input.json" stdin="${tdir}/input.json"
stdout=$(cat ${tdir}/output.json 2>/dev/null || true) stdout="$(cat ${tdir}/output.json 2>/dev/null || true)"
stdoutExpectationFile="$(pwd)/${tdir}/output.json"
args="--standard-json "$(cat ${tdir}/args 2>/dev/null || true) args="--standard-json "$(cat ${tdir}/args 2>/dev/null || true)
else else
inputFile="${tdir}input.sol" inputFile="${tdir}input.sol"
stdin="" stdin=""
stdout=$(cat ${tdir}/output 2>/dev/null || true) stdout="$(cat ${tdir}/output 2>/dev/null || true)"
stdoutExpectationFile="$(pwd)/${tdir}/output"
args=$(cat ${tdir}/args 2>/dev/null || true) args=$(cat ${tdir}/args 2>/dev/null || true)
fi fi
exitCode=$(cat ${tdir}/exit 2>/dev/null || true) exitCode=$(cat ${tdir}/exit 2>/dev/null || true)
err=$(cat ${tdir}/err 2>/dev/null || true) err="$(cat ${tdir}/err 2>/dev/null || true)"
stderrExpectationFile="${tdir}/err"
printTask " - ${tdir}" printTask " - ${tdir}"
test_solc_behaviour "$inputFile" "$args" "$stdin" "$stdout" "$exitCode" "$err" test_solc_behaviour "$inputFile" \
"$args" \
"$stdin" \
"$stdout" \
"$exitCode" \
"$err" \
"$stdoutExpectationFile" \
"$stderrExpectationFile"
done done
) )

View File

@ -1,3 +1,3 @@
gas_test_abiv2/input.sol:2:1: Warning: Experimental features are turned on. Do not use experimental features on live deployments. gas_test_abiv2/input.sol:2:1: Warning: Experimental features are turned on. Do not use experimental features on live deployments.
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
^-------------------------------^ ^-------------------------------^

View File

@ -65,4 +65,3 @@ sub_0: assembly {
/* "object_compiler/input.sol":407:422 */ /* "object_compiler/input.sol":407:422 */
return return
} }

View File

@ -1 +1 @@
{"sources":{"A":{"id":0}}} {"sources":{"A":{"id":0}}}

View File

@ -1 +1 @@
{"errors":[{"component":"general","formattedMessage":"Unknown key \"notThere\"","message":"Unknown key \"notThere\"","severity":"error","type":"JSONError"}]} {"errors":[{"component":"general","formattedMessage":"Unknown key \"notThere\"","message":"Unknown key \"notThere\"","severity":"error","type":"JSONError"}]}

View File

@ -1,2 +1 @@
{"errors":[{"component":"general","formattedMessage":"\"auxiliaryInput\" must be an object","message":"\"auxiliaryInput\" must be an object","severity":"error","type":"JSONError"}]} {"errors":[{"component":"general","formattedMessage":"\"auxiliaryInput\" must be an object","message":"\"auxiliaryInput\" must be an object","severity":"error","type":"JSONError"}]}

View File

@ -1 +1 @@
{"errors":[{"component":"general","formattedMessage":"Yul mode only supports exactly one input file.","message":"Yul mode only supports exactly one input file.","severity":"error","type":"JSONError"}]} {"errors":[{"component":"general","formattedMessage":"Yul mode only supports exactly one input file.","message":"Yul mode only supports exactly one input file.","severity":"error","type":"JSONError"}]}

View File

@ -1 +1 @@
{"errors":[{"component":"general","formattedMessage":"Yul mode only supports exactly one input file.","message":"Yul mode only supports exactly one input file.","severity":"error","type":"JSONError"}]} {"errors":[{"component":"general","formattedMessage":"Yul mode only supports exactly one input file.","message":"Yul mode only supports exactly one input file.","severity":"error","type":"JSONError"}]}

View File

@ -1,6 +1,6 @@
too_long_line_multiline.sol:2:5: Error: No visibility specified. Did you intend to add "public"? too_long_line_multiline/input.sol:2:5: Error: No visibility specified. Did you intend to add "public"?
function f() returns (byte _b, byte ... _b7, bytes22 _b22, bytes32 _b32) { function f() returns (byte _b, byte ... _b7, bytes22 _b22, bytes32 _b32) {
^ (Relevant source part starts here and spans across multiple lines). ^ (Relevant source part starts here and spans across multiple lines).
too_long_line_multiline.sol:1:1: Warning: Source file does not specify required compiler version! too_long_line_multiline/input.sol:1:1: Warning: Source file does not specify required compiler version!
contract C { contract C {
^ (Relevant source part starts here and spans across multiple lines). ^ (Relevant source part starts here and spans across multiple lines).

View File

@ -201,4 +201,3 @@ tag_2:
swap16 swap16
jump jump
tag_4: tag_4:

View File

@ -3,4 +3,3 @@ Exception while assembling:
Dynamic exception type: Dynamic exception type:
std::exception::what: Variable a1 is 17 slot(s) too deep inside the stack. std::exception::what: Variable a1 is 17 slot(s) too deep inside the stack.
[dev::tag_comment*] = Variable a1 is 17 slot(s) too deep inside the stack. [dev::tag_comment*] = Variable a1 is 17 slot(s) too deep inside the stack.

View File

@ -28,4 +28,3 @@ object "object" {
sstore(a1, a2) sstore(a1, a2)
} }
} }