Commit 3f277b37 authored by Alexey Spiridonov's avatar Alexey Spiridonov Committed by facebook-github-bot-4

Make ProcessReturnCode default-constructible

Summary: We have this previously-unused "NOT STARTED" status, which I recently appropriated to denote moved-out `ProcessReturnCode`s.

It's natural to also use this for default-constructed `ProcessReturnCodes`. Lacking a default constructor leads to a bunch of unnecessarily annoying use of `folly::Optional` in my upcoming diff, so I wanted to get rid of that, see e.g.

differential/diff/7657906/

Reviewed By: @tudor

Differential Revision: D2097368
parent b10e3e86
...@@ -126,12 +126,18 @@ class ProcessReturnCode { ...@@ -126,12 +126,18 @@ class ProcessReturnCode {
friend class Subprocess; friend class Subprocess;
public: public:
enum State { enum State {
// Subprocess starts in the constructor, so this state designates only
// default-initialized or moved-out ProcessReturnCodes.
NOT_STARTED, NOT_STARTED,
RUNNING, RUNNING,
EXITED, EXITED,
KILLED KILLED
}; };
// Default-initialized for convenience. Subprocess::returnCode() will
// never produce this value.
ProcessReturnCode() : ProcessReturnCode(RV_NOT_STARTED) {}
// Trivially copyable // Trivially copyable
ProcessReturnCode(const ProcessReturnCode& p) = default; ProcessReturnCode(const ProcessReturnCode& p) = default;
ProcessReturnCode& operator=(const ProcessReturnCode& p) = default; ProcessReturnCode& operator=(const ProcessReturnCode& p) = default;
......
...@@ -56,6 +56,11 @@ TEST(SimpleSubprocessTest, ExitsWithErrorChecked) { ...@@ -56,6 +56,11 @@ TEST(SimpleSubprocessTest, ExitsWithErrorChecked) {
EXPECT_THROW(proc.waitChecked(), CalledProcessError); EXPECT_THROW(proc.waitChecked(), CalledProcessError);
} }
TEST(SimpleSubprocessTest, DefaultConstructibleProcessReturnCode) {
ProcessReturnCode retcode;
EXPECT_TRUE(retcode.notStarted());
}
TEST(SimpleSubprocessTest, MoveSubprocess) { TEST(SimpleSubprocessTest, MoveSubprocess) {
Subprocess old_proc(std::vector<std::string>{ "/bin/true" }); Subprocess old_proc(std::vector<std::string>{ "/bin/true" });
EXPECT_TRUE(old_proc.returnCode().running()); EXPECT_TRUE(old_proc.returnCode().running());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment