solidity/test/Options.cpp

101 lines
2.7 KiB
C++
Raw Normal View History

2016-08-02 16:32:03 +00:00
/*
This file is part of solidity.
2016-08-02 16:32:03 +00:00
solidity is free software: you can redistribute it and/or modify
2016-08-02 16:32:03 +00:00
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,
2016-08-02 16:32:03 +00:00
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/>.
2016-08-02 16:32:03 +00:00
*/
/** @file TestHelper.h
* @author Marko Simovic <markobarko@gmail.com>
* @date 2014
*/
#include <test/Options.h>
2018-02-22 16:21:26 +00:00
#include <libsolidity/interface/EVMVersion.h>
#include <libsolidity/interface/Exceptions.h>
2018-02-22 16:21:26 +00:00
2016-08-02 16:32:03 +00:00
#include <boost/test/framework.hpp>
2018-02-22 16:21:26 +00:00
2016-08-02 16:32:03 +00:00
using namespace std;
using namespace dev::test;
2016-08-06 09:37:52 +00:00
Options const& Options::get()
2016-08-02 16:32:03 +00:00
{
2016-08-06 09:37:52 +00:00
static Options instance;
return instance;
}
Options::Options()
{
auto const& suite = boost::unit_test::framework::master_test_suite();
for (auto i = 0; i < suite.argc; i++)
2016-08-29 12:21:49 +00:00
if (string(suite.argv[i]) == "--ipcpath" && i + 1 < suite.argc)
2016-08-02 16:32:03 +00:00
{
2016-08-06 09:37:52 +00:00
ipcPath = suite.argv[i + 1];
2016-08-02 16:32:03 +00:00
i++;
}
else if (string(suite.argv[i]) == "--testpath" && i + 1 < suite.argc)
{
testPath = suite.argv[i + 1];
i++;
}
2016-11-23 14:14:25 +00:00
else if (string(suite.argv[i]) == "--optimize")
optimize = true;
2018-02-22 16:21:26 +00:00
else if (string(suite.argv[i]) == "--evm-version")
{
evmVersionString = i + 1 < suite.argc ? suite.argv[i + 1] : "INVALID";
2018-02-22 16:21:26 +00:00
++i;
}
2016-12-06 17:38:59 +00:00
else if (string(suite.argv[i]) == "--show-messages")
showMessages = true;
else if (string(suite.argv[i]) == "--no-ipc")
disableIPC = true;
2017-09-28 08:28:41 +00:00
else if (string(suite.argv[i]) == "--no-smt")
disableSMT = true;
2016-11-23 14:14:25 +00:00
if (!disableIPC && ipcPath.empty())
2016-08-06 09:37:52 +00:00
if (auto path = getenv("ETH_TEST_IPC"))
ipcPath = path;
if (testPath.empty())
if (auto path = getenv("ETH_TEST_PATH"))
testPath = path;
2016-08-02 16:32:03 +00:00
}
void Options::validate() const
{
solAssert(
!dev::test::Options::get().testPath.empty(),
"No test path specified. The --testpath argument is required."
);
if (!disableIPC)
solAssert(
!dev::test::Options::get().ipcPath.empty(),
"No ipc path specified. The --ipcpath argument is required, unless --no-ipc is used."
);
}
dev::solidity::EVMVersion Options::evmVersion() const
{
if (!evmVersionString.empty())
{
// We do this check as opposed to in the constructor because the BOOST_REQUIRE
// macros cannot yet be used in the constructor.
auto version = solidity::EVMVersion::fromString(evmVersionString);
BOOST_REQUIRE_MESSAGE(version, "Invalid EVM version: " + evmVersionString);
return *version;
}
else
return dev::solidity::EVMVersion();
}