mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #12376 from ethereum/develop
Merge `develop` into `breaking`
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
/// Unit tests for solc/CommandLineInterface.h
|
||||
|
||||
#include <solc/CommandLineInterface.h>
|
||||
#include <solc/Exceptions.h>
|
||||
|
||||
#include <test/solc/Common.h>
|
||||
|
||||
@@ -114,7 +115,7 @@ BOOST_AUTO_TEST_SUITE(CommandLineInterfaceTest)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(help)
|
||||
{
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({"solc", "--help"}, "", /* _processInput */ true);
|
||||
OptionsReaderAndMessages result = runCLI({"solc", "--help"}, "");
|
||||
|
||||
BOOST_TEST(result.success);
|
||||
BOOST_TEST(boost::starts_with(result.stdoutContent, "solc, the Solidity commandline compiler."));
|
||||
@@ -124,7 +125,7 @@ BOOST_AUTO_TEST_CASE(help)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(license)
|
||||
{
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({"solc", "--license"}, "", /* _processInput */ true);
|
||||
OptionsReaderAndMessages result = runCLI({"solc", "--license"}, "");
|
||||
|
||||
BOOST_TEST(result.success);
|
||||
BOOST_TEST(boost::starts_with(result.stdoutContent, "Most of the code is licensed under GPLv3"));
|
||||
@@ -134,7 +135,7 @@ BOOST_AUTO_TEST_CASE(license)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(version)
|
||||
{
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({"solc", "--version"}, "", /* _processInput */ true);
|
||||
OptionsReaderAndMessages result = runCLI({"solc", "--version"}, "");
|
||||
|
||||
BOOST_TEST(result.success);
|
||||
BOOST_TEST(boost::ends_with(result.stdoutContent, "Version: " + solidity::frontend::VersionString + "\n"));
|
||||
@@ -158,17 +159,16 @@ BOOST_AUTO_TEST_CASE(multiple_input_modes)
|
||||
string expectedMessage =
|
||||
"The following options are mutually exclusive: "
|
||||
"--help, --license, --version, --standard-json, --link, --assemble, --strict-assembly, --yul, --import-ast. "
|
||||
"Select at most one.\n";
|
||||
"Select at most one.";
|
||||
|
||||
for (string const& mode1: inputModeOptions)
|
||||
for (string const& mode2: inputModeOptions)
|
||||
if (mode1 != mode2)
|
||||
{
|
||||
vector<string> commandLine = {"solc", mode1, mode2};
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles(commandLine);
|
||||
BOOST_TEST(!result.success);
|
||||
BOOST_TEST(result.stderrContent == expectedMessage);
|
||||
}
|
||||
BOOST_CHECK_EXCEPTION(
|
||||
parseCommandLineAndReadInputFiles({"solc", mode1, mode2}),
|
||||
CommandLineValidationError,
|
||||
[&](auto const& _exception) { BOOST_TEST(_exception.what() == expectedMessage); return true; }
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(cli_input)
|
||||
@@ -251,7 +251,7 @@ BOOST_AUTO_TEST_CASE(cli_ignore_missing_no_files_exist)
|
||||
"\"" + (tempDir.path() / "input2.sol").string() + "\" is not found. Skipping.\n"
|
||||
"All specified input files either do not exist or are not regular files.\n";
|
||||
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({
|
||||
OptionsReaderAndMessages result = runCLI({
|
||||
"solc",
|
||||
(tempDir.path() / "input1.sol").string(),
|
||||
(tempDir.path() / "input2.sol").string(),
|
||||
@@ -265,11 +265,13 @@ BOOST_AUTO_TEST_CASE(cli_not_a_file)
|
||||
{
|
||||
TemporaryDirectory tempDir(TEST_CASE_NAME);
|
||||
|
||||
string expectedMessage = "\"" + tempDir.path().string() + "\" is not a valid file.\n";
|
||||
string expectedMessage = "\"" + tempDir.path().string() + "\" is not a valid file.";
|
||||
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({"solc", tempDir.path().string()});
|
||||
BOOST_TEST(!result.success);
|
||||
BOOST_TEST(result.stderrContent == expectedMessage);
|
||||
BOOST_CHECK_EXCEPTION(
|
||||
parseCommandLineAndReadInputFiles({"solc", tempDir.path().string()}),
|
||||
CommandLineValidationError,
|
||||
[&](auto const& _exception) { BOOST_TEST(_exception.what() == expectedMessage); return true; }
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(standard_json_base_path)
|
||||
@@ -334,24 +336,26 @@ BOOST_AUTO_TEST_CASE(standard_json_two_input_files)
|
||||
{
|
||||
string expectedMessage =
|
||||
"Too many input files for --standard-json.\n"
|
||||
"Please either specify a single file name or provide its content on standard input.\n";
|
||||
"Please either specify a single file name or provide its content on standard input.";
|
||||
|
||||
vector<string> commandLine = {"solc", "--standard-json", "input1.json", "input2.json"};
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles(commandLine);
|
||||
BOOST_TEST(!result.success);
|
||||
BOOST_TEST(result.stderrContent == expectedMessage);
|
||||
BOOST_CHECK_EXCEPTION(
|
||||
parseCommandLineAndReadInputFiles({"solc", "--standard-json", "input1.json", "input2.json"}),
|
||||
CommandLineValidationError,
|
||||
[&](auto const& _exception) { BOOST_TEST(_exception.what() == expectedMessage); return true; }
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(standard_json_one_input_file_and_stdin)
|
||||
{
|
||||
string expectedMessage =
|
||||
"Too many input files for --standard-json.\n"
|
||||
"Please either specify a single file name or provide its content on standard input.\n";
|
||||
"Please either specify a single file name or provide its content on standard input.";
|
||||
|
||||
vector<string> commandLine = {"solc", "--standard-json", "input1.json", "-"};
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles(commandLine);
|
||||
BOOST_TEST(!result.success);
|
||||
BOOST_TEST(result.stderrContent == expectedMessage);
|
||||
BOOST_CHECK_EXCEPTION(
|
||||
parseCommandLineAndReadInputFiles({"solc", "--standard-json", "input1.json", "-"}),
|
||||
CommandLineValidationError,
|
||||
[&](auto const& _exception) { BOOST_TEST(_exception.what() == expectedMessage); return true; }
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(standard_json_ignore_missing)
|
||||
@@ -360,29 +364,31 @@ BOOST_AUTO_TEST_CASE(standard_json_ignore_missing)
|
||||
|
||||
// This option is pretty much useless Standard JSON mode.
|
||||
string expectedMessage =
|
||||
"\"" + (tempDir.path() / "input.json").string() + "\" is not found. Skipping.\n"
|
||||
"All specified input files either do not exist or are not regular files.\n";
|
||||
"All specified input files either do not exist or are not regular files.";
|
||||
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles({
|
||||
"solc",
|
||||
"--standard-json",
|
||||
(tempDir.path() / "input.json").string(),
|
||||
"--ignore-missing",
|
||||
});
|
||||
BOOST_TEST(!result.success);
|
||||
BOOST_TEST(result.stderrContent == expectedMessage);
|
||||
BOOST_CHECK_EXCEPTION(
|
||||
parseCommandLineAndReadInputFiles({
|
||||
"solc",
|
||||
"--standard-json",
|
||||
(tempDir.path() / "input.json").string(),
|
||||
"--ignore-missing",
|
||||
}),
|
||||
CommandLineValidationError,
|
||||
[&](auto const& _exception) { BOOST_TEST(_exception.what() == expectedMessage); return true; }
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(standard_json_remapping)
|
||||
{
|
||||
string expectedMessage =
|
||||
"Import remappings are not accepted on the command line in Standard JSON mode.\n"
|
||||
"Please put them under 'settings.remappings' in the JSON input.\n";
|
||||
"Please put them under 'settings.remappings' in the JSON input.";
|
||||
|
||||
vector<string> commandLine = {"solc", "--standard-json", "a=b"};
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles(commandLine);
|
||||
BOOST_TEST(!result.success);
|
||||
BOOST_TEST(result.stderrContent == expectedMessage);
|
||||
BOOST_CHECK_EXCEPTION(
|
||||
parseCommandLineAndReadInputFiles({"solc", "--standard-json", "a=b"}),
|
||||
CommandLineValidationError,
|
||||
[&](auto const& _exception) { BOOST_TEST(_exception.what() == expectedMessage); return true; }
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_no_base_path)
|
||||
@@ -995,11 +1001,7 @@ BOOST_AUTO_TEST_CASE(cli_include_paths)
|
||||
canonicalWorkDir / "lib",
|
||||
};
|
||||
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles(
|
||||
commandLine,
|
||||
"",
|
||||
true /* _processInput */
|
||||
);
|
||||
OptionsReaderAndMessages result = runCLI(commandLine, "");
|
||||
|
||||
BOOST_TEST(result.stderrContent == "");
|
||||
BOOST_TEST(result.stdoutContent == "");
|
||||
@@ -1085,11 +1087,7 @@ BOOST_AUTO_TEST_CASE(standard_json_include_paths)
|
||||
|
||||
FileReader::FileSystemPathSet expectedAllowedDirectories = {};
|
||||
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles(
|
||||
commandLine,
|
||||
standardJsonInput,
|
||||
true /* _processInput */
|
||||
);
|
||||
OptionsReaderAndMessages result = runCLI(commandLine, standardJsonInput);
|
||||
|
||||
Json::Value parsedStdout;
|
||||
string jsonParsingErrors;
|
||||
@@ -1117,18 +1115,19 @@ BOOST_AUTO_TEST_CASE(cli_include_paths_empty_path)
|
||||
TemporaryWorkingDirectory tempWorkDir(tempDir);
|
||||
createFilesWithParentDirs({tempDir.path() / "base/main.sol"});
|
||||
|
||||
string expectedMessage = "Empty values are not allowed in --include-path.\n";
|
||||
string expectedMessage = "Empty values are not allowed in --include-path.";
|
||||
|
||||
vector<string> commandLine = {
|
||||
"solc",
|
||||
"--base-path=base/",
|
||||
"--include-path", "include/",
|
||||
"--include-path", "",
|
||||
"base/main.sol",
|
||||
};
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles(commandLine);
|
||||
BOOST_TEST(!result.success);
|
||||
BOOST_TEST(result.stderrContent == expectedMessage);
|
||||
BOOST_CHECK_EXCEPTION(
|
||||
parseCommandLineAndReadInputFiles({
|
||||
"solc",
|
||||
"--base-path=base/",
|
||||
"--include-path", "include/",
|
||||
"--include-path", "",
|
||||
"base/main.sol",
|
||||
}),
|
||||
CommandLineValidationError,
|
||||
[&](auto const& _exception) { BOOST_TEST(_exception.what() == expectedMessage); return true; }
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(cli_include_paths_without_base_path)
|
||||
@@ -1137,12 +1136,13 @@ BOOST_AUTO_TEST_CASE(cli_include_paths_without_base_path)
|
||||
TemporaryWorkingDirectory tempWorkDir(tempDir);
|
||||
createFilesWithParentDirs({tempDir.path() / "contract.sol"});
|
||||
|
||||
string expectedMessage = "--include-path option requires a non-empty base path.\n";
|
||||
string expectedMessage = "--include-path option requires a non-empty base path.";
|
||||
|
||||
vector<string> commandLine = {"solc", "--include-path", "include/", "contract.sol"};
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles(commandLine);
|
||||
BOOST_TEST(!result.success);
|
||||
BOOST_TEST(result.stderrContent == expectedMessage);
|
||||
BOOST_CHECK_EXCEPTION(
|
||||
parseCommandLineAndReadInputFiles({"solc", "--include-path", "include/", "contract.sol"}),
|
||||
CommandLineValidationError,
|
||||
[&](auto const& _exception) { BOOST_TEST(_exception.what() == expectedMessage); return true; }
|
||||
);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(cli_include_paths_should_detect_source_unit_name_collisions)
|
||||
@@ -1171,35 +1171,37 @@ BOOST_AUTO_TEST_CASE(cli_include_paths_should_detect_source_unit_name_collisions
|
||||
|
||||
{
|
||||
// import "contract1.sol" and import "contract2.sol" would be ambiguous:
|
||||
vector<string> commandLine = {
|
||||
"solc",
|
||||
"--base-path=dir1/",
|
||||
"--include-path=dir2/",
|
||||
"dir1/contract1.sol",
|
||||
"dir2/contract1.sol",
|
||||
"dir1/contract2.sol",
|
||||
"dir2/contract2.sol",
|
||||
};
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles(commandLine);
|
||||
BOOST_TEST(result.stderrContent == expectedMessage);
|
||||
BOOST_REQUIRE(!result.success);
|
||||
BOOST_CHECK_EXCEPTION(
|
||||
parseCommandLineAndReadInputFiles({
|
||||
"solc",
|
||||
"--base-path=dir1/",
|
||||
"--include-path=dir2/",
|
||||
"dir1/contract1.sol",
|
||||
"dir2/contract1.sol",
|
||||
"dir1/contract2.sol",
|
||||
"dir2/contract2.sol",
|
||||
}),
|
||||
CommandLineValidationError,
|
||||
[&](auto const& _exception) { BOOST_TEST(_exception.what() == expectedMessage); return true; }
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
// import "contract1.sol" and import "contract2.sol" would be ambiguous:
|
||||
vector<string> commandLine = {
|
||||
"solc",
|
||||
"--base-path=dir3/",
|
||||
"--include-path=dir1/",
|
||||
"--include-path=dir2/",
|
||||
"dir1/contract1.sol",
|
||||
"dir2/contract1.sol",
|
||||
"dir1/contract2.sol",
|
||||
"dir2/contract2.sol",
|
||||
};
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles(commandLine);
|
||||
BOOST_TEST(result.stderrContent == expectedMessage);
|
||||
BOOST_REQUIRE(!result.success);
|
||||
BOOST_CHECK_EXCEPTION(
|
||||
parseCommandLineAndReadInputFiles({
|
||||
"solc",
|
||||
"--base-path=dir3/",
|
||||
"--include-path=dir1/",
|
||||
"--include-path=dir2/",
|
||||
"dir1/contract1.sol",
|
||||
"dir2/contract1.sol",
|
||||
"dir1/contract2.sol",
|
||||
"dir2/contract2.sol",
|
||||
}),
|
||||
CommandLineValidationError,
|
||||
[&](auto const& _exception) { BOOST_TEST(_exception.what() == expectedMessage); return true; }
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1314,12 +1316,7 @@ BOOST_AUTO_TEST_CASE(cli_include_paths_ambiguous_import)
|
||||
"3 | import \"contract.sol\";\n"
|
||||
" | ^^^^^^^^^^^^^^^^^^^^^^\n\n";
|
||||
|
||||
OptionsReaderAndMessages result = parseCommandLineAndReadInputFiles(
|
||||
commandLine,
|
||||
mainContractSource,
|
||||
true /* _processInput */
|
||||
);
|
||||
|
||||
OptionsReaderAndMessages result = runCLI(commandLine, mainContractSource);
|
||||
BOOST_TEST(result.stderrContent == expectedMessage);
|
||||
BOOST_REQUIRE(!result.success);
|
||||
}
|
||||
|
||||
@@ -95,11 +95,7 @@ ImportCheck checkImport(
|
||||
"pragma solidity >=0.0;\n" +
|
||||
_import + ";";
|
||||
|
||||
test::OptionsReaderAndMessages cliResult = test::parseCommandLineAndReadInputFiles(
|
||||
commandLine,
|
||||
standardInputContent,
|
||||
true /* processInput */
|
||||
);
|
||||
test::OptionsReaderAndMessages cliResult = test::runCLI(commandLine, standardInputContent);
|
||||
if (cliResult.success)
|
||||
return ImportCheck::OK();
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
/// Unit tests for solc/CommandLineParser.h
|
||||
|
||||
#include <solc/CommandLineParser.h>
|
||||
#include <solc/Exceptions.h>
|
||||
|
||||
#include <test/solc/Common.h>
|
||||
|
||||
@@ -46,17 +47,13 @@ using namespace solidity::yul;
|
||||
namespace
|
||||
{
|
||||
|
||||
optional<CommandLineOptions> parseCommandLine(vector<string> const& _commandLine, ostream& _stderr)
|
||||
CommandLineOptions parseCommandLine(vector<string> const& _commandLine)
|
||||
{
|
||||
vector<char const*> argv = test::makeArgv(_commandLine);
|
||||
|
||||
CommandLineParser cliParser(_stderr);
|
||||
bool success = cliParser.parse(static_cast<int>(_commandLine.size()), argv.data());
|
||||
|
||||
if (!success)
|
||||
return nullopt;
|
||||
else
|
||||
return cliParser.options();
|
||||
CommandLineParser cliParser;
|
||||
cliParser.parse(static_cast<int>(_commandLine.size()), argv.data());
|
||||
return cliParser.options();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -75,12 +72,9 @@ BOOST_AUTO_TEST_CASE(no_options)
|
||||
expectedOptions.modelChecker.initialize = true;
|
||||
expectedOptions.modelChecker.settings = {};
|
||||
|
||||
stringstream serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, serr);
|
||||
CommandLineOptions parsedOptions = parseCommandLine(commandLine);
|
||||
|
||||
BOOST_TEST(serr.str() == "");
|
||||
BOOST_REQUIRE(parsedOptions.has_value());
|
||||
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
||||
BOOST_TEST(parsedOptions == expectedOptions);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(help_license_version)
|
||||
@@ -93,15 +87,12 @@ BOOST_AUTO_TEST_CASE(help_license_version)
|
||||
|
||||
for (auto const& [option, expectedMode]: expectedModePerOption)
|
||||
{
|
||||
stringstream serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine({"solc", option}, serr);
|
||||
CommandLineOptions parsedOptions = parseCommandLine({"solc", option});
|
||||
|
||||
CommandLineOptions expectedOptions;
|
||||
expectedOptions.input.mode = expectedMode;
|
||||
|
||||
BOOST_TEST(serr.str() == "");
|
||||
BOOST_REQUIRE(parsedOptions.has_value());
|
||||
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
||||
BOOST_TEST(parsedOptions == expectedOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,12 +217,9 @@ BOOST_AUTO_TEST_CASE(cli_mode_options)
|
||||
5,
|
||||
};
|
||||
|
||||
stringstream serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, serr);
|
||||
CommandLineOptions parsedOptions = parseCommandLine(commandLine);
|
||||
|
||||
BOOST_TEST(serr.str() == "");
|
||||
BOOST_REQUIRE(parsedOptions.has_value());
|
||||
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
||||
BOOST_TEST(parsedOptions == expectedOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,12 +340,9 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
|
||||
expectedOptions.optimizer.expectedExecutionsPerDeployment = 1000;
|
||||
}
|
||||
|
||||
stringstream serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, serr);
|
||||
CommandLineOptions parsedOptions = parseCommandLine(commandLine);
|
||||
|
||||
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);
|
||||
BOOST_TEST(parsedOptions == expectedOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,12 +405,9 @@ BOOST_AUTO_TEST_CASE(standard_json_mode_options)
|
||||
expectedOptions.compiler.combinedJsonRequests->abi = true;
|
||||
expectedOptions.compiler.combinedJsonRequests->binary = true;
|
||||
|
||||
stringstream serr;
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, serr);
|
||||
CommandLineOptions parsedOptions = parseCommandLine(commandLine);
|
||||
|
||||
BOOST_TEST(serr.str() == "");
|
||||
BOOST_REQUIRE(parsedOptions.has_value());
|
||||
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
||||
BOOST_TEST(parsedOptions == expectedOptions);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(invalid_options_input_modes_combinations)
|
||||
@@ -441,10 +423,11 @@ BOOST_AUTO_TEST_CASE(invalid_options_input_modes_combinations)
|
||||
{
|
||||
stringstream serr;
|
||||
vector<string> commandLine = {"solc", optionName, "file", inputMode};
|
||||
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, serr);
|
||||
|
||||
BOOST_TEST(serr.str() == "The following options are not supported in the current input mode: " + optionName + "\n");
|
||||
BOOST_REQUIRE(!parsedOptions.has_value());
|
||||
string expectedMessage = "The following options are not supported in the current input mode: " + optionName;
|
||||
auto hasCorrectMessage = [&](CommandLineValidationError const& _exception) { return _exception.what() == expectedMessage; };
|
||||
|
||||
BOOST_CHECK_EXCEPTION(parseCommandLine(commandLine), CommandLineValidationError, hasCorrectMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+22
-6
@@ -41,18 +41,34 @@ vector<char const*> test::makeArgv(vector<string> const& _commandLine)
|
||||
|
||||
test::OptionsReaderAndMessages test::parseCommandLineAndReadInputFiles(
|
||||
vector<string> const& _commandLine,
|
||||
string const& _standardInputContent,
|
||||
bool _processInput
|
||||
string const& _standardInputContent
|
||||
)
|
||||
{
|
||||
vector<char const*> argv = makeArgv(_commandLine);
|
||||
stringstream sin(_standardInputContent), sout, serr;
|
||||
CommandLineInterface cli(sin, sout, serr);
|
||||
bool success = cli.parseArguments(static_cast<int>(_commandLine.size()), argv.data());
|
||||
if (success)
|
||||
success = cli.readInputFiles();
|
||||
if (success && _processInput)
|
||||
success = cli.processInput();
|
||||
cli.readInputFiles();
|
||||
|
||||
return {
|
||||
success,
|
||||
cli.options(),
|
||||
cli.fileReader(),
|
||||
cli.standardJsonInput(),
|
||||
sout.str(),
|
||||
stripPreReleaseWarning(serr.str()),
|
||||
};
|
||||
}
|
||||
|
||||
test::OptionsReaderAndMessages test::runCLI(
|
||||
vector<string> const& _commandLine,
|
||||
string const& _standardInputContent
|
||||
)
|
||||
{
|
||||
vector<char const*> argv = makeArgv(_commandLine);
|
||||
stringstream sin(_standardInputContent), sout, serr;
|
||||
CommandLineInterface cli(sin, sout, serr);
|
||||
bool success = cli.run(static_cast<int>(_commandLine.size()), argv.data());
|
||||
|
||||
return {
|
||||
success,
|
||||
|
||||
+18
-2
@@ -44,10 +44,26 @@ struct OptionsReaderAndMessages
|
||||
|
||||
std::vector<char const*> makeArgv(std::vector<std::string> const& _commandLine);
|
||||
|
||||
/// Runs only command-line parsing, without compilation, assembling or any other input processing.
|
||||
/// Lets through any @a CommandLineErrors throw by the CLI.
|
||||
/// Note: This uses the @a CommandLineInterface class and does not actually spawn a new process.
|
||||
/// @param _commandLine Arguments in the form of strings that would be specified on the command-line.
|
||||
/// You must specify the program name as the first item.
|
||||
/// @param _standardInputContent Content that the CLI will be able to read from its standard input.
|
||||
OptionsReaderAndMessages parseCommandLineAndReadInputFiles(
|
||||
std::vector<std::string> const& _commandLine,
|
||||
std::string const& _standardInputContent = "",
|
||||
bool _processInput = false
|
||||
std::string const& _standardInputContent = ""
|
||||
);
|
||||
|
||||
/// Runs all stages of command-line interface processing, including error handling.
|
||||
/// Never throws @a CommandLineError - validation errors are included in the returned stderr content.
|
||||
/// Note: This uses the @a CommandLineInterface class and does not actually spawn a new process.
|
||||
/// @param _commandLine Arguments in the form of strings that would be specified on the command-line.
|
||||
/// You must specify the program name as the first item.
|
||||
/// @param _standardInputContent Content that the CLI will be able to read from its standard input.
|
||||
OptionsReaderAndMessages runCLI(
|
||||
std::vector<std::string> const& _commandLine,
|
||||
std::string const& _standardInputContent = ""
|
||||
);
|
||||
|
||||
std::string stripPreReleaseWarning(std::string const& _stderrContent);
|
||||
|
||||
Reference in New Issue
Block a user