mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #13659 from Andy53/Report-when-no-contracts-to-compile
Report when no contracts to compile
This commit is contained in:
commit
71ce291cb9
@ -48,7 +48,6 @@
|
|||||||
#include <libevmasm/GasMeter.h>
|
#include <libevmasm/GasMeter.h>
|
||||||
|
|
||||||
#include <liblangutil/Exceptions.h>
|
#include <liblangutil/Exceptions.h>
|
||||||
#include <liblangutil/Scanner.h>
|
|
||||||
#include <liblangutil/SourceReferenceFormatter.h>
|
#include <liblangutil/SourceReferenceFormatter.h>
|
||||||
|
|
||||||
#include <libsmtutil/Exceptions.h>
|
#include <libsmtutil/Exceptions.h>
|
||||||
@ -1193,8 +1192,10 @@ void CommandLineInterface::outputCompilationResults()
|
|||||||
{
|
{
|
||||||
if (!m_options.output.dir.empty())
|
if (!m_options.output.dir.empty())
|
||||||
sout() << "Compiler run successful. Artifact(s) can be found in directory " << m_options.output.dir << "." << endl;
|
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
|
else
|
||||||
serr() << "Compiler run successful, no output requested." << endl;
|
sout() << "Compiler run successful. No output generated." << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,6 +225,11 @@ EOF
|
|||||||
sed -i.bak -e 's/ Consider adding "pragma .*$//' "$stderr_path"
|
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/\(Unimplemented feature error.* in \).*$/\1<FILENAME REMOVED>/' "$stderr_path"
|
||||||
sed -i.bak -e 's/"version":[ ]*"[^"]*"/"version": "<VERSION REMOVED>"/' "$stdout_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,
|
# 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
|
# use metadata markers for detection to have some confidence that it's actually bytecode
|
||||||
|
1
test/cmdlineTests/no_contract_combined_json/args
Normal file
1
test/cmdlineTests/no_contract_combined_json/args
Normal file
@ -0,0 +1 @@
|
|||||||
|
--combined-json ast --pretty-json --json-indent 4
|
2
test/cmdlineTests/no_contract_combined_json/input.sol
Normal file
2
test/cmdlineTests/no_contract_combined_json/input.sol
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
|
pragma solidity >=0.0;
|
36
test/cmdlineTests/no_contract_combined_json/output
Normal file
36
test/cmdlineTests/no_contract_combined_json/output
Normal file
@ -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>"
|
||||||
|
}
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <test/Common.h>
|
#include <test/Common.h>
|
||||||
#include <test/libsolidity/util/SoltestErrors.h>
|
#include <test/libsolidity/util/SoltestErrors.h>
|
||||||
|
#include <liblangutil/SemVerHandler.h>
|
||||||
#include <test/FilesystemUtils.h>
|
#include <test/FilesystemUtils.h>
|
||||||
|
|
||||||
#include <libsolutil/JSON.h>
|
#include <libsolutil/JSON.h>
|
||||||
@ -44,6 +45,7 @@ using namespace std;
|
|||||||
using namespace solidity::frontend;
|
using namespace solidity::frontend;
|
||||||
using namespace solidity::test;
|
using namespace solidity::test;
|
||||||
using namespace solidity::util;
|
using namespace solidity::util;
|
||||||
|
using namespace solidity::langutil;
|
||||||
|
|
||||||
using PathSet = set<boost::filesystem::path>;
|
using PathSet = set<boost::filesystem::path>;
|
||||||
|
|
||||||
@ -1006,10 +1008,14 @@ BOOST_AUTO_TEST_CASE(cli_include_paths)
|
|||||||
canonicalWorkDir / "lib",
|
canonicalWorkDir / "lib",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
string const expectedStdoutContent = "Compiler run successful. No contracts to compile.\n";
|
||||||
OptionsReaderAndMessages result = runCLI(commandLine, "");
|
OptionsReaderAndMessages result = runCLI(commandLine, "");
|
||||||
|
|
||||||
BOOST_TEST(result.stderrContent == "");
|
BOOST_TEST(result.stderrContent == "");
|
||||||
|
if (SemVerVersion{string(VersionString)}.isPrerelease())
|
||||||
BOOST_TEST(result.stdoutContent == "");
|
BOOST_TEST(result.stdoutContent == "");
|
||||||
|
else
|
||||||
|
BOOST_TEST(result.stdoutContent == expectedStdoutContent);
|
||||||
BOOST_REQUIRE(result.success);
|
BOOST_REQUIRE(result.success);
|
||||||
BOOST_TEST(result.options == expectedOptions);
|
BOOST_TEST(result.options == expectedOptions);
|
||||||
BOOST_TEST(result.reader.sourceUnits() == expectedSources);
|
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_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)
|
BOOST_AUTO_TEST_CASE(standard_json_include_paths)
|
||||||
{
|
{
|
||||||
TemporaryDirectory tempDir({"base/", "include/", "lib/nested/"}, TEST_CASE_NAME);
|
TemporaryDirectory tempDir({"base/", "include/", "lib/nested/"}, TEST_CASE_NAME);
|
||||||
|
Loading…
Reference in New Issue
Block a user