diff --git a/test/cmdlineTests.sh b/test/cmdlineTests.sh index b320da05e..6adc91538 100755 --- a/test/cmdlineTests.sh +++ b/test/cmdlineTests.sh @@ -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 - < }] +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\":\"\"/g' "$stdout_path" - sed -i.bak -E -e 's/\"sourceMap\":\"[0-9:;-]+\"/\"sourceMap\":\"\"/g' "$stdout_path" + sed -i.bak -E -e 's/\"opcodes\":[[:space:]]*\"[^"]+\"/\"opcodes\":\"\"/g' "$stdout_path" + sed -i.bak -E -e 's/\"sourceMap\":[[:space:]]*\"[0-9:;-]+\"/\"sourceMap\":\"\"/g' "$stdout_path" # Remove bytecode (but not linker references). - sed -i.bak -E -e 's/(\"object\":\")[0-9a-f]+([^"]*\")/\1\2/g' "$stdout_path" + sed -i.bak -E -e 's/(\"object\":[[:space:]]*\")[0-9a-f]+([^"]*\")/\1\2/g' "$stdout_path" # shellcheck disable=SC2016 - sed -i.bak -E -e 's/(\"object\":\"[^"]+\$__)[0-9a-f]+(\")/\1\2/g' "$stdout_path" + sed -i.bak -E -e 's/(\"object\":[[:space:]]*\"[^"]+\$__)[0-9a-f]+(\")/\1\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\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/' "$stdout_path" + sed -i.bak -e 's/\(^[ ]*auxdata:[[:space:]]\)0x[0-9a-f]*$/\1/' "$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