From 155bc3a375486a010af385c8dc8e12b6ff98838d Mon Sep 17 00:00:00 2001 From: Trevor Shoe Date: Fri, 22 Nov 2024 17:07:38 -0500 Subject: [PATCH 1/2] [tests] Use ASSERT instead of EXPECT when appropriate --- tests/mock_process.cpp | 13 +++++++++++-- tests/test_basic_process.cpp | 12 ++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/mock_process.cpp b/tests/mock_process.cpp index 0a93f86093..1fb31d0f43 100644 --- a/tests/mock_process.cpp +++ b/tests/mock_process.cpp @@ -2,12 +2,21 @@ #include #include +[[noreturn]] void crash() +{ +#ifdef MULTIPASS_PLATFORM_WINDOWS + // Prevent Windows from making a dialogue box or reporting data. + _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); +#endif + abort(); +} + int main(int argc, char* argv[]) { if (argc == 1) { // deliberately will crash if argument 1 missing - abort(); + crash(); } // Exit immediately if only 1 argument else if (argc == 2) @@ -22,7 +31,7 @@ int main(int argc, char* argv[]) // Crash on demand if (s == "crash") { - abort(); + crash(); } // Print out what was supplied by stdin diff --git a/tests/test_basic_process.cpp b/tests/test_basic_process.cpp index 3ac4972759..8470853c25 100644 --- a/tests/test_basic_process.cpp +++ b/tests/test_basic_process.cpp @@ -38,7 +38,7 @@ TEST_F(BasicProcessTest, execute_missing_command) EXPECT_FALSE(process_state.completed_successfully()); EXPECT_FALSE(process_state.exit_code); - EXPECT_TRUE(process_state.error); + ASSERT_TRUE(process_state.error); EXPECT_EQ(QProcess::ProcessError::FailedToStart, process_state.error->state); } @@ -50,7 +50,7 @@ TEST_F(BasicProcessTest, execute_crashing_command) EXPECT_FALSE(process_state.completed_successfully()); EXPECT_FALSE(process_state.exit_code); - EXPECT_TRUE(process_state.error); + ASSERT_TRUE(process_state.error); EXPECT_EQ(QProcess::ProcessError::Crashed, process_state.error->state); } @@ -121,7 +121,7 @@ TEST_F(BasicProcessTest, process_state_when_runs_but_fails_to_stop) process_state = process.process_state(); EXPECT_FALSE(process_state.exit_code); - EXPECT_TRUE(process_state.error); + ASSERT_TRUE(process_state.error); EXPECT_EQ(QProcess::Timedout, process_state.error->state); } @@ -135,7 +135,7 @@ TEST_F(BasicProcessTest, process_state_when_crashes_on_start) auto process_state = process.process_state(); EXPECT_FALSE(process_state.exit_code); - EXPECT_TRUE(process_state.error); + ASSERT_TRUE(process_state.error); EXPECT_EQ(QProcess::Crashed, process_state.error->state); } @@ -151,7 +151,7 @@ TEST_F(BasicProcessTest, process_state_when_crashes_while_running) auto process_state = process.process_state(); EXPECT_FALSE(process_state.exit_code); - EXPECT_TRUE(process_state.error); + ASSERT_TRUE(process_state.error); EXPECT_EQ(QProcess::Crashed, process_state.error->state); } @@ -165,7 +165,7 @@ TEST_F(BasicProcessTest, process_state_when_failed_to_start) auto process_state = process.process_state(); EXPECT_FALSE(process_state.exit_code); - EXPECT_TRUE(process_state.error); + ASSERT_TRUE(process_state.error); EXPECT_EQ(QProcess::FailedToStart, process_state.error->state); } From 3799f30f8b6fdecae2a38ac07be6c53c4942d0dd Mon Sep 17 00:00:00 2001 From: Trevor Shoe Date: Fri, 22 Nov 2024 18:03:41 -0500 Subject: [PATCH 2/2] [tests] Set windows abort behavior to crash in mock_process --- tests/mock_process.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/mock_process.cpp b/tests/mock_process.cpp index 1fb31d0f43..a69fffee2c 100644 --- a/tests/mock_process.cpp +++ b/tests/mock_process.cpp @@ -5,8 +5,9 @@ [[noreturn]] void crash() { #ifdef MULTIPASS_PLATFORM_WINDOWS - // Prevent Windows from making a dialogue box or reporting data. - _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); + // Prevent Windows from making a dialogue box and enable crash data reporting. + // If data reporting is not enabled, QProcess will always return NormalExit. + _set_abort_behavior(_CALL_REPORTFAULT, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); #endif abort(); }