mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Make --pretty-json work with Standard JSON output
This commit is contained in:
committed by
Kamil Śliwak
parent
7041b87c3b
commit
9bbeea58c8
@@ -141,9 +141,16 @@ function test_solc_behaviour()
|
||||
|
||||
if [[ " ${solc_args[*]} " == *" --standard-json "* ]]
|
||||
then
|
||||
sed -i.bak -e 's/{[^{]*Warning: This is a pre-release compiler version[^}]*},\{0,1\}//' "$stdout_path"
|
||||
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"},\s*]", "}]", 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 any leftover trailing whitespace
|
||||
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 's/"errors":\[\],\{0,1\}//' "$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"
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
--combined-json abi --pretty-json --json-indent 3
|
||||
@@ -0,0 +1,3 @@
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.0;
|
||||
contract C {}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"contracts":
|
||||
{
|
||||
"pretty_json_combined/input.sol:C":
|
||||
{
|
||||
"abi": []
|
||||
}
|
||||
},
|
||||
"version": "<VERSION REMOVED>"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
--json-indent 7
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "Solidity",
|
||||
"sources":
|
||||
{
|
||||
"A":
|
||||
{
|
||||
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0; contract C {}"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"sources":
|
||||
{
|
||||
"A":
|
||||
{
|
||||
"id": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
--pretty-json
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "Solidity",
|
||||
"sources":
|
||||
{
|
||||
"A":
|
||||
{
|
||||
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0; contract C {}"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"sources":
|
||||
{
|
||||
"A":
|
||||
{
|
||||
"id": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
--pretty-json --json-indent 7
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"language": "Solidity",
|
||||
"sources":
|
||||
{
|
||||
"A":
|
||||
{
|
||||
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0; contract C { }"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"sources":
|
||||
{
|
||||
"A":
|
||||
{
|
||||
"id": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"sources":
|
||||
{
|
||||
"A":
|
||||
{
|
||||
"id": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,6 +138,7 @@ BOOST_AUTO_TEST_CASE(cli_mode_options)
|
||||
"--experimental-via-ir",
|
||||
"--revert-strings=strip",
|
||||
"--pretty-json",
|
||||
"--json-indent=7",
|
||||
"--no-color",
|
||||
"--error-codes",
|
||||
"--libraries="
|
||||
@@ -173,6 +174,7 @@ BOOST_AUTO_TEST_CASE(cli_mode_options)
|
||||
{"a", "b", "c/d"},
|
||||
{"", "contract.sol", ""},
|
||||
};
|
||||
|
||||
expectedOptions.input.addStdin = true;
|
||||
expectedOptions.input.basePath = "/home/user/";
|
||||
expectedOptions.input.allowedDirectories = {"/tmp", "/home", "project", "../contracts", "", "c", "/usr/lib"};
|
||||
@@ -183,11 +185,11 @@ BOOST_AUTO_TEST_CASE(cli_mode_options)
|
||||
expectedOptions.output.evmVersion = EVMVersion::spuriousDragon();
|
||||
expectedOptions.output.experimentalViaIR = true;
|
||||
expectedOptions.output.revertStrings = RevertStrings::Strip;
|
||||
expectedOptions.formatting.json = JsonFormat{JsonFormat::Pretty, 7};
|
||||
expectedOptions.linker.libraries = {
|
||||
{"dir1/file1.sol:L", h160("1234567890123456789012345678901234567890")},
|
||||
{"dir2/file2.sol:L", h160("1111122222333334444455555666667777788888")},
|
||||
};
|
||||
expectedOptions.formatting.prettyJson = true;
|
||||
expectedOptions.formatting.coloredOutput = false;
|
||||
expectedOptions.formatting.withErrorIds = true;
|
||||
expectedOptions.compiler.outputs = {
|
||||
@@ -269,6 +271,7 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
|
||||
"--experimental-via-ir", // Ignored in assembly mode
|
||||
"--revert-strings=strip", // Accepted but has no effect in assembly mode
|
||||
"--pretty-json",
|
||||
"--json-indent=1",
|
||||
"--no-color",
|
||||
"--error-codes",
|
||||
"--libraries="
|
||||
@@ -313,13 +316,13 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
|
||||
expectedOptions.output.overwriteFiles = true;
|
||||
expectedOptions.output.evmVersion = EVMVersion::spuriousDragon();
|
||||
expectedOptions.output.revertStrings = RevertStrings::Strip;
|
||||
expectedOptions.formatting.json = JsonFormat {JsonFormat::Pretty, 1};
|
||||
expectedOptions.assembly.targetMachine = expectedMachine;
|
||||
expectedOptions.assembly.inputLanguage = expectedLanguage;
|
||||
expectedOptions.linker.libraries = {
|
||||
{"dir1/file1.sol:L", h160("1234567890123456789012345678901234567890")},
|
||||
{"dir2/file2.sol:L", h160("1111122222333334444455555666667777788888")},
|
||||
};
|
||||
expectedOptions.formatting.prettyJson = true;
|
||||
expectedOptions.formatting.coloredOutput = false;
|
||||
expectedOptions.formatting.withErrorIds = true;
|
||||
expectedOptions.compiler.outputs = {
|
||||
@@ -359,7 +362,8 @@ BOOST_AUTO_TEST_CASE(standard_json_mode_options)
|
||||
"--evm-version=spuriousDragon", // Ignored in Standard JSON mode
|
||||
"--experimental-via-ir", // Ignored in Standard JSON mode
|
||||
"--revert-strings=strip", // Accepted but has no effect in Standard JSON mode
|
||||
"--pretty-json", // Accepted but has no effect in Standard JSON mode
|
||||
"--pretty-json",
|
||||
"--json-indent=1",
|
||||
"--no-color", // Accepted but has no effect in Standard JSON mode
|
||||
"--error-codes", // Accepted but has no effect in Standard JSON mode
|
||||
"--libraries=" // Ignored in Standard JSON mode
|
||||
@@ -387,6 +391,7 @@ BOOST_AUTO_TEST_CASE(standard_json_mode_options)
|
||||
};
|
||||
|
||||
CommandLineOptions expectedOptions;
|
||||
|
||||
expectedOptions.input.mode = InputMode::StandardJson;
|
||||
expectedOptions.input.paths = {};
|
||||
expectedOptions.input.standardJsonFile = "input.json";
|
||||
@@ -395,7 +400,7 @@ BOOST_AUTO_TEST_CASE(standard_json_mode_options)
|
||||
expectedOptions.output.dir = "/tmp/out";
|
||||
expectedOptions.output.overwriteFiles = true;
|
||||
expectedOptions.output.revertStrings = RevertStrings::Strip;
|
||||
expectedOptions.formatting.prettyJson = true;
|
||||
expectedOptions.formatting.json = JsonFormat {JsonFormat::Pretty, 1};
|
||||
expectedOptions.formatting.coloredOutput = false;
|
||||
expectedOptions.formatting.withErrorIds = true;
|
||||
expectedOptions.compiler.outputs = {
|
||||
|
||||
Reference in New Issue
Block a user