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 {
friend class Subprocess;
public:
enum State {
// Subprocess starts in the constructor, so this state designates only
// default-initialized or moved-out ProcessReturnCodes.
NOT_STARTED,
RUNNING,
EXITED,
KILLED
};
// Default-initialized for convenience. Subprocess::returnCode() will
// never produce this value.
ProcessReturnCode() : ProcessReturnCode(RV_NOT_STARTED) {}
// Trivially copyable
ProcessReturnCode(const ProcessReturnCode& p) = default;
ProcessReturnCode& operator=(const ProcessReturnCode& p) = default;
......
......@@ -56,6 +56,11 @@ TEST(SimpleSubprocessTest, ExitsWithErrorChecked) {
EXPECT_THROW(proc.waitChecked(), CalledProcessError);
}
TEST(SimpleSubprocessTest, DefaultConstructibleProcessReturnCode) {
ProcessReturnCode retcode;
EXPECT_TRUE(retcode.notStarted());
}
TEST(SimpleSubprocessTest, MoveSubprocess) {
Subprocess old_proc(std::vector<std::string>{ "/bin/true" });
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