Skip to content

Commit

Permalink
Merge pull request ethereum#13659 from Andy53/Report-when-no-contract…
Browse files Browse the repository at this point in the history
…s-to-compile

Report when no contracts to compile
  • Loading branch information
cameel authored Dec 21, 2022
2 parents 32f94d4 + 3bc535e commit 71ce291
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 3 deletions.
5 changes: 3 additions & 2 deletions solc/CommandLineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include <libevmasm/GasMeter.h>

#include <liblangutil/Exceptions.h>
#include <liblangutil/Scanner.h>
#include <liblangutil/SourceReferenceFormatter.h>

#include <libsmtutil/Exceptions.h>
Expand Down Expand Up @@ -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;
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/cmdlineTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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<FILENAME REMOVED>/' "$stderr_path"
sed -i.bak -e 's/"version":[ ]*"[^"]*"/"version": "<VERSION REMOVED>"/' "$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
Expand Down
1 change: 1 addition & 0 deletions test/cmdlineTests/no_contract_combined_json/args
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--combined-json ast --pretty-json --json-indent 4
2 changes: 2 additions & 0 deletions test/cmdlineTests/no_contract_combined_json/input.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;
36 changes: 36 additions & 0 deletions test/cmdlineTests/no_contract_combined_json/output
Original file line number Diff line number Diff line change
@@ -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": "<VERSION REMOVED>"
}
45 changes: 44 additions & 1 deletion test/solc/CommandLineInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <test/Common.h>
#include <test/libsolidity/util/SoltestErrors.h>
#include <liblangutil/SemVerHandler.h>
#include <test/FilesystemUtils.h>

#include <libsolutil/JSON.h>
Expand All @@ -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<boost::filesystem::path>;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 71ce291

Please sign in to comment.