mirror of
https://github.com/arun11299/cpp-subprocess.git
synced 2025-08-04 20:36:20 -04:00
test: Add test_exception
This commit is contained in:
parent
da162fe5a6
commit
7cc45cfabc
@ -1,4 +1,4 @@
|
|||||||
set(test_names test_subprocess test_cat test_env test_err_redirection test_split test_main test_ret_code)
|
set(test_names test_subprocess test_cat test_env test_err_redirection test_exception test_split test_main test_ret_code)
|
||||||
set(test_files env_script.sh write_err.sh write_err.txt)
|
set(test_files env_script.sh write_err.sh write_err.txt)
|
||||||
|
|
||||||
|
|
||||||
|
27
test/test_exception.cc
Normal file
27
test/test_exception.cc
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user