Improves assembly output commandline tests.

This commit is contained in:
Erik Kundt 2018-11-29 15:56:51 +01:00 committed by chriseth
parent 0d1b9c3b1b
commit 1cdcdcee65

View File

@ -262,6 +262,25 @@ SOLTMPDIR=$(mktemp -d)
) )
rm -rf "$SOLTMPDIR" rm -rf "$SOLTMPDIR"
test_solc_assembly_output() {
local input="${1}"
local expected="${2}"
local solc_args="${3}"
local expected_object="object \"object\" { code "${expected}" }"
output=$(echo "${input}" | "$SOLC" - ${solc_args} 2>/dev/null)
empty=$(echo $output | sed -ne '/'"${expected_object}"'/p')
if [ -z "$empty" ]
then
printError "Incorrect assembly output. Expected: "
echo -e ${expected}
printError "with arguments ${solc_args}, but got:"
echo "${output}"
exit 1
fi
}
printTask "Testing assemble, yul, strict-assembly and optimize..." printTask "Testing assemble, yul, strict-assembly and optimize..."
( (
echo '{}' | "$SOLC" - --assemble &>/dev/null echo '{}' | "$SOLC" - --assemble &>/dev/null
@ -271,8 +290,15 @@ printTask "Testing assemble, yul, strict-assembly and optimize..."
# Test options above in conjunction with --optimize. # Test options above in conjunction with --optimize.
# Using both, --assemble and --optimize should fail. # Using both, --assemble and --optimize should fail.
! echo '{}' | "$SOLC" - --assemble --optimize &>/dev/null ! echo '{}' | "$SOLC" - --assemble --optimize &>/dev/null
echo '{}' | "$SOLC" - --yul --optimize &>/dev/null
echo '{}' | "$SOLC" - --strict-assembly --optimize &>/dev/null # Test yul and strict assembly output
# Non-empty code results in non-empty binary representation with optimizations turned off,
# while it results in empty binary representation with optimizations turned on.
test_solc_assembly_output "{ let x:u256 := 0:u256 }" "{ let x:u256 := 0:u256 }" "--yul"
test_solc_assembly_output "{ let x:u256 := 0:u256 }" "{ }" "--yul --optimize"
test_solc_assembly_output "{ let x := 0 }" "{ let x := 0 }" "--strict-assembly"
test_solc_assembly_output "{ let x := 0 }" "{ }" "--strict-assembly --optimize"
) )