From 0cdf6757f5d518b29f29453a98c0a0df7be678dc Mon Sep 17 00:00:00 2001 From: anothersimulacrum Date: Sat, 10 Jul 2021 15:27:49 -0700 Subject: [PATCH] Fix NPC attack tests Move the player so game::load_npcs will actually spawn the NPCs. Add REQUIREs to make the game not crash on failing to spawn NPCs. Remove the weather setting because it doesn't change the tests, and causes vision tests failures due to side effects! Adjust the values of the m16a4 test to start passing. --- tests/npc_attack_test.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/npc_attack_test.cpp b/tests/npc_attack_test.cpp index 0332bcb613908..18e039a58c95a 100644 --- a/tests/npc_attack_test.cpp +++ b/tests/npc_attack_test.cpp @@ -18,7 +18,9 @@ namespace npc_attack_setup { static void spawn_main_npc() { + get_player_character().setpos( { main_npc_start, -1 } ); const string_id blank_template( "test_talker" ); + REQUIRE( g->critter_at( main_npc_start_tripoint ) == nullptr ); const character_id model_id = get_map().place_npc( main_npc_start, blank_template ); npc &model_npc = *g->find_npc( model_id ); @@ -26,6 +28,8 @@ static void spawn_main_npc() model_npc.setpos( main_npc_start_tripoint ); g->load_npcs(); + + REQUIRE( g->critter_at( main_npc_start_tripoint ) != nullptr ); } static void respawn_main_npc() @@ -71,7 +75,6 @@ static void test_melee_attacks( const npc_attack_melee_test_data &data ) clear_map_and_put_player_underground(); clear_vehicles(); scoped_weather_override sunny_weather( weather_type_id( "sunny" ) ); - g->weather.set_nextweather( calendar::turn ); npc_attack_setup::spawn_main_npc(); npc_attack_setup::spawn_zombie_at_range( 1 ); monster *zomble = g->critter_at( main_npc_start_tripoint + tripoint_east ); @@ -150,7 +153,6 @@ static void test_gun_attacks( const npc_attack_gun_test_data &data ) clear_map_and_put_player_underground(); clear_vehicles(); scoped_weather_override sunny_weather( weather_type_id( "sunny" ) ); - g->weather.set_nextweather( calendar::turn ); npc_attack_setup::spawn_main_npc(); npc &main_npc = npc_attack_setup::get_main_npc(); arm_shooter( main_npc, data.weapon_id ); @@ -280,7 +282,7 @@ TEST_CASE( "Test NPC attack variants' potential", "[npc_attack]" ) SECTION( "m16a4" ) { const npc_attack_gun_test_data gun{ "m16a4", - 345, 375 + 336, 366 }; test_gun_attacks( gun ); }