Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Simplify testeth command line options for running test from file
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Nov 5, 2019
1 parent 1bbe6d1 commit 6a957b5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 42 deletions.
3 changes: 2 additions & 1 deletion test/tools/jsontests/BlockChainTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ json_spirit::mValue doBCTest(
Options const& opt = test::Options::get();

// Select BC Test by singleTest
if (opt.singleTest && !boost::algorithm::starts_with(testname, opt.singleTestName))
if (!opt.singleTestName.empty() &&
!boost::algorithm::starts_with(testname, opt.singleTestName))
continue;

// Select BC Test by singleNet
Expand Down
47 changes: 17 additions & 30 deletions test/tools/libtesteth/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ void printHelp()
cout << setw(35) << "-g <index>" << setw(25) << "Set the transaction gas array index when running GeneralStateTests\n";
cout << setw(35) << "-v <index>" << setw(25) << "Set the transaction value array index when running GeneralStateTests\n";
cout << setw(35) << "--singletest <TestName>" << "Run on a single test\n";
cout << setw(35) << "--singletest <TestFile>" << "Run tests from file. Require -t <TestSuite>\n";
cout << setw(35) << "--singletest <TestFile> <TestName>" << "Run on a single test from file. Require -t <TestSuite>\n";
cout << setw(35) << "--singlenet <networkId>" << setw(25) << "Run tests for a specific network (Frontier|Homestead|EIP150|EIP158|Byzantium|Constantinople|ConstantinopleFix)\n";
cout << setw(35) << "--testfile <TestFile>"
<< "Run tests from a file. Requires -t <TestSuite>\n";
cout << setw(35) << "--testfile <TestFile> --singletest <TestName>"
<< "Run on a single test from a file. Requires -t <TestSuite>\n";
cout << setw(35) << "--verbosity <level>" << setw(25) << "Set logs verbosity. 0 - silent, 1 - only errors, 2 - informative, >2 - detailed\n";
cout << setw(35) << "--vm <name|path> (=legacy)" << setw(25) << "Set VM type for VMTests suite. Available options are: interpreter, legacy.\n";
cout << setw(35) << "--evmc <option>=<value>" << "EVMC option\n";
Expand Down Expand Up @@ -199,39 +201,24 @@ Options::Options(int argc, const char** argv)
else if (arg == "--singletest")
{
throwIfNoArgumentFollows();
auto name1 = std::string{argv[++i]};
if (i + 1 < argc) // two params
{
auto name2 = std::string{argv[++i]};
if (name2[0] == '-') // not param, another option
{
singleTest = true;
singleTestName = std::move(name1);
i--;
}
else
{
singleTestFile = std::move(name1);
singleTestName = std::move(name2);
}
}
else
{
if (boost::filesystem::exists(name1))
singleTestFile = std::move(name1);
else
{
singleTest = true;
singleTestName = std::move(name1);
}
}
singleTestName = std::string{argv[++i]};
}
else if (arg == "--singlenet")
{
throwIfNoArgumentFollows();
singleTestNet = std::string{argv[++i]};
ImportTest::checkAllowedNetwork(singleTestNet);
}
else if (arg == "--testfile")
{
throwIfNoArgumentFollows();
singleTestFile = std::string{argv[++i]};
if (!boost::filesystem::exists(singleTestFile))
{
cerr << "Test file not found: " << singleTestFile << "\n";
exit(1);
}
}
else if (arg == "--fullstate")
fullstate = true;
else if (arg == "--verbosity")
Expand Down Expand Up @@ -338,8 +325,8 @@ Options::Options(int argc, const char** argv)
//check restricted options
if (createRandomTest)
{
if (trValueIndex >= 0 || trGasIndex >= 0 || trDataIndex >= 0 || singleTest || all ||
stats || filltests || fillchain)
if (trValueIndex >= 0 || trGasIndex >= 0 || trDataIndex >= 0 || !singleTestName.empty() ||
all || stats || filltests || fillchain)
{
cerr << "--createRandomTest cannot be used with any of the options: " <<
"trValueIndex, trGasIndex, trDataIndex, singleTest, all, " <<
Expand Down
3 changes: 1 addition & 2 deletions test/tools/libtesteth/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class Options

/// Test selection
/// @{
bool singleTest = false;
boost::optional<std::string> singleTestFile;
std::string singleTestFile;
std::string singleTestName;
std::string singleTestNet;
int trDataIndex; ///< GeneralState data
Expand Down
7 changes: 4 additions & 3 deletions test/tools/libtesteth/TestOutputHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ void TestOutputHelper::initTest(size_t _maxTests)

bool TestOutputHelper::checkTest(std::string const& _testName)
{
if (test::Options::get().singleTest && test::Options::get().singleTestName != _testName)
return false;
if (!test::Options::get().singleTestName.empty() &&
test::Options::get().singleTestName != _testName)
return false;

m_currentTestName = _testName;
m_currentTestName = _testName;
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions test/tools/libtesteth/TestSuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ void TestSuite::executeTest(string const& _testFolder, fs::path const& _testFile
}
else
{
if (!Options::get().singleTest)
cnote << "Populating tests...";
if (Options::get().singleTestName.empty())
cnote << "Populating tests...";

TestFileData fillerData = readTestFile(_testFileName);
removeComments(fillerData.data);
Expand Down
8 changes: 4 additions & 4 deletions test/tools/libtesteth/boostTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ void customTestSuite()
}

// if running a singletest
if (opt.singleTestFile.is_initialized())
if (!opt.singleTestFile.empty())
{
boost::filesystem::path file(opt.singleTestFile.get());
boost::filesystem::path const file(opt.singleTestFile);
if (opt.rCurrentTestSuite.find("GeneralStateTests") != std::string::npos)
{
dev::test::StateTestSuite suite;
Expand Down Expand Up @@ -93,7 +93,7 @@ int main(int argc, const char* argv[])
}

dev::test::Options const& opt = dev::test::Options::get();
if (opt.createRandomTest || opt.singleTestFile.is_initialized())
if (opt.createRandomTest || !opt.singleTestFile.empty())
{
bool testSuiteFound = false;
for (int i = 0; i < argc; i++)
Expand All @@ -114,7 +114,7 @@ int main(int argc, const char* argv[])
std::cerr << "createRandomTest requires a test suite to be set -t <TestSuite>\n";
return -1;
}
if (!testSuiteFound && opt.singleTestFile.is_initialized())
if (!testSuiteFound && !opt.singleTestFile.empty())
{
std::cerr
<< "singletest <file> <testname> requires a test suite to be set -t <TestSuite>\n";
Expand Down

0 comments on commit 6a957b5

Please sign in to comment.