mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #12118 from ethereum/separate-input-modes-for-help-license-version
Separate input modes for `--help`, `--license` and `--version`
This commit is contained in:
@@ -29,6 +29,8 @@
|
||||
|
||||
#include <libsolutil/JSON.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include <range/v3/view/transform.hpp>
|
||||
|
||||
#include <map>
|
||||
@@ -110,9 +112,42 @@ namespace solidity::frontend::test
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(CommandLineInterfaceTest)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(help)
|
||||
{
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({"solc", "--help"}, "", /* _processInput */ true);
|
||||
|
||||
BOOST_TEST(result.success);
|
||||
BOOST_TEST(boost::starts_with(result.stdoutContent, "solc, the Solidity commandline compiler."));
|
||||
BOOST_TEST(result.stderrContent == "");
|
||||
BOOST_TEST(result.options.input.mode == InputMode::Help);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(license)
|
||||
{
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({"solc", "--license"}, "", /* _processInput */ true);
|
||||
|
||||
BOOST_TEST(result.success);
|
||||
BOOST_TEST(boost::starts_with(result.stdoutContent, "Most of the code is licensed under GPLv3"));
|
||||
BOOST_TEST(result.stderrContent == "");
|
||||
BOOST_TEST(result.options.input.mode == InputMode::License);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(version)
|
||||
{
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({"solc", "--version"}, "", /* _processInput */ true);
|
||||
|
||||
BOOST_TEST(result.success);
|
||||
BOOST_TEST(boost::ends_with(result.stdoutContent, "Version: " + solidity::frontend::VersionString + "\n"));
|
||||
BOOST_TEST(result.stderrContent == "");
|
||||
BOOST_TEST(result.options.input.mode == InputMode::Version);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(multiple_input_modes)
|
||||
{
|
||||
array<string, 6> inputModeOptions = {
|
||||
array<string, 9> inputModeOptions = {
|
||||
"--help",
|
||||
"--license",
|
||||
"--version",
|
||||
"--standard-json",
|
||||
"--link",
|
||||
"--assemble",
|
||||
@@ -122,7 +157,7 @@ BOOST_AUTO_TEST_CASE(multiple_input_modes)
|
||||
};
|
||||
string expectedMessage =
|
||||
"The following options are mutually exclusive: "
|
||||
"--standard-json, --link, --assemble, --strict-assembly, --yul, --import-ast. "
|
||||
"--help, --license, --version, --standard-json, --link, --assemble, --strict-assembly, --yul, --import-ast. "
|
||||
"Select at most one.\n";
|
||||
|
||||
for (string const& mode1: inputModeOptions)
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
#include <libsmtutil/SolverInterface.h>
|
||||
#include <libsolidity/interface/Version.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
@@ -48,16 +46,12 @@ using namespace solidity::yul;
|
||||
namespace
|
||||
{
|
||||
|
||||
optional<CommandLineOptions> parseCommandLine(vector<string> const& _commandLine, ostream& _stdout, ostream& _stderr)
|
||||
optional<CommandLineOptions> parseCommandLine(vector<string> const& _commandLine, ostream& _stderr)
|
||||
{
|
||||
vector<char const*> argv = test::makeArgv(_commandLine);
|
||||
|
||||
CommandLineParser cliParser(_stdout, _stderr);
|
||||
bool success = cliParser.parse(
|
||||
static_cast<int>(_commandLine.size()),
|
||||
argv.data(),
|
||||
false // interactiveTerminal
|
||||
);
|
||||
CommandLineParser cliParser(_stderr);
|
||||
bool success = cliParser.parse(static_cast<int>(_commandLine.size()), argv.data());
|
||||
|
||||
if (!success)
|
||||
return nullopt;
|
||||
@@ -81,24 +75,34 @@ BOOST_AUTO_TEST_CASE(no_options)
|
||||
expectedOptions.modelChecker.initialize = true;
|
||||
expectedOptions.modelChecker.settings = {};
|
||||
|
||||
stringstream sout, serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
|
||||
stringstream serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, serr);
|
||||
|
||||
BOOST_TEST(sout.str() == "");
|
||||
BOOST_TEST(serr.str() == "");
|
||||
BOOST_REQUIRE(parsedOptions.has_value());
|
||||
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(help)
|
||||
BOOST_AUTO_TEST_CASE(help_license_version)
|
||||
{
|
||||
stringstream sout, serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine({"solc", "--help"}, sout, serr);
|
||||
map<string, InputMode> expectedModePerOption = {
|
||||
{"--help", InputMode::Help},
|
||||
{"--license", InputMode::License},
|
||||
{"--version", InputMode::Version},
|
||||
};
|
||||
|
||||
BOOST_TEST(serr.str() == "");
|
||||
BOOST_TEST(boost::starts_with(sout.str(), "solc, the Solidity commandline compiler."));
|
||||
BOOST_TEST(sout.str().find("Usage: solc [options] [input_file...]") != string::npos);
|
||||
BOOST_TEST(!parsedOptions.has_value());
|
||||
for (auto const& [option, expectedMode]: expectedModePerOption)
|
||||
{
|
||||
stringstream serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine({"solc", option}, serr);
|
||||
|
||||
CommandLineOptions expectedOptions;
|
||||
expectedOptions.input.mode = expectedMode;
|
||||
|
||||
BOOST_TEST(serr.str() == "");
|
||||
BOOST_REQUIRE(parsedOptions.has_value());
|
||||
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(cli_mode_options)
|
||||
@@ -220,10 +224,9 @@ BOOST_AUTO_TEST_CASE(cli_mode_options)
|
||||
5,
|
||||
};
|
||||
|
||||
stringstream sout, serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
|
||||
stringstream serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, serr);
|
||||
|
||||
BOOST_TEST(sout.str() == "");
|
||||
BOOST_TEST(serr.str() == "");
|
||||
BOOST_REQUIRE(parsedOptions.has_value());
|
||||
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
||||
@@ -337,10 +340,9 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
|
||||
expectedOptions.optimizer.expectedExecutionsPerDeployment = 1000;
|
||||
}
|
||||
|
||||
stringstream sout, serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
|
||||
stringstream serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, serr);
|
||||
|
||||
BOOST_TEST(sout.str() == "");
|
||||
BOOST_TEST(serr.str() == "Warning: Yul is still experimental. Please use the output with care.\n");
|
||||
BOOST_REQUIRE(parsedOptions.has_value());
|
||||
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
||||
@@ -406,10 +408,9 @@ BOOST_AUTO_TEST_CASE(standard_json_mode_options)
|
||||
expectedOptions.compiler.combinedJsonRequests->abi = true;
|
||||
expectedOptions.compiler.combinedJsonRequests->binary = true;
|
||||
|
||||
stringstream sout, serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
|
||||
stringstream serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, serr);
|
||||
|
||||
BOOST_TEST(sout.str() == "");
|
||||
BOOST_TEST(serr.str() == "");
|
||||
BOOST_REQUIRE(parsedOptions.has_value());
|
||||
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
||||
@@ -426,11 +427,10 @@ BOOST_AUTO_TEST_CASE(invalid_options_input_modes_combinations)
|
||||
for (auto const& [optionName, inputModes]: invalidOptionInputModeCombinations)
|
||||
for (string const& inputMode: inputModes)
|
||||
{
|
||||
stringstream sout, serr;
|
||||
stringstream serr;
|
||||
vector<string> commandLine = {"solc", optionName, "file", inputMode};
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, serr);
|
||||
|
||||
BOOST_TEST(sout.str() == "");
|
||||
BOOST_TEST(serr.str() == "The following options are not supported in the current input mode: " + optionName + "\n");
|
||||
BOOST_REQUIRE(!parsedOptions.has_value());
|
||||
}
|
||||
|
||||
@@ -70,6 +70,10 @@ string test::stripPreReleaseWarning(string const& _stderrContent)
|
||||
R"(Warning( \(3805\))?: This is a pre-release compiler version, please do not use it in production\.\n)"
|
||||
R"((\n)?)"
|
||||
};
|
||||
static regex const noOutputRegex{
|
||||
R"(Compiler run successful, no output requested\.\n)"
|
||||
};
|
||||
|
||||
return regex_replace(_stderrContent, preReleaseWarningRegex, "");
|
||||
string output = regex_replace(_stderrContent, preReleaseWarningRegex, "");
|
||||
return regex_replace(move(output), noOutputRegex, "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user