Example #1
1
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;

}
Example #2
0
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;
}
Example #3
0
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;
}