mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
cmdlineTests.sh: Add msg_on_error helper that automatically prints stderr and stdout of a failed command
This commit is contained in:
+14
-16
@@ -295,7 +295,7 @@ function test_solc_assembly_output()
|
||||
|
||||
local expected_object="object \"object\" { code ${expected} }"
|
||||
|
||||
output=$(echo "${input}" | "$SOLC" - "${solc_args[@]}" 2>/dev/null)
|
||||
output=$(echo "${input}" | msg_on_error --no-stderr "$SOLC" - "${solc_args[@]}")
|
||||
empty=$(echo "$output" | tr '\n' ' ' | tr -s ' ' | sed -ne "/${expected_object}/p")
|
||||
if [ -z "$empty" ]
|
||||
then
|
||||
@@ -473,24 +473,24 @@ rm -r "$SOLTMPDIR"
|
||||
echo "Done."
|
||||
|
||||
printTask "Testing library checksum..."
|
||||
echo '' | "$SOLC" - --link --libraries a=0x90f20564390eAe531E810af625A22f51385Cd222 >/dev/null
|
||||
echo '' | msg_on_error --no-stdout "$SOLC" - --link --libraries a=0x90f20564390eAe531E810af625A22f51385Cd222
|
||||
echo '' | "$SOLC" - --link --libraries a=0x80f20564390eAe531E810af625A22f51385Cd222 &>/dev/null && exit 1
|
||||
|
||||
printTask "Testing long library names..."
|
||||
echo '' | "$SOLC" - --link --libraries aveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerylonglibraryname=0x90f20564390eAe531E810af625A22f51385Cd222 >/dev/null
|
||||
echo '' | msg_on_error --no-stdout "$SOLC" - --link --libraries aveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerylonglibraryname=0x90f20564390eAe531E810af625A22f51385Cd222
|
||||
|
||||
printTask "Testing linking itself..."
|
||||
SOLTMPDIR=$(mktemp -d)
|
||||
(
|
||||
cd "$SOLTMPDIR"
|
||||
echo 'library L { function f() public pure {} } contract C { function f() public pure { L.f(); } }' > x.sol
|
||||
"$SOLC" --bin -o . x.sol 2>/dev/null
|
||||
msg_on_error --no-stderr "$SOLC" --bin -o . x.sol
|
||||
# Explanation and placeholder should be there
|
||||
grep -q '//' C.bin && grep -q '__' C.bin
|
||||
# But not in library file.
|
||||
grep -q -v '[/_]' L.bin
|
||||
# Now link
|
||||
"$SOLC" --link --libraries x.sol:L=0x90f20564390eAe531E810af625A22f51385Cd222 C.bin
|
||||
msg_on_error "$SOLC" --link --libraries x.sol:L=0x90f20564390eAe531E810af625A22f51385Cd222 C.bin
|
||||
# Now the placeholder and explanation should be gone.
|
||||
grep -q -v '[/_]' C.bin
|
||||
)
|
||||
@@ -500,19 +500,19 @@ printTask "Testing overwriting files..."
|
||||
SOLTMPDIR=$(mktemp -d)
|
||||
(
|
||||
# First time it works
|
||||
echo 'contract C {} ' | "$SOLC" - --bin -o "$SOLTMPDIR/non-existing-stuff-to-create" 2>/dev/null
|
||||
echo 'contract C {}' | msg_on_error --no-stderr "$SOLC" - --bin -o "$SOLTMPDIR/non-existing-stuff-to-create"
|
||||
# Second time it fails
|
||||
echo 'contract C {} ' | "$SOLC" - --bin -o "$SOLTMPDIR/non-existing-stuff-to-create" 2>/dev/null && exit 1
|
||||
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
|
||||
echo 'contract C {}' | msg_on_error --no-stderr "$SOLC" - --overwrite --bin -o "$SOLTMPDIR/non-existing-stuff-to-create"
|
||||
)
|
||||
rm -r "$SOLTMPDIR"
|
||||
|
||||
printTask "Testing assemble, yul, strict-assembly and optimize..."
|
||||
(
|
||||
echo '{}' | "$SOLC" - --assemble &>/dev/null
|
||||
echo '{}' | "$SOLC" - --yul &>/dev/null
|
||||
echo '{}' | "$SOLC" - --strict-assembly &>/dev/null
|
||||
echo '{}' | msg_on_error --silent "$SOLC" - --assemble
|
||||
echo '{}' | msg_on_error --silent "$SOLC" - --yul
|
||||
echo '{}' | msg_on_error --silent "$SOLC" - --strict-assembly
|
||||
|
||||
# Test options above in conjunction with --optimize.
|
||||
# Using both, --assemble and --optimize should fail.
|
||||
@@ -545,16 +545,14 @@ SOLTMPDIR=$(mktemp -d)
|
||||
fi
|
||||
|
||||
# The contract should be compiled
|
||||
if ! output=$(echo 'contract C {} ' | "$SOLC" - --bin 2>/dev/null | grep -q "<stdin>:C")
|
||||
if ! echo 'contract C {}' | msg_on_error --no-stderr "$SOLC" - --bin | grep -q "<stdin>:C"
|
||||
then
|
||||
fail "Failed to compile a simple contract from standard input"
|
||||
fi
|
||||
|
||||
# This should not fail
|
||||
if ! output=$(echo '' | "$SOLC" --ast-compact-json - 2>/dev/null)
|
||||
then
|
||||
fail "Incorrect response to --ast-compact-json option with empty stdin"
|
||||
fi
|
||||
echo '' | msg_on_error --silent --msg "Incorrect response to --ast-compact-json option with empty stdin" \
|
||||
"$SOLC" --ast-compact-json -
|
||||
)
|
||||
rm -r "$SOLTMPDIR"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user