diff options
Diffstat (limited to 'nihil.posix/execl.test.cc')
| -rw-r--r-- | nihil.posix/execl.test.cc | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/nihil.posix/execl.test.cc b/nihil.posix/execl.test.cc new file mode 100644 index 0000000..5aaaa25 --- /dev/null +++ b/nihil.posix/execl.test.cc @@ -0,0 +1,55 @@ +/* + * This source code is released into the public domain. + */ + +#include <catch2/catch_test_macros.hpp> + +import nihil.posix; + +namespace { + +SCENARIO("nihil::execl() can be used to spawn a shell") +{ + GIVEN("An execl object") + { + auto exec = nihil::execl("/bin/sh", "sh", "-c", "x=1; echo $x"); + + WHEN("The shell is executed") + { + auto output = std::string(); + auto capture = nihil::make_capture(nihil::stdout_fileno, output).value(); + auto status = nihil::spawn(exec, capture).value().wait().value(); + + THEN("The exit code is 0") + { + REQUIRE(status.status() == 0); + } + AND_THEN("The expected output was captured") + { + REQUIRE(output == "1\n"); + } + } + } +} + +SCENARIO("nihil::execl() returns the shell's exit code") +{ + GIVEN("An execshell object") + { + auto exec = nihil::execl("/bin/sh", "sh", "-c", "x=42; exit $x"); + + WHEN("The shell is executed") + { + auto output = std::string(); + auto capture = nihil::make_capture(nihil::stdout_fileno, output).value(); + auto status = nihil::spawn(exec, capture).value().wait().value(); + + THEN("The exit code is 1") + { + REQUIRE(status.status() == 42); + } + } + } +} + +} // anonymous namespace |
