mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
use boost::program_options for test runner
This commit is contained in:
parent
5919abfdc8
commit
8f1e6bb3bf
@ -19,6 +19,8 @@
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
|
||||
#include "../db/instance.h"
|
||||
#include "../util/file_allocator.h"
|
||||
|
||||
@ -29,62 +31,71 @@
|
||||
#include "dbtests.h"
|
||||
|
||||
using namespace std;
|
||||
namespace po = boost::program_options;
|
||||
|
||||
namespace mongo {
|
||||
extern string dbpath;
|
||||
}
|
||||
|
||||
string dbpathSpec = "/tmp/unittest/";
|
||||
|
||||
void usage() {
|
||||
string instructions =
|
||||
"dbtests usage:\n"
|
||||
" -help show this message\n"
|
||||
" -dbpath <path> configure db data path for this test run\n"
|
||||
" (default is /tmp/unittest/)\n"
|
||||
" -debug run tests with verbose output\n"
|
||||
" -list list available test suites\n"
|
||||
" -seed <seed> random number seed\n"
|
||||
" <suite> run the specified test suite only";
|
||||
out() << instructions << endl;
|
||||
void show_help_text(const char* name, po::options_description options) {
|
||||
cout << "usage: " << name << " [options] [suite]..." << endl
|
||||
<< options << "suite: run the specified test suite(s) only" << endl;
|
||||
}
|
||||
|
||||
int main( int argc, char** argv ) {
|
||||
|
||||
unsigned long long seed = time( 0 );
|
||||
|
||||
int offset = 0;
|
||||
for ( int i = 1; i < argc; ++i ) {
|
||||
if ( argv[ i ] == string( "-dbpath" ) ) {
|
||||
if ( i == argc - 1 ) {
|
||||
usage();
|
||||
dbexit( EXIT_BADOPTIONS );
|
||||
}
|
||||
dbpathSpec = argv[ ++i ];
|
||||
offset += 2;
|
||||
} else if ( argv[ i ] == string( "-seed" ) ) {
|
||||
if ( i == argc - 1 ) {
|
||||
usage();
|
||||
dbexit( EXIT_BADOPTIONS );
|
||||
}
|
||||
// Don't bother checking for conversion error
|
||||
seed = strtoll( argv[ ++i ], 0, 10 );
|
||||
offset += 2;
|
||||
} else if ( argv[ i ] == string( "-help" ) ) {
|
||||
usage();
|
||||
dbexit( EXIT_CLEAN );
|
||||
} else if ( offset ) {
|
||||
argv[ i - offset ] = argv[ i ];
|
||||
}
|
||||
string dbpathSpec;
|
||||
|
||||
po::options_description shell_options("options");
|
||||
po::options_description hidden_options("Hidden options");
|
||||
po::options_description cmdline_options("Command line options");
|
||||
po::positional_options_description positional_options;
|
||||
|
||||
shell_options.add_options()
|
||||
("help,h", "show this usage information")
|
||||
("dbpath", po::value<string>(&dbpathSpec)->default_value("/tmp/unittest/"),
|
||||
"db data path for this test run")
|
||||
("debug", "run tests with verbose output")
|
||||
("list,l", "list available test suites")
|
||||
("seed", po::value<unsigned long long>(&seed), "random number seed")
|
||||
;
|
||||
|
||||
hidden_options.add_options()
|
||||
("suites", po::value< vector<string> >(), "test suites to run")
|
||||
;
|
||||
|
||||
positional_options.add("suites", -1);
|
||||
|
||||
cmdline_options.add(shell_options).add(hidden_options);
|
||||
|
||||
po::variables_map params;
|
||||
int command_line_style = (((po::command_line_style::unix_style ^
|
||||
po::command_line_style::allow_guessing) |
|
||||
po::command_line_style::allow_long_disguise) ^
|
||||
po::command_line_style::allow_sticky);
|
||||
|
||||
try {
|
||||
po::store(po::command_line_parser(argc, argv).options(cmdline_options).
|
||||
positional(positional_options).
|
||||
style(command_line_style).run(), params);
|
||||
po::notify(params);
|
||||
} catch (po::error &e) {
|
||||
cout << "ERROR: " << e.what() << endl << endl;
|
||||
show_help_text(argv[0], shell_options);
|
||||
return EXIT_BADOPTIONS;
|
||||
}
|
||||
|
||||
if (params.count("help")) {
|
||||
show_help_text(argv[0], shell_options);
|
||||
return EXIT_CLEAN;
|
||||
}
|
||||
argc -= offset;
|
||||
|
||||
if ( dbpathSpec[ dbpathSpec.length() - 1 ] != '/' )
|
||||
dbpathSpec += "/";
|
||||
dbpath = dbpathSpec.c_str();
|
||||
|
||||
acquirePathLock();
|
||||
|
||||
|
||||
srand( seed );
|
||||
printGitVersion();
|
||||
printSysInfo();
|
||||
@ -92,13 +103,18 @@ int main( int argc, char** argv ) {
|
||||
|
||||
theFileAllocator().start();
|
||||
|
||||
|
||||
vector<string> suites;
|
||||
if (params.count("suites")) {
|
||||
suites = params["suites"].as< vector<string> >();
|
||||
}
|
||||
|
||||
int ret = mongo::regression::Suite::run(params.count("debug"),
|
||||
params.count("list"),
|
||||
suites);
|
||||
|
||||
int ret = mongo::regression::Suite::run( argc, argv );
|
||||
|
||||
#if !defined(_WIN32) && !defined(__sunos__)
|
||||
flock( lockFile, LOCK_UN );
|
||||
#endif
|
||||
#endif
|
||||
|
||||
dbexit( (ExitCode)ret ); // so everything shuts down cleanly
|
||||
return ret;
|
||||
|
@ -90,31 +90,24 @@ namespace mongo {
|
||||
return r;
|
||||
}
|
||||
|
||||
int Suite::run( int argc , char ** argv ){
|
||||
list<string> torun;
|
||||
|
||||
for ( int i=1; i<argc; i++ ){
|
||||
|
||||
string s = argv[i];
|
||||
|
||||
if ( s == "-list" ){
|
||||
for ( map<string,Suite*>::iterator i=_suites->begin() ; i!=_suites->end(); i++ )
|
||||
cout << i->first << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( s == "-debug" ){
|
||||
logLevel = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
torun.push_back( s );
|
||||
if ( _suites->find( s ) == _suites->end() ){
|
||||
cout << "invalid test [" << s << "] use -list to see valid names" << endl;
|
||||
int Suite::run( bool debug , bool list_suites, vector<string> suites ){
|
||||
if ( list_suites ) {
|
||||
for ( map<string,Suite*>::iterator i = _suites->begin() ; i != _suites->end(); i++ )
|
||||
cout << i->first << endl;
|
||||
return 0;
|
||||
}
|
||||
if ( debug ) {
|
||||
logLevel = 1;
|
||||
}
|
||||
for ( unsigned int i = 0; i < suites.size(); i++ ) {
|
||||
if ( _suites->find( suites[i] ) == _suites->end() ) {
|
||||
cout << "invalid test [" << suites[i] << "], use --list to see valid names" << endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
list<string> torun(suites.begin(), suites.end());
|
||||
|
||||
if ( torun.size() == 0 )
|
||||
for ( map<string,Suite*>::iterator i=_suites->begin() ; i!=_suites->end(); i++ )
|
||||
torun.push_back( i->first );
|
||||
|
@ -114,6 +114,7 @@ namespace mongo {
|
||||
|
||||
Result * run();
|
||||
|
||||
static int run( bool debug , bool list, vector<string> suites );
|
||||
static int run( int argc , char ** argv );
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user