mirror of https://gitlab.com/cppit/jucipp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.6 KiB
57 lines
1.6 KiB
#include "process.hpp" |
|
#include <glib.h> |
|
|
|
int main() { |
|
auto output = std::make_shared<std::string>(); |
|
auto error = std::make_shared<std::string>(); |
|
{ |
|
TinyProcessLib::Process process("echo Test", "", [output](const char *bytes, size_t n) { |
|
*output += std::string(bytes, n); |
|
}); |
|
g_assert(process.get_exit_status() == 0); |
|
g_assert(output->substr(0, 4) == "Test"); |
|
output->clear(); |
|
} |
|
|
|
{ |
|
TinyProcessLib::Process process( |
|
"echo Test && ls an_incorrect_path", "", |
|
[output](const char *bytes, size_t n) { |
|
*output += std::string(bytes, n); |
|
}, |
|
[error](const char *bytes, size_t n) { |
|
*error += std::string(bytes, n); |
|
}); |
|
g_assert(process.get_exit_status() > 0); |
|
g_assert(output->substr(0, 4) == "Test"); |
|
g_assert(!error->empty()); |
|
output->clear(); |
|
error->clear(); |
|
} |
|
|
|
{ |
|
TinyProcessLib::Process process( |
|
"sh", "", [output](const char *bytes, size_t n) { |
|
*output += std::string(bytes, n); |
|
}, |
|
nullptr, true); |
|
process.write("echo Test\n"); |
|
process.write("exit\n"); |
|
g_assert(process.get_exit_status() == 0); |
|
g_assert(output->substr(0, 4) == "Test"); |
|
output->clear(); |
|
} |
|
|
|
{ |
|
TinyProcessLib::Process process( |
|
"cat", "", [output](const char *bytes, size_t n) { |
|
*output += std::string(bytes, n); |
|
}, |
|
nullptr, true); |
|
process.write("Test\n"); |
|
process.close_stdin(); |
|
g_assert(process.get_exit_status() == 0); |
|
g_assert(output->substr(0, 4) == "Test"); |
|
output->clear(); |
|
} |
|
}
|
|
|