Skip to content

Commit

Permalink
Merge pull request ethereum#13586 from GeorgePlotnikov/use-pretty-jso…
Browse files Browse the repository at this point in the history
…n-for-cmlinetests-output

Use `--pretty-json` for `cmdlineTests.sh` output by default
  • Loading branch information
cameel authored Oct 26, 2022
2 parents 799ef0a + b0a729a commit 1d85eb5
Show file tree
Hide file tree
Showing 202 changed files with 9,169 additions and 494 deletions.
9 changes: 7 additions & 2 deletions ReviewChecklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ It is also meant to serve as a final checklist for reviewers to go through befor
- [ ] Avoid basing PRs from forks on branches other than `develop` or `breaking` because
GitHub closes them when the base branch gets merged.
Do this only for PRs created directly in the main repo.
- [ ] **Does the PR update test expectations to match the modified code?** If not, your PR will not pass some of the `_soltest_`, jobs in CI.
In many cases the expectations can be updated automatically:
- `cmdlineTests.sh --update` for command-line tests.
- `isoltest --enforce-gas-cost --accept-updates` for soltest-based tests.
- If your PR affects gas costs, an extra run of `isoltest --enforce-gas-cost --optimize --accept-updates` is needed to update gas expectations with optimizer enabled.
- Review updated files before committing them.
**Are expectations correct and do updated tests still serve their purpose?**

## Coding Style and Good Practices
- [ ] Does the PR follow our [coding style](CODING_STYLE.md)?
Expand Down Expand Up @@ -127,8 +134,6 @@ The following points are all covered by the coding style but come up so often th
- [ ] **Do not include version pragma and the SPDX comment in semantic and syntax test cases**.
In other test types include them if necessary to suppress warnings.
- [ ] **If you have to use a version pragma, avoid hard-coding version.** Use `pragma solidity *`.
- [ ] **Add `--pretty-print --pretty-json 4` to the `args` file of in command-line tests** to get
readable, indented output.
- [ ] **When writing StandardJSON command-line tests, use `urls` instead of `content`** and put
the Solidity or Yul code in a separate file.

Expand Down
26 changes: 16 additions & 10 deletions test/cmdlineTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
27 changes: 26 additions & 1 deletion test/cmdlineTests/linking_standard_solidity/output.json
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
{"contracts":{"A":{"C":{"evm":{"bytecode":{"linkReferences":{},"object":"<BYTECODE REMOVED>"}}}}},"sources":{"A":{"id":0}}}
{
"contracts":
{
"A":
{
"C":
{
"evm":
{
"bytecode":
{
"linkReferences": {},
"object": "<BYTECODE REMOVED>"
}
}
}
}
},
"sources":
{
"A":
{
"id": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
{"contracts":{"A\"B":{"C":{"evm":{"bytecode":{"linkReferences":{},"object":"<BYTECODE REMOVED>"}}}}},"sources":{"A\"B":{"id":0}}}
{
"contracts":
{
"A\"B":
{
"C":
{
"evm":
{
"bytecode":
{
"linkReferences": {},
"object": "<BYTECODE REMOVED>"
}
}
}
}
},
"sources":
{
"A\"B":
{
"id": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
{"contracts":{"A":{"C":{"evm":{"bytecode":{"linkReferences":{"A":{"L2":[{"length":20,"start":184},{"length":20,"start":368}]}},"object":"<BYTECODE REMOVED>__$622b2f540b6a16ff5db7bea656ad8fcf4f$__<BYTECODE REMOVED>__$622b2f540b6a16ff5db7bea656ad8fcf4f$__<BYTECODE REMOVED>"}}}}},"sources":{"A":{"id":0}}}
{
"contracts":
{
"A":
{
"C":
{
"evm":
{
"bytecode":
{
"linkReferences":
{
"A":
{
"L2":
[
{
"length": 20,
"start": 184
},
{
"length": 20,
"start": 368
}
]
}
},
"object": "<BYTECODE REMOVED>__$622b2f540b6a16ff5db7bea656ad8fcf4f$__<BYTECODE REMOVED>__$622b2f540b6a16ff5db7bea656ad8fcf4f$__<BYTECODE REMOVED>"
}
}
}
}
},
"sources":
{
"A":
{
"id": 0
}
}
}
20 changes: 19 additions & 1 deletion test/cmdlineTests/linking_standard_yul/output.json
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
{"contracts":{"A":{"a":{"evm":{"bytecode":{"linkReferences":{},"object":"<BYTECODE REMOVED>"}}}}},}
{
"contracts":
{
"A":
{
"a":
{
"evm":
{
"bytecode":
{
"linkReferences": {},
"object": "<BYTECODE REMOVED>"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
{"contracts":{"A":{"a":{"evm":{"bytecode":{"linkReferences":{},"object":"<BYTECODE REMOVED>"}}}}},}
{
"contracts":
{
"A":
{
"a":
{
"evm":
{
"bytecode":
{
"linkReferences": {},
"object": "<BYTECODE REMOVED>"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
{"contracts":{"A":{"a":{"evm":{"bytecode":{"linkReferences":{"contract/test.sol":{"L2":[{"length":20,"start":22}]}},"object":"<BYTECODE REMOVED>__$fb58009a6b1ecea3b9d99bedd645df4ec3$__<BYTECODE REMOVED>"}}}}},}
{
"contracts":
{
"A":
{
"a":
{
"evm":
{
"bytecode":
{
"linkReferences":
{
"contract/test.sol":
{
"L2":
[
{
"length": 20,
"start": 22
}
]
}
},
"object": "<BYTECODE REMOVED>__$fb58009a6b1ecea3b9d99bedd645df4ec3$__<BYTECODE REMOVED>"
}
}
}
}
}
}
43 changes: 42 additions & 1 deletion test/cmdlineTests/output_selection_all_A1/output.json
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
{"contracts":{"a.sol":{"A1":{"evm":{"bytecode":{"object":"<BYTECODE REMOVED>"}}}},"b.sol":{"A1":{"evm":{"bytecode":{"object":"<BYTECODE REMOVED>"}}}}},"sources":{"a.sol":{"id":0},"b.sol":{"id":1}}}
{
"contracts":
{
"a.sol":
{
"A1":
{
"evm":
{
"bytecode":
{
"object": "<BYTECODE REMOVED>"
}
}
}
},
"b.sol":
{
"A1":
{
"evm":
{
"bytecode":
{
"object": "<BYTECODE REMOVED>"
}
}
}
}
},
"sources":
{
"a.sol":
{
"id": 0
},
"b.sol":
{
"id": 1
}
}
}
30 changes: 29 additions & 1 deletion test/cmdlineTests/output_selection_all_A2/output.json
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
{"contracts":{"a.sol":{"A2":{"evm":{"bytecode":{"object":"<BYTECODE REMOVED>"}}}}},"sources":{"a.sol":{"id":0},"b.sol":{"id":1}}}
{
"contracts":
{
"a.sol":
{
"A2":
{
"evm":
{
"bytecode":
{
"object": "<BYTECODE REMOVED>"
}
}
}
}
},
"sources":
{
"a.sol":
{
"id": 0
},
"b.sol":
{
"id": 1
}
}
}
14 changes: 13 additions & 1 deletion test/cmdlineTests/output_selection_all_blank/output.json
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
{"sources":{"a.sol":{"id":0},"b.sol":{"id":1}}}
{
"sources":
{
"a.sol":
{
"id": 0
},
"b.sol":
{
"id": 1
}
}
}
Loading

0 comments on commit 1d85eb5

Please sign in to comment.