aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.posix/execv.test.cc
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-30 07:51:23 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-30 07:51:23 +0100
commit034cd404a129103a8dd7747e6bd00ffd5550da93 (patch)
treed27946517d4d9333abd26ac50bbd4a436093e2ce /nihil.posix/execv.test.cc
parent3e7902f7d790a486d3d9cb978df193f07f3a6ad9 (diff)
downloadnihil-034cd404a129103a8dd7747e6bd00ffd5550da93.tar.gz
nihil-034cd404a129103a8dd7747e6bd00ffd5550da93.tar.bz2
refactoring
Diffstat (limited to 'nihil.posix/execv.test.cc')
-rw-r--r--nihil.posix/execv.test.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/nihil.posix/execv.test.cc b/nihil.posix/execv.test.cc
new file mode 100644
index 0000000..aaeead7
--- /dev/null
+++ b/nihil.posix/execv.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::execv() can be used to spawn a shell")
+{
+ GIVEN("An execv object")
+ {
+ auto exec = nihil::execv("/bin/sh", nihil::argv{"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::execv() returns the shell's exit code")
+{
+ GIVEN("An execshell object")
+ {
+ auto exec = nihil::execv("/bin/sh", nihil::argv{"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