#!/usr/local/bin/cppipe // Test cppipe functions #include #include #include using namespace std; int main(int argc, char* argv[]) { if(argc > 1) { cerr << "FAILURE: didn't expect any arguments, got:\n"; for(int i = 0; i < argc; ++i) cerr << argv[i] << endl; exit(1); } Cmd ls("ls"); Cmd ll("ls", "-l"); Cmd grep("grep"); Cmd echo("echo"); Cmd rm("rm"); string out1 = $(ll + "src" | grep + "inl" | grep + "child"); if(out1.find("childProcess.inl") != string::npos) cout << "OK 0/13" << endl; string out2 = $(echo + "abc" + "def"); // "abc def" = 7 chars, trailing newlines are stripped by $() if(auto len = out2.size(); len != 7) { cerr << "FAILURE: unexpected output length " << len << endl; exit(1); } Cmd success("echo", "OK 1/13"); Cmd fail("false"); Cmd unexpected("echo", "FAILURE"); success && fail && unexpected; // shouldnt compile // success || // unexpected && // unexpected; Cmd write_file("echo", "Existing ", " ", "file. OK 2/13"); write_file > "file.txt"; grep + "Existing" < "file.txt"; echo + "Appended to file OK 3/13" >> "file.txt"; grep + "Appended" < "file.txt" && rm + "file.txt" && fail || Cmd("echo", "OK 4/13"); echo + "OK 5/13" && echo + "OK 6/13", Cmd("echo", "OK 7/13"); echo + "OK 8/13" & echo + "OK 9/13" && echo + "OK 10/13"; // wait for all detached while(wait(nullptr) != -1); Cmd run_OK = echo; run_OK.append_args({ "OK 11/13" }); run( run_OK ); run({ "echo", "OK 12/13" }); exec({ "echo", "OK 13/13" }); // todo // exec( echo + $(echo + "OK 11/13") ); }