config.h tests
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char s[16];
|
||||
scanf("%s", s);
|
||||
printf("%s\n", s);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
#include <cppipe/commands.hpp>
|
||||
|
||||
#include <sys/wait.h>
|
||||
#include <iostream>
|
||||
|
||||
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 | grep + "cpp" | grep + "child");
|
||||
if(out1.find("childProcess.cpp") != string::npos)
|
||||
cout << "OK 0/11" << endl;
|
||||
|
||||
string out2 = $(echo + "abc" + "def");
|
||||
if(auto len = out2.size(); len != 8)
|
||||
cerr << "FAILURE: unexpected output length " << len << endl;
|
||||
|
||||
Cmd success("echo", "OK 1/11");
|
||||
Cmd fail("mkdir", ".");
|
||||
Cmd unexpected("echo", "FAILURE");
|
||||
success &&
|
||||
fail &&
|
||||
unexpected;
|
||||
|
||||
// shouldnt compile
|
||||
// success ||
|
||||
// unexpected &&
|
||||
// unexpected;
|
||||
|
||||
Cmd write_file("echo", "Existing ", " ", "file. OK 2/11");
|
||||
|
||||
write_file > "file.txt";
|
||||
grep + "Existing" < "file.txt";
|
||||
|
||||
echo + "Appended to file OK 3/11" >> "file.txt";
|
||||
grep + "Appended" < "file.txt" &&
|
||||
rm + "file.txt" &&
|
||||
fail ||
|
||||
Cmd("echo", "OK 4/11");
|
||||
|
||||
echo + "OK 5/11" &&
|
||||
echo + "OK 6/11",
|
||||
Cmd("echo", "OK 7/11");
|
||||
|
||||
echo + "OK 8/11" &
|
||||
echo + "OK 9/11" &&
|
||||
echo + "OK 10/11";
|
||||
|
||||
// wait for all detached
|
||||
while(wait(nullptr) != -1);
|
||||
|
||||
exec( echo + "OK 11/11" );
|
||||
|
||||
// todo
|
||||
// exec( echo + $(echo + "OK 11/11") );
|
||||
}
|
||||
Reference in New Issue
Block a user