Skip to content

Commit

Permalink
Avoid using $? in conditions and do && exit 1 instead if !
Browse files Browse the repository at this point in the history
  • Loading branch information
cameel committed Feb 2, 2021
1 parent c681f6f commit c61aefa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
3 changes: 1 addition & 2 deletions scripts/ASTImportTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 7 additions & 17 deletions test/cmdlineTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand All @@ -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,
Expand Down Expand Up @@ -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-json - 2>/dev/null)
result=$?
set -e
if [[ $result != 0 ]]
if ! output=$(echo '' | "$SOLC" --ast-json - 2>/dev/null)
then
printError "Incorrect response to --ast-json option with empty stdin"
exit 1
Expand All @@ -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
Expand Down

0 comments on commit c61aefa

Please sign in to comment.