cpp-subprocess/test/test_redirection.cc.in
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

24 lines
730 B
C++

#include <cpp-subprocess/subprocess.hpp>
#include <cstdlib>
#include <string>
#include <tuple>
using namespace subprocess;
int main() {
auto p = Popen("python3 @TEST_REDIRECTION_PYTHON_SCRIPT_PATH@", output{PIPE}, error{PIPE});
OutBuffer out_buf;
ErrBuffer err_buf;
std::tie(out_buf, err_buf) = p.communicate();
std::string out{out_buf.buf.data()};
std::string err{err_buf.buf.data()};
if (out.find("Hello message.") == std::string::npos) return EXIT_FAILURE;
if (err.find("Hello message.") != std::string::npos) return EXIT_FAILURE;
if (out.find("Error report.") != std::string::npos) return EXIT_FAILURE;
if (err.find("Error report.") == std::string::npos) return EXIT_FAILURE;
return EXIT_SUCCESS;
}