Skip to content

Commit 376b923

Browse files
committed
adding support for no-pretty-print
1 parent 799ef0a commit 376b923

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

test/cmdlineTests.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,25 +186,25 @@ function test_solc_behaviour
186186
exitCode=$?
187187
set -e
188188

189-
if [[ " ${solc_args[*]} " == *" --standard-json "* ]]
189+
if [[ " ${solc_args[*]} " == *" --standard-json "* ]] && [[ -s $stdout_path ]]
190190
then
191191
python3 - <<EOF
192192
import re, sys
193193
json = open("$stdout_path", "r").read()
194194
json = re.sub(r"{[^{}]*Warning: This is a pre-release compiler version[^{}]*},?", "", json)
195-
json = re.sub(r"\"errors\":\s*\[\s*\],?\s*","",json) # Remove "errors" array if it's not empty
196-
json = re.sub("\n\\s+\n", "\n\n", json) # Remove trailing whitespace
197-
json = re.sub(r"},(\n{0,1})\n*(\s*])", r"}\1\2", json) # },] -> }]
195+
json = re.sub(r"\"errors\":\s*\[\s*\],?","\n" if json[1] == " " else "",json) # Remove "errors" array if it's not empty
196+
json = re.sub("\n\\s*\n", "\n", json) # Remove trailing whitespace
197+
json = re.sub(r"},(\n{0,1})\n*(\s*(]|}))", r"}\1\2", json) # Remove trailing comma
198198
open("$stdout_path", "w").write(json)
199199
EOF
200200
sed -i.bak -E -e 's/ Consider adding \\"pragma solidity \^[0-9.]*;\\"//g' "$stdout_path"
201-
sed -i.bak -E -e 's/\"opcodes\":\"[^"]+\"/\"opcodes\":\"<OPCODES REMOVED>\"/g' "$stdout_path"
202-
sed -i.bak -E -e 's/\"sourceMap\":\"[0-9:;-]+\"/\"sourceMap\":\"<SOURCEMAP REMOVED>\"/g' "$stdout_path"
201+
sed -i.bak -E -e 's/\"opcodes\":[[:space:]]*\"[^"]+\"/\"opcodes\":\"<OPCODES REMOVED>\"/g' "$stdout_path"
202+
sed -i.bak -E -e 's/\"sourceMap\":[[:space:]]*\"[0-9:;-]+\"/\"sourceMap\":\"<SOURCEMAP REMOVED>\"/g' "$stdout_path"
203203

204204
# Remove bytecode (but not linker references).
205-
sed -i.bak -E -e 's/(\"object\":\")[0-9a-f]+([^"]*\")/\1<BYTECODE REMOVED>\2/g' "$stdout_path"
205+
sed -i.bak -E -e 's/(\"object\":[[:space:]]*\")[0-9a-f]+([^"]*\")/\1<BYTECODE REMOVED>\2/g' "$stdout_path"
206206
# shellcheck disable=SC2016
207-
sed -i.bak -E -e 's/(\"object\":\"[^"]+\$__)[0-9a-f]+(\")/\1<BYTECODE REMOVED>\2/g' "$stdout_path"
207+
sed -i.bak -E -e 's/(\"object\":[[:space:]]*\"[^"]+\$__)[0-9a-f]+(\")/\1<BYTECODE REMOVED>\2/g' "$stdout_path"
208208
# shellcheck disable=SC2016
209209
sed -i.bak -E -e 's/([0-9a-f]{34}\$__)[0-9a-f]+(__\$[0-9a-f]{17})/\1<BYTECODE REMOVED>\2/g' "$stdout_path"
210210
# Remove metadata in assembly output (see below about the magic numbers)
@@ -215,7 +215,7 @@ EOF
215215
# Replace escaped newlines by actual newlines for readability
216216
# shellcheck disable=SC1003
217217
sed -i.bak -E -e 's/\\n/\'$'\n/g' "$stdout_path"
218-
sed -i.bak -e 's/\(^[ ]*auxdata: \)0x[0-9a-f]*$/\1<AUXDATA REMOVED>/' "$stdout_path"
218+
sed -i.bak -e 's/\(^[ ]*auxdata:[[:space:]]\)0x[0-9a-f]*$/\1<AUXDATA REMOVED>/' "$stdout_path"
219219
rm "$stdout_path.bak"
220220
else
221221
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..."
458458
inputFile=""
459459
stdout="$(cat "${tdir}/output.json" 2>/dev/null || true)"
460460
stdoutExpectationFile="${tdir}/output.json"
461-
command_args="--standard-json "$(cat "${tdir}/args" 2>/dev/null || true)
461+
prettyPrintFlags=""
462+
if [[ ! -f "${tdir}/no-pretty-print" ]]
463+
then
464+
prettyPrintFlags="--pretty-json --json-indent 4"
465+
fi
466+
467+
command_args="--standard-json ${prettyPrintFlags} "$(cat "${tdir}/args" 2>/dev/null || true)
462468
else
463469
if [ -e "${tdir}/stdin" ]
464470
then

0 commit comments

Comments
 (0)