@@ -839,7 +839,7 @@ func _childProcess() {
839
839
var stderr = _Stderr ( )
840
840
print ( " \( _stdlibUnittestStreamPrefix) ;end " , to: & stderr)
841
841
842
- if ! testSuite. _testByName ( testName) . canReuseChildProcessAfterTest {
842
+ if testSuite. _shouldShutDownChildProcess ( forTestNamed : testName) {
843
843
return
844
844
}
845
845
}
@@ -1107,7 +1107,7 @@ class _ParentProcess {
1107
1107
// Check if the child has sent us "end" markers for the current test.
1108
1108
if stdoutEnd && stderrEnd {
1109
1109
var status : ProcessTerminationStatus ?
1110
- if ! testSuite. _testByName ( testName) . canReuseChildProcessAfterTest {
1110
+ if testSuite. _shouldShutDownChildProcess ( forTestNamed : testName) {
1111
1111
status = _waitForChild ( )
1112
1112
switch status! {
1113
1113
case . exit( 0 ) :
@@ -1147,7 +1147,11 @@ class _ParentProcess {
1147
1147
return ( failed: false , ( ) )
1148
1148
}
1149
1149
#endif
1150
- print ( " \( _stdlibUnittestStreamPrefix) ;shutdown " , to: & _childStdin)
1150
+ // If the child process expects an EOF, its stdin fd has already been closed and
1151
+ // it will shut itself down automatically.
1152
+ if !_childStdin. isClosed {
1153
+ print ( " \( _stdlibUnittestStreamPrefix) ;shutdown " , to: & _childStdin)
1154
+ }
1151
1155
1152
1156
var childCrashed = false
1153
1157
@@ -1209,6 +1213,9 @@ class _ParentProcess {
1209
1213
if t. stdinText != nil {
1210
1214
print ( " The test \( fullTestName) requires stdin input and can't be run in-process, marking as failed " )
1211
1215
_anyExpectFailed = true
1216
+ } else if t. requiresOwnProcess {
1217
+ print ( " The test \( fullTestName) requires running in a child process and can't be run in-process, marking as failed. " )
1218
+ _anyExpectFailed = true
1212
1219
} else {
1213
1220
_anyExpectFailed = false
1214
1221
testSuite. _runTest ( name: t. name, parameter: testParameter)
@@ -1550,6 +1557,17 @@ public final class TestSuite {
1550
1557
return _tests [ _testNameToIndex [ testName] !]
1551
1558
}
1552
1559
1560
+ /// Determines if we should shut down the current test process, i.e. if this
1561
+ /// test or the next test requires executing in its own process.
1562
+ func _shouldShutDownChildProcess( forTestNamed testName: String ) -> Bool {
1563
+ let index = _testNameToIndex [ testName] !
1564
+ if index == _tests. count - 1 { return false }
1565
+ let currentTest = _tests [ index]
1566
+ let nextTest = _tests [ index + 1 ]
1567
+ if !currentTest. canReuseChildProcessAfterTest { return true }
1568
+ return currentTest. requiresOwnProcess || nextTest. requiresOwnProcess
1569
+ }
1570
+
1553
1571
internal enum _TestCode {
1554
1572
case single( code: ( ) -> Void )
1555
1573
case parameterized( code: ( Int ) -> Void , count: Int )
@@ -1564,6 +1582,7 @@ public final class TestSuite {
1564
1582
let stdinEndsWithEOF : Bool
1565
1583
let crashOutputMatches : [ String ]
1566
1584
let code : _TestCode
1585
+ let requiresOwnProcess : Bool
1567
1586
1568
1587
/// Whether the test harness should stop reusing the child process after
1569
1588
/// running this test.
@@ -1601,6 +1620,7 @@ public final class TestSuite {
1601
1620
var _stdinEndsWithEOF : Bool = false
1602
1621
var _crashOutputMatches : [ String ] = [ ]
1603
1622
var _testLoc : SourceLoc ?
1623
+ var _requiresOwnProcess : Bool = false
1604
1624
}
1605
1625
1606
1626
init ( testSuite: TestSuite , name: String , loc: SourceLoc ) {
@@ -1630,6 +1650,11 @@ public final class TestSuite {
1630
1650
return self
1631
1651
}
1632
1652
1653
+ public func requireOwnProcess( ) -> _TestBuilder {
1654
+ _data. _requiresOwnProcess = true
1655
+ return self
1656
+ }
1657
+
1633
1658
internal func _build( _ testCode: _TestCode ) {
1634
1659
_testSuite. _tests. append (
1635
1660
_Test (
@@ -1638,7 +1663,8 @@ public final class TestSuite {
1638
1663
stdinText: _data. _stdinText,
1639
1664
stdinEndsWithEOF: _data. _stdinEndsWithEOF,
1640
1665
crashOutputMatches: _data. _crashOutputMatches,
1641
- code: testCode) )
1666
+ code: testCode,
1667
+ requiresOwnProcess: _data. _requiresOwnProcess) )
1642
1668
_testSuite. _testNameToIndex [ _name] = _testSuite. _tests. count - 1
1643
1669
}
1644
1670
0 commit comments