From c8fc241be5d8a245c05c7d76d3df733f64ed9ee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Sat, 12 Dec 2020 03:01:48 +0100 Subject: [PATCH] Avoid using $? in conditions and do && exit 1 instead if ! --- scripts/ASTImportTest.sh | 3 +-- test/cmdlineTests.sh | 24 +++++++----------------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/scripts/ASTImportTest.sh b/scripts/ASTImportTest.sh index d11b63c40..28dbc5d58 100755 --- a/scripts/ASTImportTest.sh +++ b/scripts/ASTImportTest.sh @@ -45,8 +45,7 @@ function testImportExportEquivalence { # save exported json as expected result (silently) $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) - $SOLC --import-ast --combined-json ast,compact-format --pretty-json expected.json > obtained.json 2> /dev/null - if [ $? -ne 0 ] + if ! $SOLC --import-ast --combined-json ast,compact-format --pretty-json expected.json > obtained.json 2> /dev/null then # For investigating, use exit 1 here so the script stops at the # first failing test diff --git a/test/cmdlineTests.sh b/test/cmdlineTests.sh index d05768ebe..56c453200 100755 --- a/test/cmdlineTests.sh +++ b/test/cmdlineTests.sh @@ -378,7 +378,7 @@ echo "Done." printTask "Testing library checksum..." echo '' | "$SOLC" - --link --libraries a=0x90f20564390eAe531E810af625A22f51385Cd222 >/dev/null -! echo '' | "$SOLC" - --link --libraries a=0x80f20564390eAe531E810af625A22f51385Cd222 &>/dev/null +echo '' | "$SOLC" - --link --libraries a=0x80f20564390eAe531E810af625A22f51385Cd222 &>/dev/null && exit 1 printTask "Testing long library names..." echo '' | "$SOLC" - --link --libraries aveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerylonglibraryname=0x90f20564390eAe531E810af625A22f51385Cd222 >/dev/null @@ -408,7 +408,7 @@ SOLTMPDIR=$(mktemp -d) # First time it works echo 'contract C {} ' | "$SOLC" - --bin -o "$SOLTMPDIR/non-existing-stuff-to-create" 2>/dev/null # Second time it fails - ! echo 'contract C {} ' | "$SOLC" - --bin -o "$SOLTMPDIR/non-existing-stuff-to-create" 2>/dev/null + echo 'contract C {} ' | "$SOLC" - --bin -o "$SOLTMPDIR/non-existing-stuff-to-create" 2>/dev/null && exit 1 # Unless we force echo 'contract C {} ' | "$SOLC" - --overwrite --bin -o "$SOLTMPDIR/non-existing-stuff-to-create" 2>/dev/null ) @@ -422,8 +422,8 @@ printTask "Testing assemble, yul, strict-assembly and optimize..." # Test options above in conjunction with --optimize. # Using both, --assemble and --optimize should fail. - ! echo '{}' | "$SOLC" - --assemble --optimize &>/dev/null - ! echo '{}' | "$SOLC" - --yul --optimize &>/dev/null + echo '{}' | "$SOLC" - --assemble --optimize &>/dev/null && exit 1 + echo '{}' | "$SOLC" - --yul --optimize &>/dev/null && exit 1 # Test yul and strict assembly output # Non-empty code results in non-empty binary representation with optimizations turned off, @@ -451,24 +451,15 @@ SOLTMPDIR=$(mktemp -d) exit 1 fi - set +e - output=$(echo 'contract C {} ' | "$SOLC" - --bin 2>/dev/null | grep -q ":C") - result=$? - set -e - # The contract should be compiled - if [[ "$result" != 0 ]] + if ! output=$(echo 'contract C {} ' | "$SOLC" - --bin 2>/dev/null | grep -q ":C") then printError "Failed to compile a simple contract from standard input" exit 1 fi # This should not fail - set +e - output=$(echo '' | "$SOLC" --ast-compact-json - 2>/dev/null) - result=$? - set -e - if [[ $result != 0 ]] + if ! output=$(echo '' | "$SOLC" --ast-compact-json - 2>/dev/null) then printError "Incorrect response to --ast-compact-json option with empty stdin" exit 1 @@ -479,8 +470,7 @@ printTask "Testing AST import..." SOLTMPDIR=$(mktemp -d) ( cd "$SOLTMPDIR" - "$REPO_ROOT/scripts/ASTImportTest.sh" - if [ $? -ne 0 ] + if ! "$REPO_ROOT/scripts/ASTImportTest.sh" then rm -rf "$SOLTMPDIR" exit 1