From b9f51cc26d830e07f4e790a43f7f5c1468d4a599 Mon Sep 17 00:00:00 2001 From: Qrox Date: Fri, 18 Sep 2020 22:36:39 +0800 Subject: [PATCH 1/2] Fix unit test terminating message not starting on new line --- build-scripts/problem-matchers/json.json | 2 +- tests/test_main.cpp | 25 ++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/build-scripts/problem-matchers/json.json b/build-scripts/problem-matchers/json.json index aa4c9098573f6..eafe4261f6bd4 100644 --- a/build-scripts/problem-matchers/json.json +++ b/build-scripts/problem-matchers/json.json @@ -4,7 +4,7 @@ "owner": "cata-json", "pattern": [ { - "regexp": "^(?:Terminated: )?Json error: ([^:]*):([0-9]+):([0-9]+): (.*)$", + "regexp": "^Json error: ([^:]*):([0-9]+):([0-9]+): (.*)$", "file": 1, "line": 2, "column": 3, diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 374e2a5e7f09b..b065a71ce6b59 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -305,16 +305,16 @@ int main( int argc, const char *argv[] ) // If the run is terminated due to a crash during initialization, we won't // see the seed unless it's printed out in advance, so do that here. - printf( "Randomness seeded to: %u\n", seed ); + DebugLog( D_INFO, DC_ALL ) << "Randomness seeded to: " << seed; } try { // TODO: Only init game if we're running tests that need it. init_global_game_state( mods, option_overrides_for_test_suite, user_dir ); } 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" ); + DebugLog( D_ERROR, DC_ALL ) << "Terminated:\n" << err.what(); + DebugLog( D_INFO, DC_ALL ) << + "Make sure that you're in the correct working directory and your data isn't corrupted."; return EXIT_FAILURE; } @@ -324,7 +324,7 @@ int main( int argc, const char *argv[] ) 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 ) ); + DebugLog( D_INFO, DC_ALL ) << "Starting the actual test at " << 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 ); @@ -333,22 +333,23 @@ int main( int argc, const char *argv[] ) 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() ); + DebugLog( D_INFO, DC_ALL ) << "Test world " << world_name << " left for inspection."; } std::chrono::duration elapsed_seconds = end - start; - printf( "Ended test at %sThe test took %.3f seconds\n", std::ctime( &end_time ), - elapsed_seconds.count() ); + DebugLog( D_INFO, DC_ALL ) << "Ended test at " << std::ctime( &end_time ); + DebugLog( D_INFO, DC_ALL ) << "The test took " << elapsed_seconds.count() << " seconds"; if( error_during_initialization ) { - printf( "\nTreating result as failure due to error logged during initialization.\n" ); - printf( "Randomness seeded to: %u\n", seed ); + DebugLog( D_INFO, DC_ALL ) << + "Treating result as failure due to error logged during initialization."; + DebugLog( D_INFO, DC_ALL ) << "Randomness seeded to: " << seed; return 1; } if( debug_has_error_been_observed() ) { - printf( "\nTreating result as failure due to error logged during tests.\n" ); - printf( "Randomness seeded to: %u\n", seed ); + DebugLog( D_INFO, DC_ALL ) << "Treating result as failure due to error logged during tests."; + DebugLog( D_INFO, DC_ALL ) << "Randomness seeded to: " << seed; return 1; } From 636ef81fca8773ae0e838238637754a6b1191b59 Mon Sep 17 00:00:00 2001 From: Qrox Date: Sat, 19 Sep 2020 08:43:41 +0800 Subject: [PATCH 2/2] Remove redundant output --- tests/test_main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_main.cpp b/tests/test_main.cpp index b065a71ce6b59..ddd1be563a596 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -343,13 +343,11 @@ int main( int argc, const char *argv[] ) if( error_during_initialization ) { DebugLog( D_INFO, DC_ALL ) << "Treating result as failure due to error logged during initialization."; - DebugLog( D_INFO, DC_ALL ) << "Randomness seeded to: " << seed; return 1; } if( debug_has_error_been_observed() ) { DebugLog( D_INFO, DC_ALL ) << "Treating result as failure due to error logged during tests."; - DebugLog( D_INFO, DC_ALL ) << "Randomness seeded to: " << seed; return 1; }