From 3bc535e1a1b9c3d6d32d21c798b9bc2f5f12b71f Mon Sep 17 00:00:00 2001 From: andy53 Date: Wed, 2 Nov 2022 20:46:54 -0600 Subject: [PATCH] Report when no contracts to compile updates --- solc/CommandLineInterface.cpp | 5 ++- test/cmdlineTests.sh | 5 +++ .../no_contract_combined_json/args | 1 + .../no_contract_combined_json/input.sol | 2 + .../no_contract_combined_json/output | 36 +++++++++++++++ test/solc/CommandLineInterface.cpp | 45 ++++++++++++++++++- 6 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 test/cmdlineTests/no_contract_combined_json/args create mode 100644 test/cmdlineTests/no_contract_combined_json/input.sol create mode 100644 test/cmdlineTests/no_contract_combined_json/output diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 3973008f9589..c687d44b5443 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -48,7 +48,6 @@ #include #include -#include #include #include @@ -1193,8 +1192,10 @@ void CommandLineInterface::outputCompilationResults() { if (!m_options.output.dir.empty()) sout() << "Compiler run successful. Artifact(s) can be found in directory " << m_options.output.dir << "." << endl; + else if (contracts.empty()) + sout() << "Compiler run successful. No contracts to compile." << endl; else - serr() << "Compiler run successful, no output requested." << endl; + sout() << "Compiler run successful. No output generated." << endl; } } diff --git a/test/cmdlineTests.sh b/test/cmdlineTests.sh index d04117156a46..ce9af142fc76 100755 --- a/test/cmdlineTests.sh +++ b/test/cmdlineTests.sh @@ -225,6 +225,11 @@ EOF sed -i.bak -e 's/ Consider adding "pragma .*$//' "$stderr_path" sed -i.bak -e 's/\(Unimplemented feature error.* in \).*$/\1/' "$stderr_path" sed -i.bak -e 's/"version":[ ]*"[^"]*"/"version": ""/' "$stdout_path" + if [[ $stdout_expectation_file != "" && $stderr_expectation_file != "" ]] + then + sed -i.bak -e '/^Compiler run successful\. No contracts to compile\.$/d' "$stdout_path" + sed -i.bak -e '/^Compiler run successful\. No output generated\.$/d' "$stdout_path" + fi # Remove bytecode (but not linker references). Since non-JSON output is unstructured, # use metadata markers for detection to have some confidence that it's actually bytecode diff --git a/test/cmdlineTests/no_contract_combined_json/args b/test/cmdlineTests/no_contract_combined_json/args new file mode 100644 index 000000000000..8d81d1c0f2b4 --- /dev/null +++ b/test/cmdlineTests/no_contract_combined_json/args @@ -0,0 +1 @@ +--combined-json ast --pretty-json --json-indent 4 \ No newline at end of file diff --git a/test/cmdlineTests/no_contract_combined_json/input.sol b/test/cmdlineTests/no_contract_combined_json/input.sol new file mode 100644 index 000000000000..b926e9263b96 --- /dev/null +++ b/test/cmdlineTests/no_contract_combined_json/input.sol @@ -0,0 +1,2 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; \ No newline at end of file diff --git a/test/cmdlineTests/no_contract_combined_json/output b/test/cmdlineTests/no_contract_combined_json/output new file mode 100644 index 000000000000..af7300896046 --- /dev/null +++ b/test/cmdlineTests/no_contract_combined_json/output @@ -0,0 +1,36 @@ +{ + "sourceList": + [ + "no_contract_combined_json/input.sol" + ], + "sources": + { + "no_contract_combined_json/input.sol": + { + "AST": + { + "absolutePath": "no_contract_combined_json/input.sol", + "exportedSymbols": {}, + "id": 2, + "license": "GPL-3.0", + "nodeType": "SourceUnit", + "nodes": + [ + { + "id": 1, + "literals": + [ + "solidity", + ">=", + "0.0" + ], + "nodeType": "PragmaDirective", + "src": "36:22:0" + } + ], + "src": "36:22:0" + } + } + }, + "version": "" +} diff --git a/test/solc/CommandLineInterface.cpp b/test/solc/CommandLineInterface.cpp index 2ae57541bdd5..8124b1545f56 100644 --- a/test/solc/CommandLineInterface.cpp +++ b/test/solc/CommandLineInterface.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -44,6 +45,7 @@ using namespace std; using namespace solidity::frontend; using namespace solidity::test; using namespace solidity::util; +using namespace solidity::langutil; using PathSet = set; @@ -1006,10 +1008,14 @@ BOOST_AUTO_TEST_CASE(cli_include_paths) canonicalWorkDir / "lib", }; + string const expectedStdoutContent = "Compiler run successful. No contracts to compile.\n"; OptionsReaderAndMessages result = runCLI(commandLine, ""); BOOST_TEST(result.stderrContent == ""); - BOOST_TEST(result.stdoutContent == ""); + if (SemVerVersion{string(VersionString)}.isPrerelease()) + BOOST_TEST(result.stdoutContent == ""); + else + BOOST_TEST(result.stdoutContent == expectedStdoutContent); BOOST_REQUIRE(result.success); BOOST_TEST(result.options == expectedOptions); BOOST_TEST(result.reader.sourceUnits() == expectedSources); @@ -1018,6 +1024,43 @@ BOOST_AUTO_TEST_CASE(cli_include_paths) BOOST_TEST(result.reader.basePath() == expectedWorkDir / "base/"); } +BOOST_AUTO_TEST_CASE(cli_no_contracts_to_compile) +{ + string const contractSource = R"( + // SPDX-License-Identifier: GPL-3.0 + pragma solidity >=0.0; + enum Status { test } + )"; + + string const expectedStdoutContent = "Compiler run successful. No contracts to compile.\n"; + OptionsReaderAndMessages result = runCLI({"solc", "-"}, contractSource); + + if (SemVerVersion{string(VersionString)}.isPrerelease()) + BOOST_TEST(result.stdoutContent == ""); + else + BOOST_TEST(result.stdoutContent == expectedStdoutContent); + BOOST_REQUIRE(result.success); +} + +BOOST_AUTO_TEST_CASE(cli_no_output) +{ + string const contractSource = R"( + // SPDX-License-Identifier: GPL-3.0 + pragma solidity >=0.0; + abstract contract A { + function B() public virtual returns(uint); + })"; + + string const expectedStdoutContent = "Compiler run successful. No output generated.\n"; + OptionsReaderAndMessages result = runCLI({"solc", "-"}, contractSource); + + if (SemVerVersion{string(VersionString)}.isPrerelease()) + BOOST_TEST(result.stdoutContent == ""); + else + BOOST_TEST(result.stdoutContent == expectedStdoutContent); + BOOST_REQUIRE(result.success); +} + BOOST_AUTO_TEST_CASE(standard_json_include_paths) { TemporaryDirectory tempDir({"base/", "include/", "lib/nested/"}, TEST_CASE_NAME);