mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
added generic userDefinedTest function
This commit is contained in:
parent
99c3957eca
commit
3c45877e2a
@ -305,6 +305,45 @@ std::string getTestPath()
|
|||||||
return testPath;
|
return testPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void userDefinedTest(string testTypeFlag, std::function<void(json_spirit::mValue&, bool)> doTests)
|
||||||
|
{
|
||||||
|
for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
|
||||||
|
{
|
||||||
|
string arg = boost::unit_test::framework::master_test_suite().argv[i];
|
||||||
|
if (arg == testTypeFlag)
|
||||||
|
{
|
||||||
|
if (i + 1 >= boost::unit_test::framework::master_test_suite().argc)
|
||||||
|
{
|
||||||
|
cnote << "Missing filename\nUsage: testeth " << testTypeFlag << " <filename>\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string filename = boost::unit_test::framework::master_test_suite().argv[i + 1];
|
||||||
|
int currentVerbosity = g_logVerbosity;
|
||||||
|
g_logVerbosity = 12;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
cnote << "Testing user defined test: " << filename;
|
||||||
|
json_spirit::mValue v;
|
||||||
|
string s = asString(contents(filename));
|
||||||
|
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. ");
|
||||||
|
json_spirit::read_string(s, v);
|
||||||
|
doTests(v, false);
|
||||||
|
}
|
||||||
|
catch (Exception const& _e)
|
||||||
|
{
|
||||||
|
BOOST_ERROR("Failed Test with Exception: " << diagnostic_information(_e));
|
||||||
|
}
|
||||||
|
catch (std::exception const& _e)
|
||||||
|
{
|
||||||
|
BOOST_ERROR("Failed Test with Exception: " << _e.what());
|
||||||
|
}
|
||||||
|
g_logVerbosity = currentVerbosity;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void executeTests(const string& _name, const string& _testPathAppendix, std::function<void(json_spirit::mValue&, bool)> doTests)
|
void executeTests(const string& _name, const string& _testPathAppendix, std::function<void(json_spirit::mValue&, bool)> doTests)
|
||||||
{
|
{
|
||||||
string testPath = getTestPath();
|
string testPath = getTestPath();
|
||||||
|
@ -71,6 +71,7 @@ void checkOutput(bytes const& _output, json_spirit::mObject& _o);
|
|||||||
void checkStorage(std::map<u256, u256> _expectedStore, std::map<u256, u256> _resultStore, Address _expectedAddr);
|
void checkStorage(std::map<u256, u256> _expectedStore, std::map<u256, u256> _resultStore, Address _expectedAddr);
|
||||||
void executeTests(const std::string& _name, const std::string& _testPathAppendix, std::function<void(json_spirit::mValue&, bool)> doTests);
|
void executeTests(const std::string& _name, const std::string& _testPathAppendix, std::function<void(json_spirit::mValue&, bool)> doTests);
|
||||||
std::string getTestPath();
|
std::string getTestPath();
|
||||||
|
void userDefinedTest(string testTypeFlag, std::function<void(json_spirit::mValue&, bool)> doTests);
|
||||||
|
|
||||||
template<typename mapType>
|
template<typename mapType>
|
||||||
void checkAddresses(mapType& _expectedAddrs, mapType& _resultAddrs)
|
void checkAddresses(mapType& _expectedAddrs, mapType& _resultAddrs)
|
||||||
|
36
state.cpp
36
state.cpp
@ -124,41 +124,7 @@ BOOST_AUTO_TEST_CASE(stPreCompiledContracts)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(userDefinedFileState)
|
BOOST_AUTO_TEST_CASE(userDefinedFileState)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
|
userDefinedTest("--statetest", dev::test::doStateTests);
|
||||||
{
|
|
||||||
string arg = boost::unit_test::framework::master_test_suite().argv[i];
|
|
||||||
if (arg == "--statetest")
|
|
||||||
{
|
|
||||||
if (i + 1 >= boost::unit_test::framework::master_test_suite().argc)
|
|
||||||
{
|
|
||||||
cnote << "Missing filename\nUsage: testeth --statetest <filename>\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
string filename = boost::unit_test::framework::master_test_suite().argv[i+1];
|
|
||||||
int currentVerbosity = g_logVerbosity;
|
|
||||||
g_logVerbosity = 12;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
cnote << "Testing VM..." << "user defined test";
|
|
||||||
json_spirit::mValue v;
|
|
||||||
string s = asString(contents(filename));
|
|
||||||
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. ");
|
|
||||||
json_spirit::read_string(s, v);
|
|
||||||
dev::test::doStateTests(v, false);
|
|
||||||
}
|
|
||||||
catch (Exception const& _e)
|
|
||||||
{
|
|
||||||
BOOST_ERROR("Failed state test with Exception: " << diagnostic_information(_e));
|
|
||||||
}
|
|
||||||
catch (std::exception const& _e)
|
|
||||||
{
|
|
||||||
BOOST_ERROR("Failed state test with Exception: " << _e.what());
|
|
||||||
}
|
|
||||||
g_logVerbosity = currentVerbosity;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
42
vm.cpp
42
vm.cpp
@ -441,10 +441,8 @@ BOOST_AUTO_TEST_CASE(vmRandom)
|
|||||||
{
|
{
|
||||||
cnote << "Testing ..." << path.filename();
|
cnote << "Testing ..." << path.filename();
|
||||||
json_spirit::mValue v;
|
json_spirit::mValue v;
|
||||||
string testpath(path.c_str());
|
string s = asString(dev::contents(path.string()));
|
||||||
string s = asString(dev::contents(testpath));
|
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Content of " + path.string() + " is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?");
|
||||||
|
|
||||||
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + testpath + " is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path?");
|
|
||||||
json_spirit::read_string(s, v);
|
json_spirit::read_string(s, v);
|
||||||
doVMTests(v, false);
|
doVMTests(v, false);
|
||||||
}
|
}
|
||||||
@ -461,41 +459,7 @@ BOOST_AUTO_TEST_CASE(vmRandom)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(userDefinedFileVM)
|
BOOST_AUTO_TEST_CASE(userDefinedFileVM)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
|
userDefinedTest("--vmtest", dev::test::doVMTests);
|
||||||
{
|
|
||||||
string arg = boost::unit_test::framework::master_test_suite().argv[i];
|
|
||||||
if (arg == "--vmtest")
|
|
||||||
{
|
|
||||||
if (i + 1 >= boost::unit_test::framework::master_test_suite().argc)
|
|
||||||
{
|
|
||||||
cnote << "Missing filename\nUsage: testeth --vmtest <filename>\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
string filename = boost::unit_test::framework::master_test_suite().argv[i+1];
|
|
||||||
int currentVerbosity = g_logVerbosity;
|
|
||||||
g_logVerbosity = 12;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
cnote << "Testing VM..." << "user defined test";
|
|
||||||
json_spirit::mValue v;
|
|
||||||
string s = asString(contents(filename));
|
|
||||||
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of " + filename + " is empty. ");
|
|
||||||
json_spirit::read_string(s, v);
|
|
||||||
dev::test::doVMTests(v, false);
|
|
||||||
}
|
|
||||||
catch (Exception const& _e)
|
|
||||||
{
|
|
||||||
BOOST_ERROR("Failed VM Test with Exception: " << diagnostic_information(_e));
|
|
||||||
}
|
|
||||||
catch (std::exception const& _e)
|
|
||||||
{
|
|
||||||
BOOST_ERROR("Failed VM Test with Exception: " << _e.what());
|
|
||||||
}
|
|
||||||
g_logVerbosity = currentVerbosity;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
Loading…
Reference in New Issue
Block a user