adding support for no-pretty-print

This commit is contained in:
George Plotnikov 2022-10-26 15:13:11 +05:00
parent 799ef0ab1a
commit 376b923a79

View File

@ -186,25 +186,25 @@ function test_solc_behaviour
exitCode=$?
set -e
if [[ " ${solc_args[*]} " == *" --standard-json "* ]]
if [[ " ${solc_args[*]} " == *" --standard-json "* ]] && [[ -s $stdout_path ]]
then
python3 - <<EOF
import re, sys
json = open("$stdout_path", "r").read()
json = re.sub(r"{[^{}]*Warning: This is a pre-release compiler version[^{}]*},?", "", json)
json = re.sub(r"\"errors\":\s*\[\s*\],?\s*","",json) # Remove "errors" array if it's not empty
json = re.sub("\n\\s+\n", "\n\n", json) # Remove trailing whitespace
json = re.sub(r"},(\n{0,1})\n*(\s*])", r"}\1\2", json) # },] -> }]
json = re.sub(r"\"errors\":\s*\[\s*\],?","\n" if json[1] == " " else "",json) # Remove "errors" array if it's not empty
json = re.sub("\n\\s*\n", "\n", json) # Remove trailing whitespace
json = re.sub(r"},(\n{0,1})\n*(\s*(]|}))", r"}\1\2", json) # Remove trailing comma
open("$stdout_path", "w").write(json)
EOF
sed -i.bak -E -e 's/ Consider adding \\"pragma solidity \^[0-9.]*;\\"//g' "$stdout_path"
sed -i.bak -E -e 's/\"opcodes\":\"[^"]+\"/\"opcodes\":\"<OPCODES REMOVED>\"/g' "$stdout_path"
sed -i.bak -E -e 's/\"sourceMap\":\"[0-9:;-]+\"/\"sourceMap\":\"<SOURCEMAP REMOVED>\"/g' "$stdout_path"
sed -i.bak -E -e 's/\"opcodes\":[[:space:]]*\"[^"]+\"/\"opcodes\":\"<OPCODES REMOVED>\"/g' "$stdout_path"
sed -i.bak -E -e 's/\"sourceMap\":[[:space:]]*\"[0-9:;-]+\"/\"sourceMap\":\"<SOURCEMAP REMOVED>\"/g' "$stdout_path"
# Remove bytecode (but not linker references).
sed -i.bak -E -e 's/(\"object\":\")[0-9a-f]+([^"]*\")/\1<BYTECODE REMOVED>\2/g' "$stdout_path"
sed -i.bak -E -e 's/(\"object\":[[:space:]]*\")[0-9a-f]+([^"]*\")/\1<BYTECODE REMOVED>\2/g' "$stdout_path"
# shellcheck disable=SC2016
sed -i.bak -E -e 's/(\"object\":\"[^"]+\$__)[0-9a-f]+(\")/\1<BYTECODE REMOVED>\2/g' "$stdout_path"
sed -i.bak -E -e 's/(\"object\":[[:space:]]*\"[^"]+\$__)[0-9a-f]+(\")/\1<BYTECODE REMOVED>\2/g' "$stdout_path"
# shellcheck disable=SC2016
sed -i.bak -E -e 's/([0-9a-f]{34}\$__)[0-9a-f]+(__\$[0-9a-f]{17})/\1<BYTECODE REMOVED>\2/g' "$stdout_path"
# Remove metadata in assembly output (see below about the magic numbers)
@ -215,7 +215,7 @@ EOF
# Replace escaped newlines by actual newlines for readability
# shellcheck disable=SC1003
sed -i.bak -E -e 's/\\n/\'$'\n/g' "$stdout_path"
sed -i.bak -e 's/\(^[ ]*auxdata: \)0x[0-9a-f]*$/\1<AUXDATA REMOVED>/' "$stdout_path"
sed -i.bak -e 's/\(^[ ]*auxdata:[[:space:]]\)0x[0-9a-f]*$/\1<AUXDATA REMOVED>/' "$stdout_path"
rm "$stdout_path.bak"
else
sed -i.bak -e '/^Warning: This is a pre-release compiler version, please do not use it in production./d' "$stderr_path"
@ -458,7 +458,13 @@ printTask "Running general commandline tests..."
inputFile=""
stdout="$(cat "${tdir}/output.json" 2>/dev/null || true)"
stdoutExpectationFile="${tdir}/output.json"
command_args="--standard-json "$(cat "${tdir}/args" 2>/dev/null || true)
prettyPrintFlags=""
if [[ ! -f "${tdir}/no-pretty-print" ]]
then
prettyPrintFlags="--pretty-json --json-indent 4"
fi
command_args="--standard-json ${prettyPrintFlags} "$(cat "${tdir}/args" 2>/dev/null || true)
else
if [ -e "${tdir}/stdin" ]
then