Skip to content

Commit 968ca88

Browse files
authored
Merge pull request #5872 from ethereum/semantic-tests-split
Semantic test infrastructure
2 parents 1b6d87c + dacad62 commit 968ca88

23 files changed

+594
-45
lines changed

test/ExecutionFramework.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,13 @@ string getIPCSocketPath()
4949

5050
}
5151

52-
ExecutionFramework::ExecutionFramework() :
53-
m_rpc(RPCSession::instance(getIPCSocketPath())),
52+
ExecutionFramework::ExecutionFramework():
53+
ExecutionFramework(getIPCSocketPath())
54+
{
55+
}
56+
57+
ExecutionFramework::ExecutionFramework(string const& _ipcPath):
58+
m_rpc(RPCSession::instance(_ipcPath)),
5459
m_evmVersion(dev::test::Options::get().evmVersion()),
5560
m_optimize(dev::test::Options::get().optimize),
5661
m_showMessages(dev::test::Options::get().showMessages),

test/ExecutionFramework.h

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ExecutionFramework
5353

5454
public:
5555
ExecutionFramework();
56+
explicit ExecutionFramework(std::string const& _ipcPath);
5657
virtual ~ExecutionFramework() = default;
5758

5859
virtual bytes const& compileAndRunWithoutCheck(

test/InteractiveTests.h

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <test/TestCase.h>
2121
#include <test/libsolidity/ASTJSONTest.h>
2222
#include <test/libsolidity/SyntaxTest.h>
23+
#include <test/libsolidity/SemanticTest.h>
2324
#include <test/libsolidity/SMTCheckerJSONTest.h>
2425
#include <test/libyul/YulOptimizerTest.h>
2526
#include <test/libyul/ObjectCompilerTest.h>
@@ -52,6 +53,7 @@ Testsuite const g_interactiveTestsuites[] = {
5253
{"Yul Optimizer", "libyul", "yulOptimizerTests", false, false, &yul::test::YulOptimizerTest::create},
5354
{"Yul Object Compiler", "libyul", "objectCompiler", false, false, &yul::test::ObjectCompilerTest::create},
5455
{"Syntax", "libsolidity", "syntaxTests", false, false, &SyntaxTest::create},
56+
{"Semantic", "libsolidity", "semanticTests", false, true, &SemanticTest::create},
5557
{"JSON AST", "libsolidity", "ASTJSON", false, false, &ASTJSONTest::create},
5658
{"SMT Checker", "libsolidity", "smtCheckerTests", true, false, &SyntaxTest::create},
5759
{"SMT Checker JSON", "libsolidity", "smtCheckerTestsJSON", true, false, &SMTCheckerTest::create}

test/RPCSession.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,16 @@ string IPCSocket::sendRequest(string const& _req)
139139

140140
RPCSession& RPCSession::instance(string const& _path)
141141
{
142-
static RPCSession session(_path);
143-
BOOST_REQUIRE_EQUAL(session.m_ipcSocket.path(), _path);
144-
return session;
142+
try
143+
{
144+
static RPCSession session(_path);
145+
BOOST_REQUIRE_EQUAL(session.m_ipcSocket.path(), _path);
146+
return session;
147+
}
148+
catch (std::exception const&)
149+
{
150+
BOOST_THROW_EXCEPTION(std::runtime_error("Error creating RPC session for socket: " + _path));
151+
}
145152
}
146153

147154
string RPCSession::eth_getCode(string const& _address, string const& _blockNumber)

test/TestCase.h

+15-1
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,25 @@ namespace solidity
3030
namespace test
3131
{
3232

33+
#define soltestAssert(CONDITION, DESCRIPTION) \
34+
do \
35+
{ \
36+
if (!(CONDITION)) \
37+
BOOST_THROW_EXCEPTION(runtime_error(DESCRIPTION)); \
38+
} \
39+
while (false)
40+
3341
/** Common superclass of SyntaxTest and SemanticsTest. */
3442
class TestCase
3543
{
3644
public:
37-
using TestCaseCreator = std::unique_ptr<TestCase>(*)(std::string const&);
45+
struct Config
46+
{
47+
std::string filename;
48+
std::string ipcPath;
49+
};
50+
51+
using TestCaseCreator = std::unique_ptr<TestCase>(*)(Config const&);
3852

3953
virtual ~TestCase() = default;
4054

test/boostTest.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ int registerTests(
7474
boost::unit_test::test_suite& _suite,
7575
boost::filesystem::path const& _basepath,
7676
boost::filesystem::path const& _path,
77+
std::string const& _ipcPath,
7778
TestCase::TestCaseCreator _testCaseCreator
7879
)
7980
{
8081
int numTestsAdded = 0;
8182
fs::path fullpath = _basepath / _path;
83+
TestCase::Config config{fullpath.string(), _ipcPath};
8284
if (fs::is_directory(fullpath))
8385
{
8486
test_suite* sub_suite = BOOST_TEST_SUITE(_path.filename().string());
@@ -87,7 +89,7 @@ int registerTests(
8789
fs::directory_iterator()
8890
))
8991
if (fs::is_directory(entry.path()) || TestCase::isTestFilename(entry.path().filename()))
90-
numTestsAdded += registerTests(*sub_suite, _basepath, _path / entry.path().filename(), _testCaseCreator);
92+
numTestsAdded += registerTests(*sub_suite, _basepath, _path / entry.path().filename(), _ipcPath, _testCaseCreator);
9193
_suite.add(sub_suite);
9294
}
9395
else
@@ -96,13 +98,13 @@ int registerTests(
9698

9799
filenames.emplace_back(new string(_path.string()));
98100
_suite.add(make_test_case(
99-
[fullpath, _testCaseCreator]
101+
[config, _testCaseCreator]
100102
{
101103
BOOST_REQUIRE_NO_THROW({
102104
try
103105
{
104106
stringstream errorStream;
105-
if (!_testCaseCreator(fullpath.string())->run(errorStream))
107+
if (!_testCaseCreator(config)->run(errorStream))
106108
BOOST_ERROR("Test expectation mismatch.\n" + errorStream.str());
107109
}
108110
catch (boost::exception const& _e)
@@ -142,6 +144,7 @@ test_suite* init_unit_test_suite( int /*argc*/, char* /*argv*/[] )
142144
master,
143145
options.testPath / ts.path,
144146
ts.subpath,
147+
options.ipcPath,
145148
ts.testCaseCreator
146149
) > 0, std::string("no ") + ts.title + " tests found");
147150
}

test/libsolidity/ASTJSONTest.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ namespace test
3535
class ASTJSONTest: public TestCase
3636
{
3737
public:
38-
static std::unique_ptr<TestCase> create(std::string const& _filename)
39-
{ return std::unique_ptr<TestCase>(new ASTJSONTest(_filename)); }
38+
static std::unique_ptr<TestCase> create(Config const& _config)
39+
{ return std::unique_ptr<TestCase>(new ASTJSONTest(_config.filename)); }
4040
ASTJSONTest(std::string const& _filename);
4141

4242
bool run(std::ostream& _stream, std::string const& _linePrefix = "", bool const _formatted = false) override;

test/libsolidity/SMTCheckerJSONTest.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ namespace test
3333
class SMTCheckerTest: public SyntaxTest
3434
{
3535
public:
36-
static std::unique_ptr<TestCase> create(std::string const& _filename)
36+
static std::unique_ptr<TestCase> create(Config const& _config)
3737
{
38-
return std::unique_ptr<TestCase>(new SMTCheckerTest(_filename));
38+
return std::unique_ptr<TestCase>(new SMTCheckerTest(_config.filename));
3939
}
4040
SMTCheckerTest(std::string const& _filename);
4141

0 commit comments

Comments
 (0)