Use Bash arrays for variables containing multiple space-separated values

This commit is contained in:
Kamil Śliwak 2020-12-11 21:34:55 +01:00
parent c19464f908
commit 4a7d494d3c
8 changed files with 58 additions and 50 deletions

View File

@ -38,6 +38,9 @@ OPTIMIZE=${OPTIMIZE:-"0"}
EVM=${EVM:-"invalid"} EVM=${EVM:-"invalid"}
REPODIR="$(realpath "$(dirname "$0")/..")" REPODIR="$(realpath "$(dirname "$0")/..")"
IFS=" " read -r -a BOOST_TEST_ARGS <<< "$BOOST_TEST_ARGS"
IFS=" " read -r -a SOLTEST_FLAGS <<< "$SOLTEST_FLAGS"
source "${REPODIR}/scripts/common.sh" source "${REPODIR}/scripts/common.sh"
# Test result output directory (CircleCI is reading test results from here) # Test result output directory (CircleCI is reading test results from here)
mkdir -p test_results mkdir -p test_results
@ -53,11 +56,12 @@ get_logfile_basename() {
echo -ne "${filename}" echo -ne "${filename}"
} }
BOOST_TEST_ARGS="--color_output=no --show_progress=yes --logger=JUNIT,error,test_results/`get_logfile_basename`.xml ${BOOST_TEST_ARGS}" BOOST_TEST_ARGS=("--color_output=no" "--show_progress=yes" "--logger=JUNIT,error,test_results/`get_logfile_basename`.xml" "${BOOST_TEST_ARGS[@]}")
SOLTEST_ARGS="--evm-version=$EVM $SOLTEST_FLAGS" SOLTEST_ARGS=("--evm-version=$EVM" "${SOLTEST_FLAGS[@]}")
test "${OPTIMIZE}" = "1" && SOLTEST_ARGS="${SOLTEST_ARGS} --optimize"
test "${ABI_ENCODER_V1}" = "1" && SOLTEST_ARGS="${SOLTEST_ARGS} --abiencoderv1"
echo "Running ${REPODIR}/build/test/soltest ${BOOST_TEST_ARGS} -- ${SOLTEST_ARGS}" test "${OPTIMIZE}" = "1" && SOLTEST_ARGS+=(--optimize)
test "${ABI_ENCODER_V1}" = "1" && SOLTEST_ARGS+=(--abiencoderv1)
"${REPODIR}/build/test/soltest" ${BOOST_TEST_ARGS} -- ${SOLTEST_ARGS} echo "Running ${REPODIR}/build/test/soltest ${BOOST_TEST_ARGS[*]} -- ${SOLTEST_ARGS[*]}"
"${REPODIR}/build/test/soltest" "${BOOST_TEST_ARGS[@]}" -- "${SOLTEST_ARGS[@]}"

View File

@ -37,10 +37,13 @@ fi
# $1 name of the file to be exported and imported # $1 name of the file to be exported and imported
# $2 any files needed to do so that might be in parent directories # $2 any files needed to do so that might be in parent directories
function testImportExportEquivalence { function testImportExportEquivalence {
if $SOLC "$1" $2 > /dev/null 2>&1 local nth_input_file="$1"
IFS=" " read -r -a all_input_files <<< "$2"
if $SOLC "$nth_input_file" "${all_input_files[@]}" > /dev/null 2>&1
then then
# save exported json as expected result (silently) # save exported json as expected result (silently)
$SOLC --combined-json ast,compact-format --pretty-json "$1" $2 > expected.json 2> /dev/null $SOLC --combined-json ast,compact-format --pretty-json "$nth_input_file" "${all_input_files[@]}" > expected.json 2> /dev/null
# import it, and export it again as obtained result (silently) # import it, and export it again as obtained result (silently)
$SOLC --import-ast --combined-json ast,compact-format --pretty-json expected.json > obtained.json 2> /dev/null $SOLC --import-ast --combined-json ast,compact-format --pretty-json expected.json > obtained.json 2> /dev/null
if [ $? -ne 0 ] if [ $? -ne 0 ]

View File

@ -1,5 +1,4 @@
./test/cmdlineTests.sh ./test/cmdlineTests.sh
./scripts/soltest.sh
./scripts/wasm-rebuild/docker-scripts/rebuild_tags.sh ./scripts/wasm-rebuild/docker-scripts/rebuild_tags.sh
./scripts/wasm-rebuild/docker-scripts/rebuild_current.sh ./scripts/wasm-rebuild/docker-scripts/rebuild_current.sh
./scripts/wasm-rebuild/docker-scripts/genbytecode.sh ./scripts/wasm-rebuild/docker-scripts/genbytecode.sh

View File

@ -18,8 +18,8 @@
# (c) 2016-2019 solidity contributors. # (c) 2016-2019 solidity contributors.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
FULLARGS="--optimize --ignore-missing --combined-json abi,asm,ast,bin,bin-runtime,compact-format,devdoc,hashes,interface,metadata,opcodes,srcmap,srcmap-runtime,userdoc" FULLARGS=(--optimize --ignore-missing --combined-json "abi,asm,ast,bin,bin-runtime,compact-format,devdoc,hashes,interface,metadata,opcodes,srcmap,srcmap-runtime,userdoc")
OLDARGS="--optimize --combined-json abi,asm,ast,bin,bin-runtime,devdoc,interface,metadata,opcodes,srcmap,srcmap-runtime,userdoc" OLDARGS=(--optimize --combined-json "abi,asm,ast,bin,bin-runtime,devdoc,interface,metadata,opcodes,srcmap,srcmap-runtime,userdoc")
function compileFull() function compileFull()
{ {
local expected_exit_code=0 local expected_exit_code=0
@ -37,23 +37,23 @@ function compileFull()
expect_output=2 expect_output=2
shift; shift;
fi fi
local args=$FULLARGS local args=("${FULLARGS[@]}")
if [[ $1 = '-v' ]]; then if [[ $1 = '-v' ]]; then
if (echo "$2" | grep -Po '(?<=0.4.)\d+' >/dev/null); then if (echo "$2" | grep -Po '(?<=0.4.)\d+' >/dev/null); then
patch=$(echo "$2" | grep -Po '(?<=0.4.)\d+') patch=$(echo "$2" | grep -Po '(?<=0.4.)\d+')
if (( patch < 22 )); then if (( patch < 22 )); then
args=$OLDARGS args=("${OLDARGS[@]}")
fi fi
fi fi
shift 2 shift 2
fi fi
local files="$*" local files=("$@")
local stderr_path=$(mktemp) local stderr_path=$(mktemp)
set +e set +e
"$SOLC" ${args} ${files} >/dev/null 2>"$stderr_path" "$SOLC" "${args[@]}" "${files[@]}" >/dev/null 2>"$stderr_path"
local exit_code=$? local exit_code=$?
local errors=$(grep -v -E 'Warning: This is a pre-release compiler version|Warning: Experimental features are turned on|pragma experimental ABIEncoderV2|^ +--> |^ +\||^[0-9]+ +\|' < "$stderr_path") local errors=$(grep -v -E 'Warning: This is a pre-release compiler version|Warning: Experimental features are turned on|pragma experimental ABIEncoderV2|^ +--> |^ +\||^[0-9]+ +\|' < "$stderr_path")
set -e set -e
@ -70,7 +70,7 @@ function compileFull()
printError "Was failure: $exit_code" printError "Was failure: $exit_code"
echo "$errors" echo "$errors"
printError "While calling:" printError "While calling:"
echo "\"$SOLC\" $args $files" echo "\"$SOLC\" ${args[*]} ${files[*]}"
printError "Inside directory:" printError "Inside directory:"
pwd pwd
false false

View File

@ -145,17 +145,17 @@ SOLTMPDIR=$(mktemp -d)
fi fi
echo "$f" echo "$f"
opts='' opts=()
# We expect errors if explicitly stated, or if imports # We expect errors if explicitly stated, or if imports
# are used (in the style guide) # are used (in the style guide)
if ( ! grep -E "This will not compile after" "$f" >/dev/null && \ if ( ! grep -E "This will not compile after" "$f" >/dev/null && \
grep -E "This will not compile|import \"" "$f" >/dev/null ) grep -E "This will not compile|import \"" "$f" >/dev/null )
then then
opts="-e" opts=(-e)
fi fi
# ignore warnings in this case # ignore warnings in this case
opts="$opts -o" opts+=(-o)
findMinimalVersion "$f" findMinimalVersion "$f"
if [[ "$version" == "" ]] if [[ "$version" == "" ]]
@ -168,7 +168,7 @@ SOLTMPDIR=$(mktemp -d)
continue continue
fi fi
opts="$opts -v $version" opts+=(-v "$version")
solc_bin="solc-$version" solc_bin="solc-$version"
echo "$solc_bin" echo "$solc_bin"
@ -188,7 +188,7 @@ SOLTMPDIR=$(mktemp -d)
chmod a+x solc chmod a+x solc
SOLC="$SOLTMPDIR/solc" SOLC="$SOLTMPDIR/solc"
compileFull $opts "$SOLTMPDIR/$f" compileFull "${opts[@]}" "$SOLTMPDIR/$f"
done done
) )
rm -rf "$SOLTMPDIR" rm -rf "$SOLTMPDIR"

View File

@ -4,8 +4,8 @@ set -e
REPO_ROOT="$(dirname "$0")"/.. REPO_ROOT="$(dirname "$0")"/..
USE_DEBUGGER=0 USE_DEBUGGER=0
DEBUGGER="gdb --args" DEBUGGER="gdb --args"
BOOST_OPTIONS= BOOST_OPTIONS=()
SOLTEST_OPTIONS= SOLTEST_OPTIONS=()
SOLIDITY_BUILD_DIR=${SOLIDITY_BUILD_DIR:-${REPO_ROOT}/build} SOLIDITY_BUILD_DIR=${SOLIDITY_BUILD_DIR:-${REPO_ROOT}/build}
usage() { usage() {
@ -41,7 +41,7 @@ do
;; ;;
--boost-options) --boost-options)
shift shift
BOOST_OPTIONS="${BOOST_OPTIONS} $1" BOOST_OPTIONS+=("$1")
;; ;;
--help) --help)
usage usage
@ -49,13 +49,13 @@ do
;; ;;
--run_test | -t ) --run_test | -t )
shift shift
BOOST_OPTIONS="${BOOST_OPTIONS} -t $1" BOOST_OPTIONS+=(-t "$1")
;; ;;
--show-progress | -p) --show-progress | -p)
BOOST_OPTIONS="${BOOST_OPTIONS} $1" BOOST_OPTIONS+=("$1")
;; ;;
*) *)
SOLTEST_OPTIONS="${SOLTEST_OPTIONS} $1" SOLTEST_OPTIONS+=("$1")
;; ;;
esac esac
shift shift
@ -64,4 +64,4 @@ if [ "$USE_DEBUGGER" -ne "0" ]; then
DEBUG_PREFIX=${DEBUGGER} DEBUG_PREFIX=${DEBUGGER}
fi fi
exec ${DEBUG_PREFIX} "${SOLIDITY_BUILD_DIR}/test/soltest" ${BOOST_OPTIONS} -- --testpath "${REPO_ROOT}/test" ${SOLTEST_OPTIONS} exec ${DEBUG_PREFIX} "${SOLIDITY_BUILD_DIR}/test/soltest" "${BOOST_OPTIONS[@]}" -- --testpath "${REPO_ROOT}/test" "${SOLTEST_OPTIONS[@]}"

View File

@ -30,6 +30,7 @@ set -e
REPO_ROOT="$(dirname "$0")/.." REPO_ROOT="$(dirname "$0")/.."
SOLIDITY_BUILD_DIR="${SOLIDITY_BUILD_DIR:-${REPO_ROOT}/build}" SOLIDITY_BUILD_DIR="${SOLIDITY_BUILD_DIR:-${REPO_ROOT}/build}"
IFS=" " read -r -a SMT_FLAGS <<< "$SMT_FLAGS"
source "${REPO_ROOT}/scripts/common.sh" source "${REPO_ROOT}/scripts/common.sh"
@ -100,21 +101,21 @@ do
fi fi
for abiv1 in $FORCE_ABIV1_RUNS for abiv1 in $FORCE_ABIV1_RUNS
do do
force_abiv1_flag="" force_abiv1_flag=()
if [[ "$abiv1" == "yes" ]] if [[ "$abiv1" == "yes" ]]
then then
force_abiv1_flag="--abiencoderv1" force_abiv1_flag=(--abiencoderv1)
fi fi
printTask "--> Running tests using $optimize --evm-version $vm $force_abiv1_flag..." printTask "--> Running tests using $optimize --evm-version $vm ${force_abiv1_flag[*]}..."
log="" log=()
if [ -n "$log_directory" ] if [ -n "$log_directory" ]
then then
if [ -n "$optimize" ] if [ -n "$optimize" ]
then then
log=--logger=JUNIT,error,$log_directory/opt_$vm.xml log+=("--logger=JUNIT,error,$log_directory/opt_$vm.xml")
else else
log=--logger=JUNIT,error,$log_directory/noopt_$vm.xml log+=("--logger=JUNIT,error,$log_directory/noopt_$vm.xml")
fi fi
fi fi
@ -122,7 +123,7 @@ do
[ "${vm}" = "byzantium" ] && [ "${optimize}" = "" ] && EWASM_ARGS="--ewasm" [ "${vm}" = "byzantium" ] && [ "${optimize}" = "" ] && EWASM_ARGS="--ewasm"
set +e set +e
"${SOLIDITY_BUILD_DIR}"/test/soltest --show-progress $log -- ${EWASM_ARGS} --testpath "$REPO_ROOT"/test "$optimize" --evm-version "$vm" $SMT_FLAGS $force_abiv1_flag "${SOLIDITY_BUILD_DIR}"/test/soltest --show-progress "${log[@]}" -- ${EWASM_ARGS} --testpath "$REPO_ROOT"/test "$optimize" --evm-version "$vm" "${SMT_FLAGS[@]}" "${force_abiv1_flag[@]}"
if test "0" -ne "$?"; then if test "0" -ne "$?"; then
exit 1 exit 1

View File

@ -111,7 +111,8 @@ function ask_expectation_update
function test_solc_behaviour() function test_solc_behaviour()
{ {
local filename="${1}" local filename="${1}"
local solc_args="${2}" local solc_args
IFS=" " read -r -a solc_args <<< "${2}"
local solc_stdin="${3}" local solc_stdin="${3}"
[ -z "$solc_stdin" ] && solc_stdin="/dev/stdin" [ -z "$solc_stdin" ] && solc_stdin="/dev/stdin"
local stdout_expected="${4}" local stdout_expected="${4}"
@ -127,13 +128,13 @@ function test_solc_behaviour()
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} <$solc_stdin" local solc_command="$SOLC ${filename} ${solc_args[*]} <$solc_stdin"
set +e set +e
"$SOLC" "${filename}" ${solc_args} <"$solc_stdin" >"$stdout_path" 2>"$stderr_path" "$SOLC" "${filename}" "${solc_args[@]}" <"$solc_stdin" >"$stdout_path" 2>"$stderr_path"
exitCode=$? exitCode=$?
set -e set -e
if [[ "$solc_args" == *"--standard-json"* ]] if [[ " ${solc_args[*]} " == *" --standard-json "* ]]
then then
sed -i.bak -e 's/{[^{]*Warning: This is a pre-release compiler version[^}]*},\{0,1\}//' "$stdout_path" sed -i.bak -e 's/{[^{]*Warning: This is a pre-release compiler version[^}]*},\{0,1\}//' "$stdout_path"
sed -i.bak -E -e 's/ Consider adding \\"pragma solidity \^[0-9.]*;\\"//g' "$stdout_path" sed -i.bak -E -e 's/ Consider adding \\"pragma solidity \^[0-9.]*;\\"//g' "$stdout_path"
@ -221,17 +222,17 @@ function test_solc_assembly_output()
{ {
local input="${1}" local input="${1}"
local expected="${2}" local expected="${2}"
local solc_args="${3}" IFS=" " read -r -a solc_args <<< "${3}"
local expected_object="object \"object\" { code ${expected} }" local expected_object="object \"object\" { code ${expected} }"
output=$(echo "${input}" | "$SOLC" - ${solc_args} 2>/dev/null) output=$(echo "${input}" | "$SOLC" - "${solc_args[@]}" 2>/dev/null)
empty=$(echo "$output" | tr '\n' ' ' | tr -s ' ' | sed -ne "/${expected_object}/p") empty=$(echo "$output" | tr '\n' ' ' | tr -s ' ' | sed -ne "/${expected_object}/p")
if [ -z "$empty" ] if [ -z "$empty" ]
then then
printError "Incorrect assembly output. Expected: " printError "Incorrect assembly output. Expected: "
echo -e "${expected}" echo -e "${expected}"
printError "with arguments ${solc_args}, but got:" printError "with arguments ${solc_args[*]}, but got:"
echo "${output}" echo "${output}"
exit 1 exit 1
fi fi
@ -302,19 +303,19 @@ printTask "Running general commandline tests..."
inputFile="" inputFile=""
stdout="$(cat "${tdir}/output.json" 2>/dev/null || true)" stdout="$(cat "${tdir}/output.json" 2>/dev/null || true)"
stdoutExpectationFile="${tdir}/output.json" stdoutExpectationFile="${tdir}/output.json"
args="--standard-json "$(cat "${tdir}/args" 2>/dev/null || true) command_args="--standard-json "$(cat "${tdir}/args" 2>/dev/null || true)
else else
stdin="" stdin=""
stdout="$(cat "${tdir}/output" 2>/dev/null || true)" stdout="$(cat "${tdir}/output" 2>/dev/null || true)"
stdoutExpectationFile="${tdir}/output" stdoutExpectationFile="${tdir}/output"
args=$(cat "${tdir}/args" 2>/dev/null || true) command_args=$(cat "${tdir}/args" 2>/dev/null || true)
fi fi
exitCodeExpectationFile="${tdir}/exit" exitCodeExpectationFile="${tdir}/exit"
exitCode=$(cat "$exitCodeExpectationFile" 2>/dev/null || true) 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" \
"$args" \ "$command_args" \
"$stdin" \ "$stdin" \
"$stdout" \ "$stdout" \
"$exitCode" \ "$exitCode" \
@ -354,22 +355,22 @@ SOLTMPDIR=$(mktemp -d)
fi fi
echo "$f" echo "$f"
opts='' opts=()
# We expect errors if explicitly stated, or if imports # We expect errors if explicitly stated, or if imports
# are used (in the style guide) # are used (in the style guide)
if grep -E "This will not compile|import \"" "$f" >/dev/null if grep -E "This will not compile|import \"" "$f" >/dev/null
then then
opts="-e" opts=(-e)
fi fi
if grep "This will report a warning" "$f" >/dev/null if grep "This will report a warning" "$f" >/dev/null
then then
opts="$opts -w" opts+=(-w)
fi fi
if grep "This may report a warning" "$f" >/dev/null if grep "This may report a warning" "$f" >/dev/null
then then
opts="$opts -o" opts+=(-o)
fi fi
compileFull $opts "$SOLTMPDIR/$f" compileFull "${opts[@]}" "$SOLTMPDIR/$f"
done done
) )
rm -rf "$SOLTMPDIR" rm -rf "$SOLTMPDIR"