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
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;
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());