Make ProcessReturnCode default-constructible
authorAlexey Spiridonov <lesha@fb.com>
Mon, 27 Jul 2015 02:36:57 +0000 (19:36 -0700)
committerfacebook-github-bot-4 <folly-bot@fb.com>
Mon, 27 Jul 2015 03:22:13 +0000 (20:22 -0700)
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

folly/Subprocess.h
folly/test/SubprocessTest.cpp

index 0354b4b21e56d11450fbd2db98fc41650ac33de4..4f970082fee6485f48e8b5398056ea166a87f1dc 100644 (file)
@@ -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;
index b42a0d57d27d99588fc5e8fba2b46bc720c23d81..724dbd2407620fd80847a242ea6371a31a3a2eac 100644 (file)
@@ -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());