5
5
6
6
import StdlibUnittest
7
7
8
+ #if os(Windows)
9
+ // HACK: It seems that other platforms might be lucky and the stdout and stderr
10
+ // are being sent to the parent process in the order they are used. However, in
11
+ // Windows the result of a print followed by a fatalError is not always ordered
12
+ // the same in the parent. To avoid a random order, we add Sleep(1) before the
13
+ // fatalError calls, which yields enough time to other threads so the output is
14
+ // ordered like in other platforms.
15
+ import WinSDK
16
+ #endif
17
+
8
18
9
19
_setOverrideOSVersion ( . osx( major: 10 , minor: 9 , bugFix: 3 ) )
10
20
_setTestSuiteFailedCallback ( ) { print ( " abort() " ) }
11
21
22
+ private func fatalErrorWithDelayIfNeeded(
23
+ _ message: @autoclosure ( ) -> String = String ( ) ,
24
+ file: StaticString = #file, line: UInt = #line
25
+ ) -> Never {
26
+ #if os(Windows)
27
+ Sleep ( 1 )
28
+ #endif
29
+ fatalError ( message, file: file, line: line)
30
+ }
31
+
12
32
//
13
33
// Test that harness aborts when a test crashes during a test run.
14
34
//
@@ -17,10 +37,10 @@ var TestSuiteCrashes = TestSuite("TestSuiteCrashes")
17
37
18
38
TestSuiteCrashes . test ( " crashesUnexpectedly1 " ) {
19
39
print ( " crashesUnexpectedly1 " )
20
- fatalError ( " This should crash " )
40
+ fatalErrorWithDelayIfNeeded ( " This should crash " )
21
41
}
22
- // CHECK-DAG : stdout>>> crashesUnexpectedly1
23
- // CHECK-DAG : stderr>>> Fatal error: This should crash:
42
+ // CHECK: stdout>>> crashesUnexpectedly1
43
+ // CHECK: stderr>>> Fatal error: This should crash:
24
44
// CHECK: stderr>>> CRASHED: SIG
25
45
// CHECK: [ FAIL ] TestSuiteCrashes.crashesUnexpectedly1
26
46
@@ -41,7 +61,7 @@ TestSuiteCrashes.test("fails1") {
41
61
42
62
TestSuiteCrashes . test ( " crashesUnexpectedly2 " ) {
43
63
print ( " crashesUnexpectedly2 " )
44
- fatalError ( " This should crash " )
64
+ fatalErrorWithDelayIfNeeded ( " This should crash " )
45
65
}
46
66
// CHECK: stdout>>> crashesUnexpectedly2
47
67
// CHECK: stderr>>> Fatal error: This should crash:
@@ -66,7 +86,7 @@ TestSuiteCrashes.test("fails2") {
66
86
TestSuiteCrashes . test ( " crashesAsExpected1 " ) {
67
87
print ( " crashesAsExpected1 " )
68
88
expectCrashLater ( )
69
- fatalError ( " This should crash " )
89
+ fatalErrorWithDelayIfNeeded ( " This should crash " )
70
90
}
71
91
// CHECK: stdout>>> crashesAsExpected1
72
92
// CHECK: stderr>>> Fatal error: This should crash:
@@ -91,7 +111,7 @@ TestSuiteCrashes.test("fails3") {
91
111
TestSuiteCrashes . test ( " crashesUnexpectedlyXfail " )
92
112
. xfail ( . osxBugFix( 10 , 9 , 3 , reason: " " ) ) . code {
93
113
print ( " crashesUnexpectedlyXfail " )
94
- fatalError ( " This should crash " )
114
+ fatalErrorWithDelayIfNeeded ( " This should crash " )
95
115
}
96
116
// CHECK: stdout>>> crashesUnexpectedlyXfail
97
117
// CHECK: stderr>>> Fatal error: This should crash:
@@ -102,7 +122,7 @@ TestSuiteCrashes.test("crashesAsExpectedXfail")
102
122
. xfail ( . osxBugFix( 10 , 9 , 3 , reason: " " ) ) . code {
103
123
print ( " crashesAsExpectedXfail " )
104
124
expectCrashLater ( )
105
- fatalError ( " This should crash " )
125
+ fatalErrorWithDelayIfNeeded ( " This should crash " )
106
126
}
107
127
// CHECK: stdout>>> crashesAsExpectedXfail
108
128
// CHECK: stderr>>> Fatal error: This should crash:
@@ -113,7 +133,7 @@ TestSuiteCrashes.test("crashesWithMessagePasses")
113
133
. crashOutputMatches ( " This should crash " ) . code {
114
134
print ( " abcd " )
115
135
expectCrashLater ( )
116
- fatalError ( " This should crash " )
136
+ fatalErrorWithDelayIfNeeded ( " This should crash " )
117
137
}
118
138
// CHECK: stdout>>> abcd
119
139
// CHECK: stderr>>> Fatal error: This should crash:
@@ -124,7 +144,7 @@ TestSuiteCrashes.test("crashesWithMessageFails")
124
144
. crashOutputMatches ( " This should crash " ) . code {
125
145
print ( " This should crash " )
126
146
expectCrashLater ( )
127
- fatalError ( " unexpected message " )
147
+ fatalErrorWithDelayIfNeeded ( " unexpected message " )
128
148
}
129
149
// CHECK: stdout>>> This should crash
130
150
// CHECK: stderr>>> Fatal error: unexpected message:
@@ -139,7 +159,7 @@ TestSuiteCrashes.test("crashesWithMultipleMessagesPasses")
139
159
. code {
140
160
print ( " abcd " )
141
161
expectCrashLater ( )
142
- fatalError ( " This should crash and your little dog too " )
162
+ fatalErrorWithDelayIfNeeded ( " This should crash and your little dog too " )
143
163
}
144
164
// CHECK: stdout>>> abcd
145
165
// CHECK: stderr>>> Fatal error: This should crash and your little dog too:
@@ -154,7 +174,7 @@ TestSuiteCrashes.test("crashesWithMultipleMessagesFails")
154
174
. code {
155
175
print ( " This should crash " )
156
176
expectCrashLater ( )
157
- fatalError ( " unexpected message and your little dog too " )
177
+ fatalErrorWithDelayIfNeeded ( " unexpected message and your little dog too " )
158
178
}
159
179
// CHECK: stdout>>> This should crash
160
180
// CHECK: stderr>>> Fatal error: unexpected message and your little dog too:
0 commit comments