2019-02-19 16:34:59 +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/>.
|
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2019-02-19 16:34:59 +00:00
|
|
|
/** @file IsolTestOptions.cpp
|
|
|
|
* @date 2019
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <test/tools/IsolTestOptions.h>
|
2019-04-10 14:09:32 +00:00
|
|
|
|
2020-01-06 10:52:23 +00:00
|
|
|
#include <libsolutil/Assertions.h>
|
2019-04-10 14:09:32 +00:00
|
|
|
|
2019-02-19 16:34:59 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2019-04-10 14:09:32 +00:00
|
|
|
|
2019-02-19 16:34:59 +00:00
|
|
|
#include <iostream>
|
2019-04-10 14:09:32 +00:00
|
|
|
#include <regex>
|
|
|
|
#include <string>
|
2019-02-19 16:34:59 +00:00
|
|
|
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
namespace po = boost::program_options;
|
|
|
|
|
2019-12-23 15:50:30 +00:00
|
|
|
namespace solidity::test
|
2019-02-19 16:34:59 +00:00
|
|
|
{
|
|
|
|
|
2020-12-08 20:06:10 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2019-02-19 16:34:59 +00:00
|
|
|
auto const description = R"(isoltest, tool for interactively managing test contracts.
|
2019-04-10 14:09:32 +00:00
|
|
|
Usage: isoltest [Options]
|
2019-02-19 16:34:59 +00:00
|
|
|
Interactively validates test contracts.
|
|
|
|
|
|
|
|
Allowed options)";
|
|
|
|
|
|
|
|
std::string editorPath()
|
|
|
|
{
|
|
|
|
if (getenv("EDITOR"))
|
|
|
|
return getenv("EDITOR");
|
|
|
|
else if (fs::exists("/usr/bin/editor"))
|
|
|
|
return "/usr/bin/editor";
|
|
|
|
|
|
|
|
return std::string{};
|
|
|
|
}
|
|
|
|
|
2020-12-08 20:06:10 +00:00
|
|
|
}
|
|
|
|
|
2021-09-20 18:22:58 +00:00
|
|
|
IsolTestOptions::IsolTestOptions():
|
2019-02-19 16:34:59 +00:00
|
|
|
CommonOptions(description)
|
2021-09-18 09:55:50 +00:00
|
|
|
{
|
|
|
|
enforceViaYul = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsolTestOptions::addOptions()
|
2019-02-19 16:34:59 +00:00
|
|
|
{
|
2021-09-18 11:22:27 +00:00
|
|
|
CommonOptions::addOptions();
|
2019-02-19 16:34:59 +00:00
|
|
|
options.add_options()
|
2021-09-20 18:22:58 +00:00
|
|
|
("editor", po::value<std::string>(&editor)->default_value(editorPath()), "Path to editor for opening test files.")
|
2021-09-18 12:13:04 +00:00
|
|
|
("help", po::bool_switch(&showHelp)->default_value(showHelp), "Show this help screen.")
|
|
|
|
("no-color", po::bool_switch(&noColor)->default_value(noColor), "Don't use colors.")
|
|
|
|
("accept-updates", po::bool_switch(&acceptUpdates)->default_value(acceptUpdates), "Automatically accept expectation updates.")
|
2019-04-17 09:45:51 +00:00
|
|
|
("test,t", po::value<std::string>(&testFilter)->default_value("*/*"), "Filters which test units to include.");
|
2019-02-19 16:34:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsolTestOptions::parse(int _argc, char const* const* _argv)
|
|
|
|
{
|
|
|
|
bool const res = CommonOptions::parse(_argc, _argv);
|
|
|
|
|
|
|
|
if (showHelp || !res)
|
|
|
|
{
|
|
|
|
std::cout << options << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-27 16:20:04 +00:00
|
|
|
enforceGasTest = enforceGasTest || (evmVersion() == langutil::EVMVersion{} && !useABIEncoderV1);
|
2021-10-27 16:02:26 +00:00
|
|
|
|
2019-02-19 16:34:59 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-04-10 14:09:32 +00:00
|
|
|
void IsolTestOptions::validate() const
|
|
|
|
{
|
2021-09-18 11:59:37 +00:00
|
|
|
CommonOptions::validate();
|
2020-09-17 15:06:08 +00:00
|
|
|
static std::string filterString{"[a-zA-Z0-9_/*]*"};
|
2019-04-17 09:45:51 +00:00
|
|
|
static std::regex filterExpression{filterString};
|
2019-04-10 14:09:32 +00:00
|
|
|
assertThrow(
|
2019-04-17 09:45:51 +00:00
|
|
|
regex_match(testFilter, filterExpression),
|
2019-04-10 14:09:32 +00:00
|
|
|
ConfigException,
|
2019-04-17 09:45:51 +00:00
|
|
|
"Invalid test unit filter - can only contain '" + filterString + ": " + testFilter
|
2019-04-10 14:09:32 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-19 16:34:59 +00:00
|
|
|
}
|