Skip to content

Commit 1d85eb5

Browse files
authored
Merge pull request #13586 from GeorgePlotnikov/use-pretty-json-for-cmlinetests-output
Use `--pretty-json` for `cmdlineTests.sh` output by default
2 parents 799ef0a + b0a729a commit 1d85eb5

File tree

202 files changed

+9169
-494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+9169
-494
lines changed

ReviewChecklist.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ It is also meant to serve as a final checklist for reviewers to go through befor
2626
- [ ] Avoid basing PRs from forks on branches other than `develop` or `breaking` because
2727
GitHub closes them when the base branch gets merged.
2828
Do this only for PRs created directly in the main repo.
29+
- [ ] **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.
30+
In many cases the expectations can be updated automatically:
31+
- `cmdlineTests.sh --update` for command-line tests.
32+
- `isoltest --enforce-gas-cost --accept-updates` for soltest-based tests.
33+
- 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.
34+
- Review updated files before committing them.
35+
**Are expectations correct and do updated tests still serve their purpose?**
2936

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

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
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
{"contracts":{"A":{"C":{"evm":{"bytecode":{"linkReferences":{},"object":"<BYTECODE REMOVED>"}}}}},"sources":{"A":{"id":0}}}
1+
{
2+
"contracts":
3+
{
4+
"A":
5+
{
6+
"C":
7+
{
8+
"evm":
9+
{
10+
"bytecode":
11+
{
12+
"linkReferences": {},
13+
"object": "<BYTECODE REMOVED>"
14+
}
15+
}
16+
}
17+
}
18+
},
19+
"sources":
20+
{
21+
"A":
22+
{
23+
"id": 0
24+
}
25+
}
26+
}
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
{"contracts":{"A\"B":{"C":{"evm":{"bytecode":{"linkReferences":{},"object":"<BYTECODE REMOVED>"}}}}},"sources":{"A\"B":{"id":0}}}
1+
{
2+
"contracts":
3+
{
4+
"A\"B":
5+
{
6+
"C":
7+
{
8+
"evm":
9+
{
10+
"bytecode":
11+
{
12+
"linkReferences": {},
13+
"object": "<BYTECODE REMOVED>"
14+
}
15+
}
16+
}
17+
}
18+
},
19+
"sources":
20+
{
21+
"A\"B":
22+
{
23+
"id": 0
24+
}
25+
}
26+
}
Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,42 @@
1-
{"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}}}
1+
{
2+
"contracts":
3+
{
4+
"A":
5+
{
6+
"C":
7+
{
8+
"evm":
9+
{
10+
"bytecode":
11+
{
12+
"linkReferences":
13+
{
14+
"A":
15+
{
16+
"L2":
17+
[
18+
{
19+
"length": 20,
20+
"start": 184
21+
},
22+
{
23+
"length": 20,
24+
"start": 368
25+
}
26+
]
27+
}
28+
},
29+
"object": "<BYTECODE REMOVED>__$622b2f540b6a16ff5db7bea656ad8fcf4f$__<BYTECODE REMOVED>__$622b2f540b6a16ff5db7bea656ad8fcf4f$__<BYTECODE REMOVED>"
30+
}
31+
}
32+
}
33+
}
34+
},
35+
"sources":
36+
{
37+
"A":
38+
{
39+
"id": 0
40+
}
41+
}
42+
}
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
{"contracts":{"A":{"a":{"evm":{"bytecode":{"linkReferences":{},"object":"<BYTECODE REMOVED>"}}}}},}
1+
{
2+
"contracts":
3+
{
4+
"A":
5+
{
6+
"a":
7+
{
8+
"evm":
9+
{
10+
"bytecode":
11+
{
12+
"linkReferences": {},
13+
"object": "<BYTECODE REMOVED>"
14+
}
15+
}
16+
}
17+
}
18+
}
19+
}
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
{"contracts":{"A":{"a":{"evm":{"bytecode":{"linkReferences":{},"object":"<BYTECODE REMOVED>"}}}}},}
1+
{
2+
"contracts":
3+
{
4+
"A":
5+
{
6+
"a":
7+
{
8+
"evm":
9+
{
10+
"bytecode":
11+
{
12+
"linkReferences": {},
13+
"object": "<BYTECODE REMOVED>"
14+
}
15+
}
16+
}
17+
}
18+
}
19+
}
Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,31 @@
1-
{"contracts":{"A":{"a":{"evm":{"bytecode":{"linkReferences":{"contract/test.sol":{"L2":[{"length":20,"start":22}]}},"object":"<BYTECODE REMOVED>__$fb58009a6b1ecea3b9d99bedd645df4ec3$__<BYTECODE REMOVED>"}}}}},}
1+
{
2+
"contracts":
3+
{
4+
"A":
5+
{
6+
"a":
7+
{
8+
"evm":
9+
{
10+
"bytecode":
11+
{
12+
"linkReferences":
13+
{
14+
"contract/test.sol":
15+
{
16+
"L2":
17+
[
18+
{
19+
"length": 20,
20+
"start": 22
21+
}
22+
]
23+
}
24+
},
25+
"object": "<BYTECODE REMOVED>__$fb58009a6b1ecea3b9d99bedd645df4ec3$__<BYTECODE REMOVED>"
26+
}
27+
}
28+
}
29+
}
30+
}
31+
}
Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,42 @@
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}}}
1+
{
2+
"contracts":
3+
{
4+
"a.sol":
5+
{
6+
"A1":
7+
{
8+
"evm":
9+
{
10+
"bytecode":
11+
{
12+
"object": "<BYTECODE REMOVED>"
13+
}
14+
}
15+
}
16+
},
17+
"b.sol":
18+
{
19+
"A1":
20+
{
21+
"evm":
22+
{
23+
"bytecode":
24+
{
25+
"object": "<BYTECODE REMOVED>"
26+
}
27+
}
28+
}
29+
}
30+
},
31+
"sources":
32+
{
33+
"a.sol":
34+
{
35+
"id": 0
36+
},
37+
"b.sol":
38+
{
39+
"id": 1
40+
}
41+
}
42+
}
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
{"contracts":{"a.sol":{"A2":{"evm":{"bytecode":{"object":"<BYTECODE REMOVED>"}}}}},"sources":{"a.sol":{"id":0},"b.sol":{"id":1}}}
1+
{
2+
"contracts":
3+
{
4+
"a.sol":
5+
{
6+
"A2":
7+
{
8+
"evm":
9+
{
10+
"bytecode":
11+
{
12+
"object": "<BYTECODE REMOVED>"
13+
}
14+
}
15+
}
16+
}
17+
},
18+
"sources":
19+
{
20+
"a.sol":
21+
{
22+
"id": 0
23+
},
24+
"b.sol":
25+
{
26+
"id": 1
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)