@@ -422,21 +422,33 @@ TEST(ProgramTest, TestExecuteNegative) {
422
422
bool ExecutionFailed;
423
423
int RetCode = ExecuteAndWait (Executable, argv, std::nullopt, {}, 0 , 0 ,
424
424
&Error, &ExecutionFailed);
425
+
425
426
EXPECT_LT (RetCode, 0 ) << " On error ExecuteAndWait should return 0 or "
426
427
" positive value indicating the result code" ;
427
- EXPECT_TRUE (ExecutionFailed);
428
428
EXPECT_FALSE (Error.empty ());
429
+
430
+ // Note ExecutionFailed may or may not be false. When using fork, the error
431
+ // is produced on the wait for the child, not the execution point.
429
432
}
430
433
431
434
{
432
435
std::string Error;
433
436
bool ExecutionFailed;
434
437
ProcessInfo PI = ExecuteNoWait (Executable, argv, std::nullopt, {}, 0 ,
435
438
&Error, &ExecutionFailed);
436
- EXPECT_EQ (PI.Pid , ProcessInfo::InvalidPid)
437
- << " On error ExecuteNoWait should return an invalid ProcessInfo" ;
438
- EXPECT_TRUE (ExecutionFailed);
439
- EXPECT_FALSE (Error.empty ());
439
+
440
+ if (ExecutionFailed) {
441
+ EXPECT_EQ (PI.Pid , ProcessInfo::InvalidPid)
442
+ << " On error ExecuteNoWait should return an invalid ProcessInfo" ;
443
+ EXPECT_FALSE (Error.empty ());
444
+ } else {
445
+ std::string WaitErrMsg;
446
+ EXPECT_NE (PI.Pid , ProcessInfo::InvalidPid);
447
+ ProcessInfo WaitPI = Wait (PI, std::nullopt, &WaitErrMsg);
448
+ EXPECT_EQ (WaitPI.Pid , PI.Pid );
449
+ EXPECT_LT (WaitPI.ReturnCode , 0 );
450
+ EXPECT_FALSE (WaitErrMsg.empty ());
451
+ }
440
452
}
441
453
442
454
}
0 commit comments