Move ExecTestHelper to using a regex.
Test: treehugger Change-Id: I1aa6bc174e000cb57481c51109d98b8c2c5acb8e
This commit is contained in:
parent
5b4913a599
commit
419554e99c
2 changed files with 9 additions and 5 deletions
|
@ -134,7 +134,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
|
||||
}
|
||||
|
||||
|
@ -150,7 +151,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
|
||||
}
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ class ExecTestHelper {
|
|||
}
|
||||
|
||||
void Run(const std::function<void()>& 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_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue