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