cpp-subprocess/test/test_ret_code.cc
xoviat f6799fcc34 WIP: add windows compatibility (#32)
* windows: add util functions

* windows: add cmake files

* windows: add travis.yml

* windows: address compatibility
- set cxx standard
- conditionally exclude codecvt

* windows: improve test coverage

* windows: improve test coverage

* windows: consolidate tests

* windows: disable failing test

* windows: modify read_atmost_n to use file object

* windows: modify read_all to use file object

* windows: update read_all test to use new api

* windows: implement main subprocess logic

* windows: add macro names

* windows: setup comm channels

* windows: compatibility fixes
2019-05-09 22:02:58 +05:30

34 lines
779 B
C++

#include <iostream>
#include "../subprocess.hpp"
namespace sp = subprocess;
void test_ret_code()
{
std::cout << "Test::test_poll_ret_code" << std::endl;
auto p = sp::Popen({"/usr/bin/false"});
while (p.poll() == -1) {
usleep(1000 * 100);
}
assert (p.retcode() == 1);
}
void test_ret_code_comm()
{
using namespace sp;
auto cat = Popen({"cat", "../subprocess.hpp"}, output{PIPE});
auto grep = Popen({"grep", "template"}, input{cat.output()}, output{PIPE});
auto cut = Popen({"cut", "-d,", "-f", "1"}, input{grep.output()}, output{PIPE});
auto res = cut.communicate().first;
std::cout << res.buf.data() << std::endl;
std::cout << "retcode: " << cut.retcode() << std::endl;
}
int main() {
// test_ret_code();
test_ret_code_comm();
return 0;
}