2021-06-07 17:04:02 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
|
|
|
|
|
|
|
/// Unit tests for solc/CommandLineParser.h
|
|
|
|
|
|
|
|
#include <solc/CommandLineParser.h>
|
|
|
|
|
2021-06-13 13:53:16 +00:00
|
|
|
#include <test/solc/Common.h>
|
|
|
|
|
2021-06-07 17:04:02 +00:00
|
|
|
#include <test/Common.h>
|
|
|
|
#include <test/libsolidity/util/SoltestErrors.h>
|
|
|
|
|
|
|
|
#include <libsolutil/CommonData.h>
|
|
|
|
#include <liblangutil/EVMVersion.h>
|
2021-05-19 15:35:19 +00:00
|
|
|
#include <libsmtutil/SolverInterface.h>
|
2021-06-07 17:04:02 +00:00
|
|
|
#include <libsolidity/interface/Version.h>
|
|
|
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <optional>
|
|
|
|
#include <ostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace solidity::frontend;
|
|
|
|
using namespace solidity::langutil;
|
|
|
|
using namespace solidity::util;
|
|
|
|
using namespace solidity::yul;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2021-06-13 13:53:16 +00:00
|
|
|
optional<CommandLineOptions> parseCommandLine(vector<string> const& _commandLine, ostream& _stdout, ostream& _stderr)
|
2021-06-07 17:04:02 +00:00
|
|
|
{
|
2021-06-13 13:53:16 +00:00
|
|
|
vector<char const*> argv = test::makeArgv(_commandLine);
|
2021-06-07 17:04:02 +00:00
|
|
|
|
2021-06-10 15:45:09 +00:00
|
|
|
CommandLineParser cliParser(_stdout, _stderr);
|
2021-06-07 17:04:02 +00:00
|
|
|
bool success = cliParser.parse(
|
2021-06-13 13:53:16 +00:00
|
|
|
static_cast<int>(_commandLine.size()),
|
2021-06-07 17:04:02 +00:00
|
|
|
argv.data(),
|
|
|
|
false // interactiveTerminal
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
return nullopt;
|
|
|
|
else
|
|
|
|
return cliParser.options();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace solidity::frontend::test
|
|
|
|
{
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(CommandLineParserTest)
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(no_options)
|
|
|
|
{
|
|
|
|
vector<string> commandLine = {"solc", "contract.sol"};
|
|
|
|
|
|
|
|
CommandLineOptions expectedOptions;
|
|
|
|
expectedOptions.input.paths = {"contract.sol"};
|
|
|
|
expectedOptions.modelChecker.initialize = true;
|
2021-07-15 15:39:01 +00:00
|
|
|
expectedOptions.modelChecker.settings = {};
|
2021-06-07 17:04:02 +00:00
|
|
|
|
2021-06-10 15:45:09 +00:00
|
|
|
stringstream sout, serr;
|
|
|
|
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
|
2021-06-07 17:04:02 +00:00
|
|
|
|
2021-06-10 15:45:09 +00:00
|
|
|
BOOST_TEST(sout.str() == "");
|
|
|
|
BOOST_TEST(serr.str() == "");
|
2021-06-07 17:04:02 +00:00
|
|
|
BOOST_REQUIRE(parsedOptions.has_value());
|
2021-06-13 13:53:16 +00:00
|
|
|
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
2021-06-07 17:04:02 +00:00
|
|
|
}
|
|
|
|
|
2021-06-16 20:50:32 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(help)
|
|
|
|
{
|
|
|
|
stringstream sout, serr;
|
|
|
|
optional<CommandLineOptions> parsedOptions = parseCommandLine({"solc", "--help"}, sout, serr);
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2021-06-07 17:04:02 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(cli_mode_options)
|
|
|
|
{
|
|
|
|
for (InputMode inputMode: {InputMode::Compiler, InputMode::CompilerWithASTImport})
|
|
|
|
{
|
|
|
|
vector<string> commandLine = {
|
|
|
|
"solc",
|
|
|
|
"contract.sol", // Both modes do not care about file names, just about
|
|
|
|
"/tmp/projects/token.sol", // their content. They also both support stdin.
|
|
|
|
"/home/user/lib/dex.sol",
|
|
|
|
"file",
|
|
|
|
"input.json",
|
|
|
|
"-",
|
|
|
|
"/tmp=/usr/lib/",
|
|
|
|
"a:b=c/d",
|
|
|
|
":contract.sol=",
|
|
|
|
"--base-path=/home/user/",
|
2021-08-20 17:17:44 +00:00
|
|
|
"--include-path=/usr/lib/include/",
|
|
|
|
"--include-path=/home/user/include",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--allow-paths=/tmp,/home,project,../contracts",
|
|
|
|
"--ignore-missing",
|
|
|
|
"--error-recovery",
|
|
|
|
"--output-dir=/tmp/out",
|
|
|
|
"--overwrite",
|
|
|
|
"--evm-version=spuriousDragon",
|
|
|
|
"--experimental-via-ir",
|
|
|
|
"--revert-strings=strip",
|
2021-09-13 12:17:05 +00:00
|
|
|
"--debug-info=location",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--pretty-json",
|
2021-07-07 11:18:24 +00:00
|
|
|
"--json-indent=7",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--no-color",
|
|
|
|
"--error-codes",
|
|
|
|
"--libraries="
|
|
|
|
"dir1/file1.sol:L=0x1234567890123456789012345678901234567890,"
|
|
|
|
"dir2/file2.sol:L=0x1111122222333334444455555666667777788888",
|
|
|
|
"--ast-compact-json", "--asm", "--asm-json", "--opcodes", "--bin", "--bin-runtime", "--abi",
|
|
|
|
"--ir", "--ir-optimized", "--ewasm", "--hashes", "--userdoc", "--devdoc", "--metadata", "--storage-layout",
|
|
|
|
"--gas",
|
|
|
|
"--combined-json="
|
|
|
|
"abi,metadata,bin,bin-runtime,opcodes,asm,storage-layout,generated-sources,generated-sources-runtime,"
|
|
|
|
"srcmap,srcmap-runtime,function-debug,function-debug-runtime,hashes,devdoc,userdoc,ast",
|
|
|
|
"--metadata-hash=swarm",
|
|
|
|
"--metadata-literal",
|
|
|
|
"--optimize",
|
|
|
|
"--optimize-runs=1000",
|
|
|
|
"--yul-optimizations=agf",
|
|
|
|
"--model-checker-contracts=contract1.yul:A,contract2.yul:B",
|
2021-07-15 15:39:01 +00:00
|
|
|
"--model-checker-div-mod-no-slacks",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--model-checker-engine=bmc",
|
2021-08-11 08:54:03 +00:00
|
|
|
"--model-checker-show-unproved",
|
2021-05-19 15:35:19 +00:00
|
|
|
"--model-checker-solvers=z3,smtlib2",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--model-checker-targets=underflow,divByZero",
|
|
|
|
"--model-checker-timeout=5",
|
|
|
|
};
|
|
|
|
|
|
|
|
if (inputMode == InputMode::CompilerWithASTImport)
|
|
|
|
commandLine += vector<string>{
|
|
|
|
"--import-ast",
|
|
|
|
};
|
|
|
|
|
|
|
|
CommandLineOptions expectedOptions;
|
|
|
|
expectedOptions.input.mode = inputMode;
|
|
|
|
expectedOptions.input.paths = {"contract.sol", "/tmp/projects/token.sol", "/home/user/lib/dex.sol", "file", "input.json"};
|
|
|
|
expectedOptions.input.remappings = {
|
|
|
|
{"", "/tmp", "/usr/lib/"},
|
|
|
|
{"a", "b", "c/d"},
|
|
|
|
{"", "contract.sol", ""},
|
|
|
|
};
|
2021-07-07 11:18:24 +00:00
|
|
|
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.input.addStdin = true;
|
|
|
|
expectedOptions.input.basePath = "/home/user/";
|
2021-08-20 17:17:44 +00:00
|
|
|
expectedOptions.input.includePaths = {"/usr/lib/include/", "/home/user/include"};
|
|
|
|
|
2021-07-23 18:27:50 +00:00
|
|
|
expectedOptions.input.allowedDirectories = {"/tmp", "/home", "project", "../contracts", "c", "/usr/lib"};
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.input.ignoreMissingFiles = true;
|
|
|
|
expectedOptions.input.errorRecovery = (inputMode == InputMode::Compiler);
|
|
|
|
expectedOptions.output.dir = "/tmp/out";
|
|
|
|
expectedOptions.output.overwriteFiles = true;
|
|
|
|
expectedOptions.output.evmVersion = EVMVersion::spuriousDragon();
|
|
|
|
expectedOptions.output.experimentalViaIR = true;
|
|
|
|
expectedOptions.output.revertStrings = RevertStrings::Strip;
|
2021-09-13 12:17:05 +00:00
|
|
|
expectedOptions.output.debugInfoSelection = DebugInfoSelection::fromString("location");
|
2021-07-07 11:18:24 +00:00
|
|
|
expectedOptions.formatting.json = JsonFormat{JsonFormat::Pretty, 7};
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.linker.libraries = {
|
|
|
|
{"dir1/file1.sol:L", h160("1234567890123456789012345678901234567890")},
|
|
|
|
{"dir2/file2.sol:L", h160("1111122222333334444455555666667777788888")},
|
|
|
|
};
|
|
|
|
expectedOptions.formatting.coloredOutput = false;
|
|
|
|
expectedOptions.formatting.withErrorIds = true;
|
|
|
|
expectedOptions.compiler.outputs = {
|
|
|
|
true, true, true, true, true,
|
|
|
|
true, true, true, true, true,
|
|
|
|
true, true, true, true, true,
|
|
|
|
};
|
|
|
|
expectedOptions.compiler.estimateGas = true;
|
|
|
|
expectedOptions.compiler.combinedJsonRequests = {
|
|
|
|
true, true, true, true, true,
|
|
|
|
true, true, true, true, true,
|
|
|
|
true, true, true, true, true,
|
|
|
|
true, true,
|
|
|
|
};
|
|
|
|
expectedOptions.metadata.hash = CompilerStack::MetadataHash::Bzzr1;
|
|
|
|
expectedOptions.metadata.literalSources = true;
|
|
|
|
expectedOptions.optimizer.enabled = true;
|
|
|
|
expectedOptions.optimizer.expectedExecutionsPerDeployment = 1000;
|
|
|
|
expectedOptions.optimizer.yulSteps = "agf";
|
|
|
|
|
|
|
|
expectedOptions.modelChecker.initialize = true;
|
|
|
|
expectedOptions.modelChecker.settings = {
|
|
|
|
{{{"contract1.yul", {"A"}}, {"contract2.yul", {"B"}}}},
|
2021-07-15 15:39:01 +00:00
|
|
|
true,
|
2021-06-07 17:04:02 +00:00
|
|
|
{true, false},
|
2021-07-02 13:05:24 +00:00
|
|
|
true,
|
2021-05-19 15:35:19 +00:00
|
|
|
{false, true, true},
|
2021-06-07 17:04:02 +00:00
|
|
|
{{VerificationTargetType::Underflow, VerificationTargetType::DivByZero}},
|
|
|
|
5,
|
|
|
|
};
|
|
|
|
|
2021-06-10 15:45:09 +00:00
|
|
|
stringstream sout, serr;
|
|
|
|
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
|
2021-06-07 17:04:02 +00:00
|
|
|
|
2021-06-10 15:45:09 +00:00
|
|
|
BOOST_TEST(sout.str() == "");
|
|
|
|
BOOST_TEST(serr.str() == "");
|
2021-06-07 17:04:02 +00:00
|
|
|
BOOST_REQUIRE(parsedOptions.has_value());
|
2021-06-13 13:53:16 +00:00
|
|
|
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
2021-06-07 17:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(assembly_mode_options)
|
|
|
|
{
|
|
|
|
static vector<tuple<vector<string>, AssemblyStack::Machine, AssemblyStack::Language>> const allowedCombinations = {
|
|
|
|
{{"--machine=ewasm", "--yul-dialect=ewasm", "--assemble"}, AssemblyStack::Machine::Ewasm, AssemblyStack::Language::Ewasm},
|
|
|
|
{{"--machine=ewasm", "--yul-dialect=ewasm", "--yul"}, AssemblyStack::Machine::Ewasm, AssemblyStack::Language::Ewasm},
|
|
|
|
{{"--machine=ewasm", "--yul-dialect=ewasm", "--strict-assembly"}, AssemblyStack::Machine::Ewasm, AssemblyStack::Language::Ewasm},
|
|
|
|
{{"--machine=ewasm", "--yul-dialect=evm", "--assemble"}, AssemblyStack::Machine::Ewasm, AssemblyStack::Language::StrictAssembly},
|
|
|
|
{{"--machine=ewasm", "--yul-dialect=evm", "--yul"}, AssemblyStack::Machine::Ewasm, AssemblyStack::Language::StrictAssembly},
|
|
|
|
{{"--machine=ewasm", "--yul-dialect=evm", "--strict-assembly"}, AssemblyStack::Machine::Ewasm, AssemblyStack::Language::StrictAssembly},
|
|
|
|
{{"--machine=ewasm", "--strict-assembly"}, AssemblyStack::Machine::Ewasm, AssemblyStack::Language::Ewasm},
|
|
|
|
{{"--machine=evm", "--yul-dialect=evm", "--assemble"}, AssemblyStack::Machine::EVM, AssemblyStack::Language::StrictAssembly},
|
|
|
|
{{"--machine=evm", "--yul-dialect=evm", "--yul"}, AssemblyStack::Machine::EVM, AssemblyStack::Language::StrictAssembly},
|
|
|
|
{{"--machine=evm", "--yul-dialect=evm", "--strict-assembly"}, AssemblyStack::Machine::EVM, AssemblyStack::Language::StrictAssembly},
|
|
|
|
{{"--machine=evm", "--assemble"}, AssemblyStack::Machine::EVM, AssemblyStack::Language::Assembly},
|
|
|
|
{{"--machine=evm", "--yul"}, AssemblyStack::Machine::EVM, AssemblyStack::Language::Yul},
|
|
|
|
{{"--machine=evm", "--strict-assembly"}, AssemblyStack::Machine::EVM, AssemblyStack::Language::StrictAssembly},
|
|
|
|
{{"--assemble"}, AssemblyStack::Machine::EVM, AssemblyStack::Language::Assembly},
|
|
|
|
{{"--yul"}, AssemblyStack::Machine::EVM, AssemblyStack::Language::Yul},
|
|
|
|
{{"--strict-assembly"}, AssemblyStack::Machine::EVM, AssemblyStack::Language::StrictAssembly},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (auto const& [assemblyOptions, expectedMachine, expectedLanguage]: allowedCombinations)
|
|
|
|
{
|
|
|
|
vector<string> commandLine = {
|
|
|
|
"solc",
|
|
|
|
"contract.yul",
|
|
|
|
"/tmp/projects/token.yul",
|
|
|
|
"/home/user/lib/dex.yul",
|
|
|
|
"file",
|
|
|
|
"input.json",
|
|
|
|
"-",
|
|
|
|
"/tmp=/usr/lib/",
|
|
|
|
"a:b=c/d",
|
|
|
|
":contract.yul=",
|
|
|
|
"--base-path=/home/user/",
|
2021-08-20 17:17:44 +00:00
|
|
|
"--include-path=/usr/lib/include/",
|
|
|
|
"--include-path=/home/user/include",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--allow-paths=/tmp,/home,project,../contracts",
|
|
|
|
"--ignore-missing",
|
|
|
|
"--error-recovery", // Ignored in assembly mode
|
|
|
|
"--overwrite",
|
|
|
|
"--evm-version=spuriousDragon",
|
|
|
|
"--revert-strings=strip", // Accepted but has no effect in assembly mode
|
2021-09-13 12:17:05 +00:00
|
|
|
"--debug-info=location",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--pretty-json",
|
2021-07-07 11:18:24 +00:00
|
|
|
"--json-indent=1",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--no-color",
|
|
|
|
"--error-codes",
|
|
|
|
"--libraries="
|
|
|
|
"dir1/file1.sol:L=0x1234567890123456789012345678901234567890,"
|
|
|
|
"dir2/file2.sol:L=0x1111122222333334444455555666667777788888",
|
|
|
|
"--metadata-hash=swarm", // Ignored in assembly mode
|
|
|
|
"--metadata-literal", // Ignored in assembly mode
|
|
|
|
"--model-checker-contracts=" // Ignored in assembly mode
|
|
|
|
"contract1.yul:A,"
|
|
|
|
"contract2.yul:B",
|
2021-07-15 15:39:01 +00:00
|
|
|
"--model-checker-div-mod-no-slacks", // Ignored in assembly mode
|
2021-06-07 17:04:02 +00:00
|
|
|
"--model-checker-engine=bmc", // Ignored in assembly mode
|
2021-08-11 08:54:03 +00:00
|
|
|
"--model-checker-show-unproved", // Ignored in assembly mode
|
2021-05-19 15:35:19 +00:00
|
|
|
"--model-checker-solvers=z3,smtlib2", // Ignored in assembly mode
|
2021-06-07 17:04:02 +00:00
|
|
|
"--model-checker-targets=" // Ignored in assembly mode
|
|
|
|
"underflow,"
|
|
|
|
"divByZero",
|
|
|
|
"--model-checker-timeout=5", // Ignored in assembly mode
|
|
|
|
};
|
|
|
|
commandLine += assemblyOptions;
|
|
|
|
if (expectedLanguage == AssemblyStack::Language::StrictAssembly || expectedLanguage == AssemblyStack::Language::Ewasm)
|
|
|
|
commandLine += vector<string>{
|
|
|
|
"--optimize",
|
2021-07-28 15:53:19 +00:00
|
|
|
"--optimize-runs=1000",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--yul-optimizations=agf",
|
|
|
|
};
|
|
|
|
|
|
|
|
CommandLineOptions expectedOptions;
|
|
|
|
expectedOptions.input.mode = InputMode::Assembler;
|
|
|
|
|
|
|
|
expectedOptions.input.paths = {"contract.yul", "/tmp/projects/token.yul", "/home/user/lib/dex.yul", "file", "input.json"};
|
|
|
|
expectedOptions.input.remappings = {
|
|
|
|
{"", "/tmp", "/usr/lib/"},
|
|
|
|
{"a", "b", "c/d"},
|
|
|
|
{"", "contract.yul", ""},
|
|
|
|
};
|
|
|
|
expectedOptions.input.addStdin = true;
|
|
|
|
expectedOptions.input.basePath = "/home/user/";
|
2021-08-20 17:17:44 +00:00
|
|
|
expectedOptions.input.includePaths = {"/usr/lib/include/", "/home/user/include"};
|
2021-07-23 18:27:50 +00:00
|
|
|
expectedOptions.input.allowedDirectories = {"/tmp", "/home", "project", "../contracts", "c", "/usr/lib"};
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.input.ignoreMissingFiles = true;
|
|
|
|
expectedOptions.output.overwriteFiles = true;
|
|
|
|
expectedOptions.output.evmVersion = EVMVersion::spuriousDragon();
|
|
|
|
expectedOptions.output.revertStrings = RevertStrings::Strip;
|
2021-09-13 12:17:05 +00:00
|
|
|
expectedOptions.output.debugInfoSelection = DebugInfoSelection::fromString("location");
|
2021-07-07 11:18:24 +00:00
|
|
|
expectedOptions.formatting.json = JsonFormat {JsonFormat::Pretty, 1};
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.assembly.targetMachine = expectedMachine;
|
|
|
|
expectedOptions.assembly.inputLanguage = expectedLanguage;
|
|
|
|
expectedOptions.linker.libraries = {
|
|
|
|
{"dir1/file1.sol:L", h160("1234567890123456789012345678901234567890")},
|
|
|
|
{"dir2/file2.sol:L", h160("1111122222333334444455555666667777788888")},
|
|
|
|
};
|
|
|
|
expectedOptions.formatting.coloredOutput = false;
|
|
|
|
expectedOptions.formatting.withErrorIds = true;
|
|
|
|
if (expectedLanguage == AssemblyStack::Language::StrictAssembly || expectedLanguage == AssemblyStack::Language::Ewasm)
|
|
|
|
{
|
|
|
|
expectedOptions.optimizer.enabled = true;
|
|
|
|
expectedOptions.optimizer.yulSteps = "agf";
|
2021-07-28 15:53:19 +00:00
|
|
|
expectedOptions.optimizer.expectedExecutionsPerDeployment = 1000;
|
2021-06-07 17:04:02 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 15:45:09 +00:00
|
|
|
stringstream sout, serr;
|
|
|
|
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
|
2021-06-07 17:04:02 +00:00
|
|
|
|
2021-06-10 15:45:09 +00:00
|
|
|
BOOST_TEST(sout.str() == "");
|
|
|
|
BOOST_TEST(serr.str() == "Warning: Yul is still experimental. Please use the output with care.\n");
|
2021-06-07 17:04:02 +00:00
|
|
|
BOOST_REQUIRE(parsedOptions.has_value());
|
2021-06-13 13:53:16 +00:00
|
|
|
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
2021-06-07 17:04:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(standard_json_mode_options)
|
|
|
|
{
|
|
|
|
vector<string> commandLine = {
|
|
|
|
"solc",
|
|
|
|
"input.json",
|
|
|
|
"--standard-json",
|
|
|
|
"--base-path=/home/user/",
|
2021-08-20 17:17:44 +00:00
|
|
|
"--include-path=/usr/lib/include/",
|
|
|
|
"--include-path=/home/user/include",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--allow-paths=/tmp,/home,project,../contracts",
|
2021-06-13 13:53:16 +00:00
|
|
|
"--ignore-missing",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--error-recovery", // Ignored in Standard JSON mode
|
|
|
|
"--output-dir=/tmp/out", // Accepted but has no effect in Standard JSON mode
|
|
|
|
"--overwrite", // Accepted but has no effect in Standard JSON mode
|
|
|
|
"--evm-version=spuriousDragon", // Ignored in Standard JSON mode
|
|
|
|
"--revert-strings=strip", // Accepted but has no effect in Standard JSON mode
|
2021-07-07 11:18:24 +00:00
|
|
|
"--pretty-json",
|
|
|
|
"--json-indent=1",
|
2021-06-07 17:04:02 +00:00
|
|
|
"--no-color", // Accepted but has no effect in Standard JSON mode
|
|
|
|
"--error-codes", // Accepted but has no effect in Standard JSON mode
|
|
|
|
"--libraries=" // Ignored in Standard JSON mode
|
|
|
|
"dir1/file1.sol:L=0x1234567890123456789012345678901234567890,"
|
|
|
|
"dir2/file2.sol:L=0x1111122222333334444455555666667777788888",
|
|
|
|
"--gas", // Accepted but has no effect in Standard JSON mode
|
|
|
|
"--combined-json=abi,bin", // Accepted but has no effect in Standard JSON mode
|
|
|
|
"--metadata-hash=swarm", // Ignored in Standard JSON mode
|
|
|
|
"--metadata-literal", // Ignored in Standard JSON mode
|
|
|
|
"--model-checker-contracts=" // Ignored in Standard JSON mode
|
|
|
|
"contract1.yul:A,"
|
|
|
|
"contract2.yul:B",
|
2021-07-15 15:39:01 +00:00
|
|
|
"--model-checker-div-mod-no-slacks", // Ignored in Standard JSON mode
|
2021-06-07 17:04:02 +00:00
|
|
|
"--model-checker-engine=bmc", // Ignored in Standard JSON mode
|
2021-08-11 08:54:03 +00:00
|
|
|
"--model-checker-show-unproved", // Ignored in Standard JSON mode
|
2021-05-19 15:35:19 +00:00
|
|
|
"--model-checker-solvers=z3,smtlib2", // Ignored in Standard JSON mode
|
2021-06-07 17:04:02 +00:00
|
|
|
"--model-checker-targets=" // Ignored in Standard JSON mode
|
|
|
|
"underflow,"
|
|
|
|
"divByZero",
|
|
|
|
"--model-checker-timeout=5", // Ignored in Standard JSON mode
|
|
|
|
};
|
|
|
|
|
|
|
|
CommandLineOptions expectedOptions;
|
2021-07-07 11:18:24 +00:00
|
|
|
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.input.mode = InputMode::StandardJson;
|
2021-06-13 13:53:16 +00:00
|
|
|
expectedOptions.input.paths = {"input.json"};
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.input.basePath = "/home/user/";
|
2021-08-20 17:17:44 +00:00
|
|
|
expectedOptions.input.includePaths = {"/usr/lib/include/", "/home/user/include"};
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.input.allowedDirectories = {"/tmp", "/home", "project", "../contracts"};
|
2021-06-13 13:53:16 +00:00
|
|
|
expectedOptions.input.ignoreMissingFiles = true;
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.output.dir = "/tmp/out";
|
|
|
|
expectedOptions.output.overwriteFiles = true;
|
|
|
|
expectedOptions.output.revertStrings = RevertStrings::Strip;
|
2021-07-07 11:18:24 +00:00
|
|
|
expectedOptions.formatting.json = JsonFormat {JsonFormat::Pretty, 1};
|
2021-06-07 17:04:02 +00:00
|
|
|
expectedOptions.formatting.coloredOutput = false;
|
|
|
|
expectedOptions.formatting.withErrorIds = true;
|
|
|
|
expectedOptions.compiler.estimateGas = true;
|
|
|
|
expectedOptions.compiler.combinedJsonRequests = CombinedJsonRequests{};
|
|
|
|
expectedOptions.compiler.combinedJsonRequests->abi = true;
|
|
|
|
expectedOptions.compiler.combinedJsonRequests->binary = true;
|
|
|
|
|
2021-06-10 15:45:09 +00:00
|
|
|
stringstream sout, serr;
|
|
|
|
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
|
2021-06-07 17:04:02 +00:00
|
|
|
|
2021-06-10 15:45:09 +00:00
|
|
|
BOOST_TEST(sout.str() == "");
|
|
|
|
BOOST_TEST(serr.str() == "");
|
2021-06-07 17:04:02 +00:00
|
|
|
BOOST_REQUIRE(parsedOptions.has_value());
|
2021-06-13 13:53:16 +00:00
|
|
|
BOOST_TEST(parsedOptions.value() == expectedOptions);
|
2021-06-07 17:04:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-27 16:10:41 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(experimental_via_ir_invalid_input_modes)
|
|
|
|
{
|
|
|
|
static array<string, 5> const inputModeOptions = {
|
|
|
|
"--assemble",
|
|
|
|
"--yul",
|
|
|
|
"--strict-assembly",
|
|
|
|
"--standard-json",
|
|
|
|
"--link",
|
|
|
|
};
|
|
|
|
for (string const& inputModeOption: inputModeOptions)
|
|
|
|
{
|
|
|
|
stringstream sout, serr;
|
|
|
|
vector<string> commandLine = {
|
|
|
|
"solc",
|
|
|
|
"--experimental-via-ir",
|
|
|
|
"file",
|
|
|
|
inputModeOption,
|
|
|
|
};
|
|
|
|
optional<CommandLineOptions> parsedOptions = parseCommandLine(commandLine, sout, serr);
|
|
|
|
|
|
|
|
BOOST_TEST(sout.str() == "");
|
|
|
|
BOOST_TEST(serr.str() == "The option --experimental-via-ir is only supported in the compiler mode.\n");
|
|
|
|
BOOST_REQUIRE(!parsedOptions.has_value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-07 17:04:02 +00:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|
|
|
|
|
|
|
|
} // namespace solidity::frontend::test
|