Skip to content

Commit

Permalink
Only init game if we're running tests that need it (#70901)
Browse files Browse the repository at this point in the history
* Only init game if no select tests have [nogame] tag

* Tests tagged [utility] never require a game object

* Add elapsed time for `[nogame]` too

* Obey astyle

* Obey clang-tidy

* Optimize for cases of invalid tags leading quitting

* Tag more tests with `[nogame]`

* Fix logic to derive `needs_game` from `[nogame]`

#70901 (comment)

* Do not access `world_generator` when no game was initialized

#70901 (comment)

* Obey astyle
  • Loading branch information
alef authored Jan 14, 2024
1 parent 2dea0a7 commit 46f8117
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 60 deletions.
4 changes: 2 additions & 2 deletions tests/algo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static void check_cycle_finding( std::unordered_map<int, std::vector<int>> &g,
CHECK( loops == expected );
}

TEST_CASE( "find_cycles_small" )
TEST_CASE( "find_cycles_small", "[nogame]" )
{
std::unordered_map<int, std::vector<int>> g = {
{ 0, { 1 } },
Expand All @@ -34,7 +34,7 @@ TEST_CASE( "find_cycles_small" )
};
check_cycle_finding( g, expected );
}
TEST_CASE( "find_cycles" )
TEST_CASE( "find_cycles", "[nogame]" )
{
std::unordered_map<int, std::vector<int>> g = {
{ 0, { 0, 1 } },
Expand Down
4 changes: 2 additions & 2 deletions tests/calendar_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "calendar.h"
#include "cata_catch.h"

TEST_CASE( "time_duration_to_string", "[calendar]" )
TEST_CASE( "time_duration_to_string", "[calendar][nogame]" )
{
calendar::set_season_length( 91 );
CHECK( to_string( 10_seconds ) == "10 seconds" );
Expand All @@ -27,7 +27,7 @@ TEST_CASE( "time_duration_to_string", "[calendar]" )
CHECK( to_string( 3650_days ) == "10 years and 1 week" );
}

TEST_CASE( "time_duration_to_string_eternal_season", "[calendar]" )
TEST_CASE( "time_duration_to_string_eternal_season", "[calendar][nogame]" )
{
calendar::set_season_length( 91 );
calendar::set_eternal_season( true );
Expand Down
2 changes: 1 addition & 1 deletion tests/cartesian_product_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "cartesian_product.h"

TEST_CASE( "cartesian_product" )
TEST_CASE( "cartesian_product", "[nogame]" )
{
std::vector<int> empty;
std::vector<int> singleton = { 0 };
Expand Down
24 changes: 12 additions & 12 deletions tests/cata_utility_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool test_string_ends_with( const std::string &s1, const char( &s2 )[N] )
return r1;
}

TEST_CASE( "string_starts_with", "[utility]" )
TEST_CASE( "string_starts_with", "[utility][nogame]" )
{
CHECK( test_string_starts_with( "", "" ) );
CHECK( test_string_starts_with( "a", "" ) );
Expand All @@ -48,7 +48,7 @@ TEST_CASE( "string_starts_with", "[utility]" )
CHECK_FALSE( test_string_starts_with( "a", "ab" ) );
}

TEST_CASE( "string_ends_with", "[utility]" )
TEST_CASE( "string_ends_with", "[utility][nogame]" )
{
CHECK( test_string_ends_with( "", "" ) );
CHECK( test_string_ends_with( "a", "" ) );
Expand All @@ -58,7 +58,7 @@ TEST_CASE( "string_ends_with", "[utility]" )
CHECK_FALSE( test_string_ends_with( "a", "ba" ) );
}

TEST_CASE( "string_ends_with_benchmark", "[.][utility][benchmark]" )
TEST_CASE( "string_ends_with_benchmark", "[.][utility][benchmark][nogame]" )
{
const std::string s1 = "long_string_with_suffix";

Expand All @@ -70,7 +70,7 @@ TEST_CASE( "string_ends_with_benchmark", "[.][utility][benchmark]" )
};
}

TEST_CASE( "string_ends_with_season_suffix", "[utility]" )
TEST_CASE( "string_ends_with_season_suffix", "[utility][nogame]" )
{
constexpr size_t suffix_len = 15;
// NOLINTNEXTLINE(cata-use-mdarray,modernize-avoid-c-arrays)
Expand All @@ -84,7 +84,7 @@ TEST_CASE( "string_ends_with_season_suffix", "[utility]" )
CHECK_FALSE( test_string_ends_with( "t_tile_season_spring1", season_suffix[0] ) );
}

TEST_CASE( "divide_round_up", "[utility]" )
TEST_CASE( "divide_round_up", "[utility][nogame]" )
{
CHECK( divide_round_up( 0, 5 ) == 0 );
CHECK( divide_round_up( 1, 5 ) == 1 );
Expand All @@ -93,7 +93,7 @@ TEST_CASE( "divide_round_up", "[utility]" )
CHECK( divide_round_up( 6, 5 ) == 2 );
}

TEST_CASE( "divide_round_up_units", "[utility]" )
TEST_CASE( "divide_round_up_units", "[utility][nogame]" )
{
CHECK( divide_round_up( 0_ml, 5_ml ) == 0 );
CHECK( divide_round_up( 1_ml, 5_ml ) == 1 );
Expand All @@ -102,7 +102,7 @@ TEST_CASE( "divide_round_up_units", "[utility]" )
CHECK( divide_round_up( 6_ml, 5_ml ) == 2 );
}

TEST_CASE( "erase_if", "[utility]" )
TEST_CASE( "erase_if", "[utility][nogame]" )
{
std::set<int> s{1, 2, 3, 4, 5};
SECTION( "erase none" ) {
Expand Down Expand Up @@ -147,7 +147,7 @@ TEST_CASE( "erase_if", "[utility]" )
}
}

TEST_CASE( "equal_ignoring_elements", "[utility]" )
TEST_CASE( "equal_ignoring_elements", "[utility][nogame]" )
{
SECTION( "empty sets" ) {
CHECK( equal_ignoring_elements<std::set<int>>(
Expand Down Expand Up @@ -235,7 +235,7 @@ TEST_CASE( "equal_ignoring_elements", "[utility]" )
}
}

TEST_CASE( "map_without_keys", "[map][filter]" )
TEST_CASE( "map_without_keys", "[map][filter][nogame]" )
{
std::map<std::string, std::string> map_empty;
std::map<std::string, std::string> map_name_a = {
Expand Down Expand Up @@ -278,7 +278,7 @@ TEST_CASE( "map_without_keys", "[map][filter]" )
CHECK_FALSE( map_without_keys( map_dirt_2, dirt ) == map_without_keys( map_name_a_dirt_2, dirt ) );
}

TEST_CASE( "map_equal_ignoring_keys", "[map][filter]" )
TEST_CASE( "map_equal_ignoring_keys", "[map][filter][nogame]" )
{
std::map<std::string, std::string> map_empty;
std::map<std::string, std::string> map_name_a = {
Expand Down Expand Up @@ -348,7 +348,7 @@ TEST_CASE( "map_equal_ignoring_keys", "[map][filter]" )
CHECK_FALSE( map_equal_ignoring_keys( lagers_are_best, beer_and_stone, rock_and_stone ) );
}

TEST_CASE( "check_debug_menu_string_methods", "[debug_menu]" )
TEST_CASE( "check_debug_menu_string_methods", "[debug_menu][nogame]" )
{
std::map<std::string, std::vector<std::string>> split_expect = {
{ "", { } },
Expand Down Expand Up @@ -380,7 +380,7 @@ TEST_CASE( "check_debug_menu_string_methods", "[debug_menu]" )
}
}

TEST_CASE( "lcmatch", "[utility]" )
TEST_CASE( "lcmatch", "[utility][nogame]" )
{
CHECK( lcmatch( "bo", "bo" ) == true );
CHECK( lcmatch( "Bo", "bo" ) == true );
Expand Down
16 changes: 8 additions & 8 deletions tests/cata_variant_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static const mtype_id This_is_not_a_valid_id( "This is not a valid id" );
static const mtype_id mon_zombie( "mon_zombie" );
static const mtype_id zombie( "zombie" );

TEST_CASE( "variant_construction", "[variant]" )
TEST_CASE( "variant_construction", "[variant][nogame]" )
{
SECTION( "itype_id" ) {
cata_variant v = cata_variant::make<cata_variant_type::itype_id>( itype_anvil );
Expand Down Expand Up @@ -62,7 +62,7 @@ TEST_CASE( "variant_construction", "[variant]" )
}
}

TEST_CASE( "variant_copy_move", "[variant]" )
TEST_CASE( "variant_copy_move", "[variant][nogame]" )
{
cata_variant v = cata_variant( zombie );
cata_variant v2 = v;
Expand All @@ -75,7 +75,7 @@ TEST_CASE( "variant_copy_move", "[variant]" )
CHECK( v5.get<mtype_id>() == zombie );
}

TEST_CASE( "variant_type_name_round_trip", "[variant]" )
TEST_CASE( "variant_type_name_round_trip", "[variant][nogame]" )
{
int num_types = static_cast<int>( cata_variant_type::num_types );
for( int i = 0; i < num_types; ++i ) {
Expand All @@ -85,14 +85,14 @@ TEST_CASE( "variant_type_name_round_trip", "[variant]" )
}
}

TEST_CASE( "variant_default_constructor", "[variant]" )
TEST_CASE( "variant_default_constructor", "[variant][nogame]" )
{
cata_variant v;
CHECK( v.type() == cata_variant_type::void_ );
CHECK( v.get_string().empty() );
}

TEST_CASE( "variant_serialization", "[variant]" )
TEST_CASE( "variant_serialization", "[variant][nogame]" )
{
cata_variant v = cata_variant( zombie );
std::ostringstream os;
Expand All @@ -101,21 +101,21 @@ TEST_CASE( "variant_serialization", "[variant]" )
CHECK( os.str() == R"(["mtype_id","zombie"])" );
}

TEST_CASE( "variant_deserialization", "[variant]" )
TEST_CASE( "variant_deserialization", "[variant][nogame]" )
{
JsonValue jsin = json_loader::from_string( R"(["mtype_id","zombie"])" );
cata_variant v;
v.deserialize( jsin );
CHECK( v == cata_variant( zombie ) );
}

TEST_CASE( "variant_from_string" )
TEST_CASE( "variant_from_string", "[nogame]" )
{
cata_variant v = cata_variant::from_string( cata_variant_type::mtype_id, "mon_zombie" );
CHECK( v == cata_variant( mon_zombie ) );
}

TEST_CASE( "variant_type_for", "[variant]" )
TEST_CASE( "variant_type_for", "[variant][nogame]" )
{
CHECK( cata_variant_type_for<bool>() == cata_variant_type::bool_ );
CHECK( cata_variant_type_for<int>() == cata_variant_type::int_ );
Expand Down
18 changes: 9 additions & 9 deletions tests/catacharset_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "translations.h"
#include "unicode.h"

TEST_CASE( "utf8_width", "[catacharset]" )
TEST_CASE( "utf8_width", "[catacharset][nogame]" )
{
CHECK( utf8_width( "Hello, world!", false ) == 13 );
CHECK( utf8_width( "你好,世界!", false ) == 12 );
Expand All @@ -25,7 +25,7 @@ TEST_CASE( "utf8_width", "[catacharset]" )
CHECK( utf8_width( "à̸̠你⃫", false ) == 3 );
}

TEST_CASE( "utf8_display_split", "[catacharset]" )
TEST_CASE( "utf8_display_split", "[catacharset][nogame]" )
{
CHECK( utf8_display_split( "你好" ) == std::vector<std::string> { "", "" } );
CHECK( utf8_display_split( "à" ) == std::vector<std::string> { "à" } );
Expand All @@ -34,13 +34,13 @@ TEST_CASE( "utf8_display_split", "[catacharset]" )
CHECK( utf8_display_split( " " ) == std::vector<std::string> { " ", " ", " ", " " } );
}

TEST_CASE( "base64", "[catacharset]" )
TEST_CASE( "base64", "[catacharset][nogame]" )
{
CHECK( base64_encode( "hello" ) == "#aGVsbG8=" );
CHECK( base64_decode( "#aGVsbG8=" ) == "hello" );
}

TEST_CASE( "utf8_to_wstr", "[catacharset]" )
TEST_CASE( "utf8_to_wstr", "[catacharset][nogame]" )
{
// std::mbstowcs' returning -1 workaround
char *result = setlocale( LC_ALL, "" );
Expand All @@ -52,7 +52,7 @@ TEST_CASE( "utf8_to_wstr", "[catacharset]" )
REQUIRE( result );
}

TEST_CASE( "wstr_to_utf8", "[catacharset]" )
TEST_CASE( "wstr_to_utf8", "[catacharset][nogame]" )
{
// std::wcstombs' returning -1 workaround
char *result = setlocale( LC_ALL, "" );
Expand All @@ -64,7 +64,7 @@ TEST_CASE( "wstr_to_utf8", "[catacharset]" )
REQUIRE( result );
}

TEST_CASE( "localized_compare", "[catacharset]" )
TEST_CASE( "localized_compare", "[catacharset][nogame]" )
{
try {
std::locale::global( std::locale( "en_US.UTF-8" ) );
Expand Down Expand Up @@ -99,7 +99,7 @@ static void check_in_place_func( const std::function<void( char32_t & )> &func,
CHECK( ch == expected );
}

TEST_CASE( "u32_to_lowercase", "[catacharset]" )
TEST_CASE( "u32_to_lowercase", "[catacharset][nogame]" )
{
// Latin
check_in_place_func( u32_to_lowercase, U'a', U'a' );
Expand All @@ -123,7 +123,7 @@ TEST_CASE( "u32_to_lowercase", "[catacharset]" )
check_in_place_func( u32_to_lowercase, U'😅', U'😅' );
}

TEST_CASE( "remove_accent", "[catacharset]" )
TEST_CASE( "remove_accent", "[catacharset][nogame]" )
{
// Latin
check_in_place_func( remove_accent, U'o', U'o' );
Expand All @@ -142,7 +142,7 @@ TEST_CASE( "remove_accent", "[catacharset]" )
check_in_place_func( remove_accent, U'😅', U'😅' );
}

TEST_CASE( "utf8_view", "[catacharset]" )
TEST_CASE( "utf8_view", "[catacharset][nogame]" )
{
static const std::string str{"Français中文русский"};
static const std::vector<char32_t> expected_code_points{
Expand Down
16 changes: 8 additions & 8 deletions tests/coordinate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ coords::coord_point<Point, Origin, Scale, InBounds> assert_not_ib( const
return p;
}

TEST_CASE( "coordinate_strings", "[point][coords]" )
TEST_CASE( "coordinate_strings", "[point][coords][nogame]" )
{
CHECK( point_abs_omt( point( 3, 4 ) ).to_string() == "(3,4)" );

Expand All @@ -37,7 +37,7 @@ TEST_CASE( "coordinate_strings", "[point][coords]" )
}
}

TEST_CASE( "coordinate_operations", "[point][coords]" )
TEST_CASE( "coordinate_operations", "[point][coords][nogame]" )
{
SECTION( "construct_from_raw_point" ) {
point p = GENERATE( take( num_trials, random_points() ) );
Expand Down Expand Up @@ -193,7 +193,7 @@ TEST_CASE( "coordinate_operations", "[point][coords]" )
}
}

TEST_CASE( "coordinate_comparison", "[point][coords]" )
TEST_CASE( "coordinate_comparison", "[point][coords][nogame]" )
{
SECTION( "compare_points" ) {
point p0 = GENERATE( take( num_trials, random_points() ) );
Expand Down Expand Up @@ -224,7 +224,7 @@ TEST_CASE( "coordinate_comparison", "[point][coords]" )
}
}

TEST_CASE( "coordinate_hash", "[point][coords]" )
TEST_CASE( "coordinate_hash", "[point][coords][nogame]" )
{
SECTION( "point_hash" ) {
point p = GENERATE( take( num_trials, random_points() ) );
Expand All @@ -239,7 +239,7 @@ TEST_CASE( "coordinate_hash", "[point][coords]" )
}
}

TEST_CASE( "coordinate_conversion_consistency", "[point][coords]" )
TEST_CASE( "coordinate_conversion_consistency", "[point][coords][nogame]" )
{
// Verifies that the new coord_point-based conversions yield the same
// results as the legacy conversion functions.
Expand Down Expand Up @@ -384,7 +384,7 @@ TEST_CASE( "coordinate_conversion_consistency", "[point][coords]" )
}
}

TEST_CASE( "combine_is_opposite_of_remain", "[point][coords]" )
TEST_CASE( "combine_is_opposite_of_remain", "[point][coords][nogame]" )
{
SECTION( "point_point" ) {
point p = GENERATE( take( num_trials, random_points() ) );
Expand Down Expand Up @@ -438,7 +438,7 @@ TEST_CASE( "combine_is_opposite_of_remain", "[point][coords]" )
}
}

TEST_CASE( "coord_point_distances", "[point][coords]" )
TEST_CASE( "coord_point_distances", "[point][coords][nogame]" )
{
point_abs_omt p0;
point_abs_omt p1( 10, 10 );
Expand All @@ -460,7 +460,7 @@ TEST_CASE( "coord_point_distances", "[point][coords]" )
}
}

TEST_CASE( "coord_point_midpoint", "[point][coords]" )
TEST_CASE( "coord_point_midpoint", "[point][coords][nogame]" )
{
point_abs_omt p0( 2, 2 );
point_abs_omt p1( 8, 17 );
Expand Down
Loading

0 comments on commit 46f8117

Please sign in to comment.