Merge pull request #10832 from ethereum/cmdline-tests-more-robust-interactive-mode

More robust interactive mode in command-line tests
This commit is contained in:
Kamil Śliwak 2021-01-22 15:34:40 +01:00 committed by GitHub
commit 8a8442377d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,12 +87,16 @@ function ask_expectation_update
then
update_expectation "$newExpectation" "$expectationFile"
else
local editor="${FCEDIT:-${VISUAL:-${EDITOR:-vi}}}"
while true
do
read -N 1 -p "(u)pdate expectation/(q)uit? "
read -N 1 -p "(e)dit/(u)pdate expectations/(s)kip/(q)uit? "
echo
case $REPLY in
e*) "$editor" "$expectationFile"; break;;
u*) update_expectation "$newExpectation" "$expectationFile"; break;;
s*) return;;
q*) exit 1;;
esac
done
@ -112,9 +116,10 @@ function test_solc_behaviour()
[ -z "$solc_stdin" ] && solc_stdin="/dev/stdin"
local stdout_expected="${4}"
local exit_code_expected="${5}"
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 exit_code_expectation_file="${6}"
local stderr_expected="${7}"
local stdout_expectation_file="${8}" # the file to write to when user chooses to update stdout expectation
local stderr_expectation_file="${9}" # the file to write to when user chooses to update stderr expectation
local stdout_path=`mktemp`
local stderr_path=`mktemp`
@ -175,7 +180,9 @@ function test_solc_behaviour()
if [[ $exitCode -ne "$exit_code_expected" ]]
then
printError "Incorrect exit code. Expected $exit_code_expected but got $exitCode."
exit 1
[[ $exit_code_expectation_file != "" ]] && ask_expectation_update "$exit_code_expected" "$exit_code_expectation_file"
[[ $exit_code_expectation_file == "" ]] && exit 1
fi
if [[ "$(cat $stdout_path)" != "${stdout_expected}" ]]
@ -188,12 +195,8 @@ function test_solc_behaviour()
printError "When running $solc_command"
if [ -n "$stdout_expectation_file" ]
then
ask_expectation_update "$(cat $stdout_path)" "$stdout_expectation_file"
else
exit 1
fi
[[ $stdout_expectation_file != "" ]] && ask_expectation_update "$(cat "$stdout_path")" "$stdout_expectation_file"
[[ $stdout_expectation_file == "" ]] && exit 1
fi
if [[ "$(cat $stderr_path)" != "${stderr_expected}" ]]
@ -206,12 +209,8 @@ function test_solc_behaviour()
printError "When running $solc_command"
if [ -n "$stderr_expectation_file" ]
then
ask_expectation_update "$(cat $stderr_path)" "$stderr_expectation_file"
else
exit 1
fi
[[ $stderr_expectation_file != "" ]] && ask_expectation_update "$(cat "$stderr_path")" "$stderr_expectation_file"
[[ $stderr_expectation_file == "" ]] && exit 1
fi
rm -f "$stdout_path" "$stderr_path"
@ -261,14 +260,14 @@ printTask "Testing unknown options..."
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..."
test_solc_behaviour "." "" "" "" 1 "\".\" is not a valid file." "" ""
test_solc_behaviour "." "" "" "" 1 "" "\".\" is not a valid file." "" ""
printTask "Testing passing empty remappings..."
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}" "=/some/remapping/target" "" "" 1 "" "Invalid remapping: \"=/some/remapping/target\"." "" ""
test_solc_behaviour "${0}" "ctx:=/some/remapping/target" "" "" 1 "" "Invalid remapping: \"ctx:=/some/remapping/target\"." "" ""
printTask "Running general commandline tests..."
(
@ -310,7 +309,8 @@ printTask "Running general commandline tests..."
stdoutExpectationFile="${tdir}/output"
args=$(cat ${tdir}/args 2>/dev/null || true)
fi
exitCode=$(cat ${tdir}/exit 2>/dev/null || true)
exitCodeExpectationFile="${tdir}/exit"
exitCode=$(cat "$exitCodeExpectationFile" 2>/dev/null || true)
err="$(cat ${tdir}/err 2>/dev/null || true)"
stderrExpectationFile="${tdir}/err"
test_solc_behaviour "$inputFile" \
@ -318,6 +318,7 @@ printTask "Running general commandline tests..."
"$stdin" \
"$stdout" \
"$exitCode" \
"$exitCodeExpectationFile" \
"$err" \
"$stdoutExpectationFile" \
"$stderrExpectationFile"