scripts/ImportExportTest.sh: add support for 'set -euo pipefail'.

This commit is contained in:
Alexander Arlt 2022-03-29 15:09:47 -05:00
parent c5e6a5b4b8
commit 3e2b62ab89
2 changed files with 17 additions and 7 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -euo pipefail
IMPORT_TEST_TYPE="${1}" IMPORT_TEST_TYPE="${1}"
# Bash script to test the import/exports. # Bash script to test the import/exports.
@ -60,7 +60,7 @@ function Ast_ImportExportEquivalence
set +e set +e
diff_files expected.json obtained.json diff_files expected.json obtained.json
DIFF=$? DIFF=$?
set -e set -euo pipefail
if [[ ${DIFF} != 0 ]] if [[ ${DIFF} != 0 ]]
then then
FAILED=$((FAILED + 1)) FAILED=$((FAILED + 1))
@ -112,7 +112,7 @@ function JsonEvmAsm_ImportExportEquivalence
set +e set +e
diff_files "expected.${output}" "obtained.${output}" diff_files "expected.${output}" "obtained.${output}"
DIFF=$? DIFF=$?
set -e set -euo pipefail
if [[ ${DIFF} != 0 ]] if [[ ${DIFF} != 0 ]]
then then
_TESTED= _TESTED=
@ -137,7 +137,7 @@ function JsonEvmAsm_ImportExportEquivalence
set +e set +e
diff_files "expected.asm" "obtained_direct_import_export.asm" diff_files "expected.asm" "obtained_direct_import_export.asm"
DIFF=$? DIFF=$?
set -e set -euo pipefail
if [[ ${DIFF} != 0 ]] if [[ ${DIFF} != 0 ]]
then then
_TESTED= _TESTED=
@ -166,6 +166,11 @@ function testImportExportEquivalence {
local nth_input_file="$1" local nth_input_file="$1"
IFS=" " read -r -a all_input_files <<< "$2" IFS=" " read -r -a all_input_files <<< "$2"
if [ -z ${all_input_files+x} ]
then
all_input_files=( "" )
fi
if $SOLC --bin "$nth_input_file" "${all_input_files[@]}" > /dev/null 2>&1 if $SOLC --bin "$nth_input_file" "${all_input_files[@]}" > /dev/null 2>&1
then then
! [[ -e stderr.txt ]] || { printError "stderr.txt already exists. Refusing to overwrite."; exit 1; } ! [[ -e stderr.txt ]] || { printError "stderr.txt already exists. Refusing to overwrite."; exit 1; }
@ -219,7 +224,7 @@ do
set +e set +e
OUTPUT=$("$SPLITSOURCES" "$solfile") OUTPUT=$("$SPLITSOURCES" "$solfile")
SPLITSOURCES_RC=$? SPLITSOURCES_RC=$?
set -e set -euo pipefail
if [ ${SPLITSOURCES_RC} == 0 ] if [ ${SPLITSOURCES_RC} == 0 ]
then then
NSOURCES=$((NSOURCES - 1)) NSOURCES=$((NSOURCES - 1))
@ -230,14 +235,14 @@ do
done done
elif [ ${SPLITSOURCES_RC} == 1 ] elif [ ${SPLITSOURCES_RC} == 1 ]
then then
testImportExportEquivalence "$solfile" testImportExportEquivalence "$solfile" ""
elif [ ${SPLITSOURCES_RC} == 2 ] elif [ ${SPLITSOURCES_RC} == 2 ]
then then
# The script will exit with return code 2, if an UnicodeDecodeError occurred. # The script will exit with return code 2, if an UnicodeDecodeError occurred.
# This is the case if e.g. some tests are using invalid utf-8 sequences. We will ignore # This is the case if e.g. some tests are using invalid utf-8 sequences. We will ignore
# these errors, but print the actual output of the script. # these errors, but print the actual output of the script.
printError "\n${OUTPUT}\n" printError "\n${OUTPUT}\n"
testImportExportEquivalence "$solfile" testImportExportEquivalence "$solfile" ""
else else
# All other return codes will be treated as critical errors. The script will exit. # All other return codes will be treated as critical errors. The script will exit.
printError "\nGot unexpected return code ${SPLITSOURCES_RC} from ${SPLITSOURCES}. Aborting." printError "\nGot unexpected return code ${SPLITSOURCES_RC} from ${SPLITSOURCES}. Aborting."

View File

@ -26,6 +26,11 @@ set -e
# changes directory. The paths returned by `caller` are relative to it. # changes directory. The paths returned by `caller` are relative to it.
_initial_work_dir=$(pwd) _initial_work_dir=$(pwd)
if [ -z ${CIRCLECI+x} ]
then
CIRCLECI=0
fi
if [ "$CIRCLECI" ] if [ "$CIRCLECI" ]
then then
export TERM="${TERM:-xterm}" export TERM="${TERM:-xterm}"