Skip to content

Commit

Permalink
Tweak subprocess test
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
  • Loading branch information
mjcarroll committed Nov 7, 2023
1 parent 870e93b commit 8b36418
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 8 additions & 2 deletions test/integration/subprocess/subprocess_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class OutputSink
if (dest == "cout" || dest == "both")
{
std::cout << val << std::endl;

}
else if (dest == "cerr" || dest == "both")
{
Expand All @@ -59,6 +58,10 @@ int main(int argc, char **argv)
int iter_ms = 0;
app.add_option("--iteration-ms", iter_ms, "length of one iteration");

bool environment = false;
app.add_flag("--environment", environment,
"print the environment variables");

CLI11_PARSE(app, argc, argv);

auto sink = OutputSink(output);
Expand All @@ -68,6 +71,9 @@ int main(int argc, char **argv)
std::this_thread::sleep_for(std::chrono::milliseconds(iter_ms));
}

sink.Write(gz::utils::printenv());
if (environment)
{
sink.Write(gz::utils::printenv());
}
return 0;
}
8 changes: 5 additions & 3 deletions test/integration/subprocess_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ TEST(Subprocess, Environment)

{
// Default behavior is to inherit the environment
auto proc = Subprocess({kExecutablePath, "--output=cout"});
auto proc = Subprocess({kExecutablePath, "--output=cout", "--environment"});
// Block until the executable is done
auto ret = proc.Join();
EXPECT_EQ(0u, ret);
Expand All @@ -137,7 +137,8 @@ TEST(Subprocess, Environment)

{
// Passing an empty map as the second arg clears the environment
auto proc = Subprocess({kExecutablePath, "--output=cout"}, {});
auto proc = Subprocess(
{kExecutablePath, "--output=cout", "--environment"}, {});
// Block until the executable is done
auto ret = proc.Join();
EXPECT_EQ(0u, ret);
Expand All @@ -150,7 +151,8 @@ TEST(Subprocess, Environment)

{
// Passing a map sets those variables, clearing the rest
auto proc = Subprocess({kExecutablePath, "--output=cout"}, {
auto proc = Subprocess(
{kExecutablePath, "--output=cout", "--environment"}, {
{"QUX_KEY", "QUX_VAL"}
});
// Block until the executable is done
Expand Down

0 comments on commit 8b36418

Please sign in to comment.