int main (int argc, char* const argv[]) { Catch::Session session; auto & cli = session.cli(); cli["-p"]["--plugins"] .describe("path to mapnik plugins") .bind(&set_plugin_path, "plugins"); cli["-C"]["--working-directory"] .describe("change working directory") .bind(&set_working_dir, "working directory"); int result = session.applyCommandLine(argc, argv); if (!plugin_path.empty()) { if (!mapnik::util::exists(plugin_path)) { std::clog << "Could not find " << plugin_path << "\n"; return -1; } mapnik::datasource_cache::instance().register_datasources(plugin_path); } else { mapnik::datasource_cache::instance().register_datasources("plugins/input/"); } if (!working_dir.empty()) { if (!mapnik::util::exists(working_dir)) { std::clog << "Could not find " << working_dir << "\n"; return -1; } boost::filesystem::current_path(working_dir); } if (result == 0) { result = session.run(); } testing::run_cleanup(); return result; }
extern "C" int run_c_components_test_failure() { Catch::Session session; Catch::ConfigData c; c.testsOrTags.push_back("[.]"); session.useConfigData(c); return session.run(); }
int main(int argc, char* const argv[]) { Catch::Session session; int returnCode = session.applyCommandLine(argc, argv); if (returnCode != 0) return returnCode; int runCode = session.run(); cin.get(); return runCode; }
int main( int argc, const char *argv[] ) { Catch::Session session; std::vector<const char *> arg_vec( argv, argv + argc ); std::vector<mod_id> mods = extract_mod_selection( arg_vec ); if( std::find( mods.begin(), mods.end(), mod_id( "dda" ) ) == mods.end() ) { mods.insert( mods.begin(), mod_id( "dda" ) ); // @todo move unit test items to core } option_overrides_t option_overrides_for_test_suite = extract_option_overrides( arg_vec ); bool dont_save = check_remove_flags( arg_vec, { "-D", "--drop-world" } ); // Note: this must not be invoked before all DDA-specific flags are stripped from arg_vec! int result = session.applyCommandLine( arg_vec.size(), &arg_vec[0] ); if( result != 0 || session.configData().showHelp ) { printf( "CataclysmDDA specific options:\n" ); printf( " --mods=<mod1,mod2,...> Loads the list of mods before executing tests.\n" ); printf( " -D, --drop-world Don't save the world on test failure.\n" ); printf( " --option_overrides=n:v[,...] Name-value pairs of game options for tests.\n" ); printf( " (overrides config/options.json values)\n" ); return result; } test_mode = true; setupDebug( DebugOutput::std_err ); try { // TODO: Only init game if we're running tests that need it. init_global_game_state( mods, option_overrides_for_test_suite ); } catch( const std::exception &err ) { fprintf( stderr, "Terminated: %s\n", err.what() ); fprintf( stderr, "Make sure that you're in the correct working directory and your data isn't corrupted.\n" ); return EXIT_FAILURE; } const auto start = std::chrono::system_clock::now(); std::time_t start_time = std::chrono::system_clock::to_time_t( start ); // Leading newline in case there were debug messages during // initialization. printf( "\nStarting the actual test at %s", std::ctime( &start_time ) ); result = session.run(); const auto end = std::chrono::system_clock::now(); std::time_t end_time = std::chrono::system_clock::to_time_t( end ); auto world_name = world_generator->active_world->world_name; if( result == 0 || dont_save ) { world_generator->delete_world( world_name, true ); } else { printf( "Test world \"%s\" left for inspection.\n", world_name.c_str() ); } std::chrono::duration<double> elapsed_seconds = end - start; printf( "Ended test at %sThe test took %.3f seconds\n", std::ctime( &end_time ), elapsed_seconds.count() ); return result; }
int main(int argc, char* argv[]) { namespace po = boost::program_options; struct gm_auth_token { const char* m_name; const char* m_description; const char* m_environment; std::string* m_pVariable; bool m_isRequired; }; static const std::vector<gm_auth_token> gm_auto_tokens = { {"username", "Google Music username", "GM_U", &TestFixture::gm_user, true}, {"password", "Google Music password", "GM_P", &TestFixture::gm_pass, true}, {"refresh_token", "Google Music refresh token", "GM_R", &TestFixture::gm_refresh, false}, {"android_id", "Google Music Android ID", "GM_AA_ID", &TestFixture::gm_android_id, false} }; po::options_description desc("Other options"); desc.add_options() ("help,h", "produce help message") ("wait", "Wait for keystroke before starting") ("oauth", "Perform OAuth") ; for (auto& auth_token : gm_auto_tokens) { desc.add_options() (auth_token.m_name, po::value(auth_token.m_pVariable), auth_token.m_description); } po::variables_map vm; Catch::Session session; auto usage = [&]() { session.showHelp(argv[0]); Catch::cout() << desc << '\n'; }; auto parsedOptions = [&]() { try { auto parsedOptions = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); po::store(parsedOptions, vm); po::notify(vm); return parsedOptions; } catch (std::exception& e) { std::cerr << e.what() << '\n'; std::cerr << "run " << argv[0] << "-h" << " for more info.\n"; exit(1); } }(); if (vm.count("help")) { usage(); return 0; } if (vm.count("oauth")) { namespace gm = GMusicApi; gm::Module m; gm::Musicmanager mm(m); mm.perform_oauth(gm::Clients().OAUTH_FILEPATH(), true); return 0; } for (auto& auth_token : gm_auto_tokens) { if (auth_token.m_pVariable->empty()) { auth_token.m_pVariable->assign(getEnv(auth_token.m_environment)); if (auth_token.m_isRequired && auth_token.m_pVariable->empty()) { std::cerr << "Auth token " << auth_token.m_name << " should be given either on the command line, " << " or set on the environment variable " << auth_token.m_environment << ".\n"; std::cerr << "run " << argv[0] << "-h" << " for more info.\n"; return 1; } } } if (vm.count("wait")) { std::cout << "Press enter to start testing.\n"; std::cin.get(); } auto unusedOptions = po::collect_unrecognized(parsedOptions.options, po::include_positional); // convert to const char* std::vector<const char*> unusedOptionsToCatch = { argv[0] }; std::transform(unusedOptions.begin(), unusedOptions.end(), std::back_inserter(unusedOptionsToCatch), [](const std::string& str) { return str.c_str(); }); return session.run(static_cast<int>(unusedOptionsToCatch.size()), unusedOptionsToCatch.data()); }