mirror of
https://github.com/arun11299/cpp-subprocess.git
synced 2025-08-05 12:56:23 -04:00

* 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
75 lines
1.9 KiB
C++
Executable File
75 lines
1.9 KiB
C++
Executable File
#include <iostream>
|
|
#include <cpp-subprocess/subprocess.hpp>
|
|
|
|
namespace sp = subprocess;
|
|
|
|
void test_cat_pipe_redirection()
|
|
{
|
|
std::cout << "Test::test_cat_pipe_redirection" << std::endl;
|
|
auto p = sp::Popen({"cat", "-"}, sp::input{sp::PIPE}, sp::output{sp::PIPE});
|
|
auto msg = "through stdin to stdout";
|
|
auto res_buf = p.communicate(msg, strlen(msg)).first;
|
|
assert(res_buf.length == strlen(msg));
|
|
std::cout << "END_TEST" << std::endl;
|
|
}
|
|
|
|
void test_cat_file_redirection()
|
|
{
|
|
std::cout << "Test::test_cat_file_redirection" << std::endl;
|
|
auto p = sp::Popen({"cat", "-"}, sp::input{sp::PIPE}, sp::output{"cat_fredirect.txt"});
|
|
auto msg = "through stdin to stdout";
|
|
int wr_bytes = p.send(msg, strlen(msg));
|
|
assert (wr_bytes == (int)strlen(msg));
|
|
std::cout << "END_TEST" << std::endl;
|
|
}
|
|
|
|
void test_cat_send_terminate()
|
|
{
|
|
std::cout << "Test::test_cat_send_terminate" << std::endl;
|
|
std::vector<sp::Popen> pops;
|
|
|
|
for (int i=0; i < 5; i++) {
|
|
pops.emplace_back(sp::Popen({"cat", "-"}, sp::input{sp::PIPE}));
|
|
pops[i].send("3 5\n", 5);
|
|
pops[i].close_input();
|
|
}
|
|
|
|
for (int i=0; i < 5; i++) {
|
|
pops[i].wait();
|
|
}
|
|
|
|
std::cout << "END_TEST" << std::endl;
|
|
}
|
|
|
|
void test_buffer_growth()
|
|
{
|
|
auto obuf = sp::check_output({"cat", "../subprocess.hpp"});
|
|
std::cout << obuf.length << std::endl;
|
|
assert (obuf.length > sp::DEFAULT_BUF_CAP_BYTES);
|
|
}
|
|
|
|
void test_buffer_growth_threaded_comm()
|
|
{
|
|
std::cout << "Test::test_buffer_growth_threaded_comm" << std::endl;
|
|
auto buf = sp::check_output("cat ../subprocess.hpp", sp::error{sp::PIPE});
|
|
std::cout << buf.length << std::endl;
|
|
assert (buf.length > sp::DEFAULT_BUF_CAP_BYTES);
|
|
std::cout << "END_TEST" << std::endl;
|
|
}
|
|
|
|
int main() {
|
|
#ifndef __USING_WINDOWS__
|
|
|
|
// test_cat_pipe_redirection();
|
|
test_cat_send_terminate();
|
|
/*
|
|
test_cat_file_redirection();
|
|
test_buffer_growth();
|
|
test_buffer_growth_threaded_comm();
|
|
*/
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
}
|