cpp-subprocess/test/test_exception.cc
Haowen Liu f6232a7f26
Improve CMake setup (#118)
* Support CMake 4

CMake 4 has removed compatibility with CMake < 3.5
Bumping minimum required version to 3.5 enables
CMake 4 to build this code.

* Move header into subdir

* Improve CMake setup

This commit configures and installs CMake metadata files. This also
provides the namespaced ALIAS target `cpp-subprocess::subprocess`.

* Update README with CMake instructions

* Update include paths in tests
2025-05-04 20:22:13 +05:30

28 lines
597 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(), "execve failed: No such file or directory"));
#endif
caught = true;
}
assert(caught);
}
int main() {
test_exception();
return 0;
}