mirror of
https://github.com/arun11299/cpp-subprocess.git
synced 2025-08-05 04:46:21 -04:00

* Fix exception when `CreateProcessW` fails This change makes the behavior on Windows consistent with the behavior on Linux. * test: Add `test_exception`
28 lines
582 B
C++
28 lines
582 B
C++
#include <cassert>
|
|
#include <cstring>
|
|
#include <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;
|
|
}
|