diff --git a/tests/dl_test.cpp b/tests/dl_test.cpp index ad1650171..bf32bd549 100644 --- a/tests/dl_test.cpp +++ b/tests/dl_test.cpp @@ -133,7 +133,8 @@ TEST(dl, exec_linker_load_file) { "helper_func called\n"; ExecTestHelper eth; eth.SetArgs({ path_to_linker, helper.c_str(), nullptr }); - eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, 0, expected_output.c_str()); + eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, 0, nullptr); + ASSERT_EQ(expected_output, eth.GetOutput()); #endif } @@ -149,7 +150,8 @@ TEST(dl, exec_linker_load_from_zip) { "helper_func called\n"; ExecTestHelper eth; eth.SetArgs({ path_to_linker, helper.c_str(), nullptr }); - eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, 0, expected_output.c_str()); + eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, 0, nullptr); + ASSERT_EQ(expected_output, eth.GetOutput()); #endif } diff --git a/tests/utils.h b/tests/utils.h index 592ac0e56..284140a0d 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -229,7 +229,7 @@ class ExecTestHelper { } void Run(const std::function& child_fn, int expected_exit_status, - const char* expected_output) { + const char* expected_output_regex) { int fds[2]; ASSERT_NE(pipe(fds), -1); @@ -258,8 +258,10 @@ class ExecTestHelper { std::string error_msg("Test output:\n" + output_); AssertChildExited(pid, expected_exit_status, &error_msg); - if (expected_output != nullptr) { - ASSERT_EQ(expected_output, output_); + if (expected_output_regex != nullptr) { + if (!std::regex_search(output_, std::regex(expected_output_regex))) { + FAIL() << "regex " << expected_output_regex << " didn't match " << output_; + } } }