Skip to content

Commit efa21c2

Browse files
committed
tests: Add test for exec timeout and adjust expected error
New exec implementation returns a different error when the command is not found. Signed-off-by: Andre Detsch <andre.detsch@foundries.io>
1 parent b99a4d1 commit efa21c2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tests/exec_test.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ TEST(Exec, FailedExec) {
1717
} catch (const std::exception& exc) {
1818
const std::string err_msg{exc.what()};
1919

20-
ASSERT_NE(err_msg.find("failed to run command"), std::string::npos);
20+
ASSERT_NE(err_msg.find("not found"), std::string::npos) << "Actual error message: " + err_msg;
2121
ASSERT_NE(err_msg.find(executable), std::string::npos) << "Actual error message: " + err_msg;
2222
;
23-
ASSERT_NE(err_msg.find("No such file or directory"), std::string::npos) << "Actual error message: " + err_msg;
24-
;
2523
}
2624
}
2725

@@ -41,6 +39,18 @@ TEST(Exec, SuccessfulExecFailedExecutable) {
4139
}
4240
}
4341

42+
TEST(Exec, ExecTimeout) {
43+
const std::string cmd{"sleep 10"};
44+
45+
try {
46+
exec(cmd, "", "", nullptr, "2s", false);
47+
} catch (const std::runtime_error& exc) {
48+
const std::string err_msg{exc.what()};
49+
50+
ASSERT_NE(err_msg.find("Timeout"), std::string::npos) << "Actual error message: " + err_msg;
51+
}
52+
}
53+
4454
int main(int argc, char** argv) {
4555
::testing::InitGoogleTest(&argc, argv);
4656
return RUN_ALL_TESTS();

0 commit comments

Comments
 (0)