2016-08-02 16:32:03 +00:00
|
|
|
/*
|
2016-11-18 23:13:20 +00:00
|
|
|
This file is part of solidity.
|
2016-08-02 16:32:03 +00:00
|
|
|
|
2016-11-18 23:13:20 +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.
|
|
|
|
|
2016-11-18 23:13:20 +00:00
|
|
|
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
|
2016-11-18 23:13:20 +00:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
2018-03-14 11:04:04 +00:00
|
|
|
#include <test/Options.h>
|
2018-02-22 16:21:26 +00:00
|
|
|
|
|
|
|
#include <libsolidity/interface/EVMVersion.h>
|
2018-03-14 11:04:04 +00:00
|
|
|
#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-10-08 08:56:16 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2018-02-22 16:21:26 +00:00
|
|
|
|
2016-08-02 16:32:03 +00:00
|
|
|
using namespace std;
|
|
|
|
using namespace dev::test;
|
2018-10-08 08:56:16 +00:00
|
|
|
namespace fs = boost::filesystem;
|
2016-08-02 16:32:03 +00:00
|
|
|
|
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++;
|
|
|
|
}
|
2018-03-06 19:45:34 +00:00
|
|
|
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")
|
|
|
|
{
|
2018-02-23 10:42:53 +00:00
|
|
|
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;
|
2017-04-26 09:53:44 +00:00
|
|
|
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
|
|
|
|
2017-04-26 09:53:44 +00:00
|
|
|
if (!disableIPC && ipcPath.empty())
|
2016-08-06 09:37:52 +00:00
|
|
|
if (auto path = getenv("ETH_TEST_IPC"))
|
|
|
|
ipcPath = path;
|
2018-03-06 19:45:34 +00:00
|
|
|
|
|
|
|
if (testPath.empty())
|
|
|
|
if (auto path = getenv("ETH_TEST_PATH"))
|
|
|
|
testPath = path;
|
2018-10-08 08:56:16 +00:00
|
|
|
|
|
|
|
if (testPath.empty())
|
|
|
|
{
|
|
|
|
auto const searchPath =
|
|
|
|
{
|
|
|
|
fs::current_path() / ".." / ".." / ".." / "test",
|
|
|
|
fs::current_path() / ".." / ".." / "test",
|
|
|
|
fs::current_path() / ".." / "test",
|
|
|
|
fs::current_path() / "test",
|
|
|
|
fs::current_path()
|
|
|
|
};
|
|
|
|
for (auto const& basePath : searchPath)
|
|
|
|
{
|
|
|
|
fs::path syntaxTestPath = basePath / "libsolidity" / "syntaxTests";
|
|
|
|
if (fs::exists(syntaxTestPath) && fs::is_directory(syntaxTestPath))
|
|
|
|
{
|
|
|
|
testPath = basePath;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-02 16:32:03 +00:00
|
|
|
}
|
2018-02-23 10:42:53 +00:00
|
|
|
|
2018-03-14 11:04:04 +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."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-02-23 10:42:53 +00:00
|
|
|
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();
|
|
|
|
}
|