X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ftest%2FSubprocessTest.cpp;h=188e7d442d3d6013d980de4d09d58fbad3c375e5;hb=717229ecf385ee10a91d6c2af859e8550df84531;hp=d9763ae63ecf19316c3164891d8a39057d3aa35a;hpb=0e5ec48b7d2e3c04b5b0454144b2e183d64e16ac;p=folly.git diff --git a/folly/test/SubprocessTest.cpp b/folly/test/SubprocessTest.cpp index d9763ae6..188e7d44 100644 --- a/folly/test/SubprocessTest.cpp +++ b/folly/test/SubprocessTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2012-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -183,7 +183,7 @@ boost::container::flat_set getOpenFds() { return fds; } -template +template void checkFdLeak(const Runnable& r) { // Get the currently open fds. Check that they are the same both before and // after calling the specified function. We read the open fds from /proc. @@ -195,7 +195,7 @@ void checkFdLeak(const Runnable& r) { auto fdsAfter = getOpenFds(); EXPECT_EQ(fdsAfter.size(), fdsBefore.size()); } -} +} // namespace // Make sure Subprocess doesn't leak any file descriptors TEST(SimpleSubprocessTest, FdLeakTest) { @@ -222,8 +222,9 @@ TEST(SimpleSubprocessTest, FdLeakTest) { // Test where the exec call fails() with pipes checkFdLeak([] { try { - Subprocess proc(std::vector({"/no/such/file"}), - Subprocess::pipeStdout().stderrFd(Subprocess::PIPE)); + Subprocess proc( + std::vector({"/no/such/file"}), + Subprocess::Options().pipeStdout().stderrFd(Subprocess::PIPE)); ADD_FAILURE() << "expected an error when running /no/such/file"; } catch (const SubprocessSpawnError& ex) { EXPECT_EQ(ENOENT, ex.errnoValue()); @@ -258,7 +259,7 @@ TEST(ParentDeathSubprocessTest, ParentDeathSignal) { } TEST(PopenSubprocessTest, PopenRead) { - Subprocess proc("ls /", Subprocess::pipeStdout()); + Subprocess proc("ls /", Subprocess::Options().pipeStdout()); int found = 0; gen::byLine(File(proc.stdoutFd())) | [&] (StringPiece line) { @@ -280,7 +281,7 @@ struct WriteFileAfterFork : public Subprocess::DangerousPostForkPreExecCallback { explicit WriteFileAfterFork(std::string filename) : filename_(std::move(filename)) {} - virtual ~WriteFileAfterFork() {} + ~WriteFileAfterFork() override {} int operator()() override { return writeFile(std::string("ok"), filename_.c_str()) ? 0 : errno; } @@ -317,8 +318,9 @@ TEST(AfterForkCallbackSubprocessTest, TestAfterForkCallbackError) { } TEST(CommunicateSubprocessTest, SimpleRead) { - Subprocess proc(std::vector{ "/bin/echo", "-n", "foo", "bar"}, - Subprocess::pipeStdout()); + Subprocess proc( + std::vector{"/bin/echo", "-n", "foo", "bar"}, + Subprocess::Options().pipeStdout()); auto p = proc.communicate(); EXPECT_EQ("foo bar", p.first); proc.waitChecked(); @@ -375,7 +377,8 @@ TEST(CommunicateSubprocessTest, Duplex2) { "-e", "s/a test/a successful test/", "-e", "/^another line/w/dev/stderr", }); - auto options = Subprocess::pipeStdin().pipeStdout().pipeStderr().usePath(); + auto options = + Subprocess::Options().pipeStdin().pipeStdout().pipeStderr().usePath(); Subprocess proc(cmd, options); auto out = proc.communicateIOBuf(std::move(input)); proc.waitChecked(); @@ -454,7 +457,7 @@ bool readToString(int fd, std::string& buf, size_t maxSize) { return (n == 0); } -} // namespace +} // namespace TEST(CommunicateSubprocessTest, Chatty) { checkFdLeak([] { @@ -463,7 +466,8 @@ TEST(CommunicateSubprocessTest, Chatty) { int wcount = 0; int rcount = 0; - auto options = Subprocess::pipeStdin().pipeStdout().pipeStderr().usePath(); + auto options = + Subprocess::Options().pipeStdin().pipeStdout().pipeStderr().usePath(); std::vector cmd { "sed", "-u",