Avoid using $? in conditions and do && exit 1 instead if !

This commit is contained in:
Kamil Śliwak 2020-12-12 03:01:48 +01:00
parent 87f9eba1cf
commit c8fc241be5
2 changed files with 8 additions and 19 deletions

View File

@ -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

View File

@ -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 "<stdin>:C")
result=$?
set -e
# The contract should be compiled
if [[ "$result" != 0 ]]
if ! output=$(echo 'contract C {} ' | "$SOLC" - --bin 2>/dev/null | grep -q "<stdin>: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