Files
daggy/tests/unit_executor_forkingexecutor.cpp
2021-06-16 10:16:30 -03:00

42 lines
1.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <iostream>
#include <filesystem>
#include "daggy/executors/ForkingExecutor.hpp"
#include "catch.hpp"
TEST_CASE("Basic Execution", "[forking_executor]") {
daggy::executor::ForkingExecutor ex;
SECTION("Simple Run") {
std::vector<std::string> cmd{"/usr/bin/echo", "abc", "123"};
auto rec = ex.runCommand(cmd);
REQUIRE(rec.rc == 0);
REQUIRE(rec.output == "abc 123\n");
REQUIRE(rec.error.empty());
}
SECTION("Error Run") {
std::vector<std::string> cmd{"/usr/bin/expr", "1", "+", "+"};
auto rec = ex.runCommand(cmd);
REQUIRE(rec.rc == 2);
REQUIRE(rec.error == "/usr/bin/expr: syntax error: missing argument after +\n");
REQUIRE(rec.output.empty());
}
SECTION("Large Output") {
const std::string BIG_FILE{"/usr/share/dict/linux.words"};
std::vector<std::string> cmd{"/usr/bin/cat", BIG_FILE};
auto rec = ex.runCommand(cmd);
REQUIRE(rec.rc == 0);
REQUIRE(rec.output.size() == std::filesystem::file_size(BIG_FILE));
REQUIRE(rec.error.empty());
}
}