Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix basic process tests on Windows #3789

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
andrei-toterman marked this conversation as resolved.
Show resolved Hide resolved
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
Loading