Riyyis Utilities for C++
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.

40 lines
879 B

#include <string>
#include "macro.h"
#include "ruc/shell.h"
#include "testcase.h"
#include "testsuite.h"
bool runShell(const char* command, std::string* output = nullptr)
{
stdout = test::TestSuite::the().outputNull();
ruc::Shell $;
auto exec = $(command);
if (output) {
*output = exec.output();
}
stdout = test::TestSuite::the().outputStd();
return !exec.status() ? true : false;
}
// -----------------------------------------
TEST_CASE(ShellCommand)
{
// Pipe test, grep section of the echo command, return true
std::string output = "";
auto result = runShell("echo 'Hello World!' | grep --only-matching 'Hello'", &output);
EXPECT_EQ(result, true);
EXPECT_EQ(output, "Hello\n");
// Return false
result = runShell("exit 1");
EXPECT_EQ(result, false);
// Return false
result = runShell("failure() { return 1; }; failure");
EXPECT_EQ(result, false);
}