1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*
* This source code is released into the public domain.
*/
#include <catch2/catch_test_macros.hpp>
import nihil;
TEST_CASE("spawn: system", "[spawn]") {
using namespace nihil;
auto output = std::string();
auto result = spawn(shell("x=1; echo $x"),
capture(stdout_fileno, output)).wait();
REQUIRE(result.okay());
REQUIRE(output == "1\n");
}
TEST_CASE("spawn: execv", "[spawn]") {
using namespace nihil;
auto output = std::string();
auto args = argv::from_args({"sh", "-c", "x=1; echo $x"});
auto result = spawn(execv("/bin/sh", std::move(args)),
capture(stdout_fileno, output)).wait();
REQUIRE(result.okay());
REQUIRE(output == "1\n");
}
TEST_CASE("spawn: execvp", "[spawn]") {
using namespace nihil;
auto output = std::string();
auto args = argv::from_args({"sh", "-c", "x=1; echo $x"});
auto result = spawn(execvp("sh", std::move(args)),
capture(stdout_fileno, output)).wait();
REQUIRE(result.okay());
REQUIRE(output == "1\n");
}
TEST_CASE("spawn: execl", "[spawn]") {
using namespace nihil;
auto output = std::string();
auto result = spawn(execl("/bin/sh", "sh", "-c", "x=1; echo $x"),
capture(stdout_fileno, output)).wait();
REQUIRE(result.okay());
REQUIRE(output == "1\n");
}
TEST_CASE("spawn: execlp", "[spawn]") {
using namespace nihil;
auto output = std::string();
auto result = spawn(execlp("sh", "sh", "-c", "x=1; echo $x"),
capture(stdout_fileno, output)).wait();
REQUIRE(result.okay());
REQUIRE(output == "1\n");
}
TEST_CASE("spawn: execlp failure", "[spawn]") {
using namespace nihil;
REQUIRE_THROWS_AS(execlp("lfjail_nonesuch_executable", "x"),
executable_not_found);
}
|