mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add support for unit tests.
This commit is contained in:
40
src/main.cpp
40
src/main.cpp
@@ -7,11 +7,13 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
extern bool AddSystemEntropy();
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
using namespace boost::unit_test;
|
||||
|
||||
void startServer()
|
||||
{
|
||||
@@ -19,6 +21,14 @@ void startServer()
|
||||
theApp->run(); // Blocks till we get a stop RPC.
|
||||
}
|
||||
|
||||
|
||||
bool init_unit_test()
|
||||
{
|
||||
nothing();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void printHelp(const po::options_description& desc)
|
||||
{
|
||||
cout << "newcoin [options] <command> <params>" << endl;
|
||||
@@ -56,11 +66,14 @@ int main(int argc, char* argv[])
|
||||
po::options_description desc("Options");
|
||||
desc.add_options()
|
||||
("help,h", "Display this message.")
|
||||
("command", po::value< vector<string> >(), "Specify a comma seperated RPC command.")
|
||||
("rpc", "Perform rpc command (default).")
|
||||
("test,t", "Perform unit tests.")
|
||||
("parameters", po::value< vector<string> >(), "Specify comma seperated parameters.")
|
||||
;
|
||||
|
||||
// Interpert positional arguments as --parameters.
|
||||
po::positional_options_description p;
|
||||
p.add("command", -1);
|
||||
p.add("parameters", -1);
|
||||
|
||||
//
|
||||
// Prepare to run
|
||||
@@ -78,7 +91,7 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
po::store(po::command_line_parser(argc, argv)
|
||||
.options(desc) // Parse options.
|
||||
.positional(p) // Remainder as --command.
|
||||
.positional(p) // Remainder as --parameters.
|
||||
.run(),
|
||||
vm);
|
||||
po::notify(vm); // Invoke option notify functions.
|
||||
@@ -92,7 +105,22 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
iResult = 1;
|
||||
}
|
||||
else if (!vm.count("command"))
|
||||
else if (vm.count("test"))
|
||||
{
|
||||
std::vector<std::string> vCmd;
|
||||
int iCmd = vm.count("parameters");
|
||||
|
||||
if (iCmd)
|
||||
vCmd = vm["parameters"].as<std::vector<std::string> >();
|
||||
|
||||
char* pvCmd[iCmd];
|
||||
|
||||
for (int i=0; i != iCmd; ++i)
|
||||
pvCmd[i] = (char*) (vCmd[0].c_str());
|
||||
|
||||
iResult = unit_test_main(init_unit_test, iCmd, pvCmd);
|
||||
}
|
||||
else if (!vm.count("parameters"))
|
||||
{
|
||||
// No arguments. Run server.
|
||||
startServer();
|
||||
@@ -100,7 +128,7 @@ int main(int argc, char* argv[])
|
||||
else
|
||||
{
|
||||
// Have a RPC command.
|
||||
std::vector<std::string> vCmd = vm["command"].as<std::vector<std::string> >();
|
||||
std::vector<std::string> vCmd = vm["parameters"].as<std::vector<std::string> >();
|
||||
|
||||
iResult = commandLineRPC(vCmd);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user