Skip to content

Commit

Permalink
Merge pull request #3789 from canonical/fix-basic-process-tests
Browse files Browse the repository at this point in the history
Fix basic process tests on Windows
  • Loading branch information
andrei-toterman authored Dec 13, 2024
2 parents 11e0ac9 + 3799f30 commit a516c93
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
14 changes: 12 additions & 2 deletions tests/mock_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@
#include <iostream>
#include <string>

[[noreturn]] void crash()
{
#ifdef MULTIPASS_PLATFORM_WINDOWS
// 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();
}

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)
Expand All @@ -22,7 +32,7 @@ int main(int argc, char* argv[])
// Crash on demand
if (s == "crash")
{
abort();
crash();
}

// Print out what was supplied by stdin
Expand Down
12 changes: 6 additions & 6 deletions tests/test_basic_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit a516c93

Please sign in to comment.