cpp-subprocess/test/test_exception.cc
Itay Bookstein 74a54f1d24 cpp-subprocess: Avoid memory allocations in forkee
Signed-off-by: Itay Bookstein <itay.bookstein@nextsilicon.com>
2025-07-10 21:42:10 +03:00

28 lines
575 B
C++

#include <cassert>
#include <cstring>
#include <cpp-subprocess/subprocess.hpp>
namespace sp = subprocess;
void test_exception()
{
bool caught = false;
try {
auto p = sp::Popen("invalid_command");
assert(false); // Expected to throw
} catch (sp::CalledProcessError& e) {
#ifdef __USING_WINDOWS__
assert(std::strstr(e.what(), "CreateProcess failed: The system cannot find the file specified."));
#else
assert(std::strstr(e.what(), "execvpe failed: 0x"));
#endif
caught = true;
}
assert(caught);
}
int main() {
test_exception();
return 0;
}