Skip to content

[windows][test] Ensure the ordering of stdout and stderr messages. #26317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions validation-test/StdlibUnittest/CrashingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,30 @@

import StdlibUnittest

#if os(Windows)
// HACK: It seems that other platforms might be lucky and the stdout and stderr
// are being sent to the parent process in the order they are used. However, in
// Windows the result of a print followed by a fatalError is not always ordered
// the same in the parent. To avoid a random order, we add Sleep(1) before the
// fatalError calls, which yields enough time to other threads so the output is
// ordered like in other platforms.
import WinSDK
#endif


_setOverrideOSVersion(.osx(major: 10, minor: 9, bugFix: 3))
_setTestSuiteFailedCallback() { print("abort()") }

private func fatalErrorWithDelayIfNeeded(
_ message: @autoclosure () -> String = String(),
file: StaticString = #file, line: UInt = #line
) -> Never {
#if os(Windows)
Sleep(1)
#endif
fatalError(message, file: file, line: line)
}

//
// Test that harness aborts when a test crashes during a test run.
//
Expand All @@ -17,10 +37,10 @@ var TestSuiteCrashes = TestSuite("TestSuiteCrashes")

TestSuiteCrashes.test("crashesUnexpectedly1") {
print("crashesUnexpectedly1")
fatalError("This should crash")
fatalErrorWithDelayIfNeeded("This should crash")
}
// CHECK-DAG: stdout>>> crashesUnexpectedly1
// CHECK-DAG: stderr>>> Fatal error: This should crash:
// CHECK: stdout>>> crashesUnexpectedly1
// CHECK: stderr>>> Fatal error: This should crash:
// CHECK: stderr>>> CRASHED: SIG
// CHECK: [ FAIL ] TestSuiteCrashes.crashesUnexpectedly1

Expand All @@ -41,7 +61,7 @@ TestSuiteCrashes.test("fails1") {

TestSuiteCrashes.test("crashesUnexpectedly2") {
print("crashesUnexpectedly2")
fatalError("This should crash")
fatalErrorWithDelayIfNeeded("This should crash")
}
// CHECK: stdout>>> crashesUnexpectedly2
// CHECK: stderr>>> Fatal error: This should crash:
Expand All @@ -66,7 +86,7 @@ TestSuiteCrashes.test("fails2") {
TestSuiteCrashes.test("crashesAsExpected1") {
print("crashesAsExpected1")
expectCrashLater()
fatalError("This should crash")
fatalErrorWithDelayIfNeeded("This should crash")
}
// CHECK: stdout>>> crashesAsExpected1
// CHECK: stderr>>> Fatal error: This should crash:
Expand All @@ -91,7 +111,7 @@ TestSuiteCrashes.test("fails3") {
TestSuiteCrashes.test("crashesUnexpectedlyXfail")
.xfail(.osxBugFix(10, 9, 3, reason: "")).code {
print("crashesUnexpectedlyXfail")
fatalError("This should crash")
fatalErrorWithDelayIfNeeded("This should crash")
}
// CHECK: stdout>>> crashesUnexpectedlyXfail
// CHECK: stderr>>> Fatal error: This should crash:
Expand All @@ -102,7 +122,7 @@ TestSuiteCrashes.test("crashesAsExpectedXfail")
.xfail(.osxBugFix(10, 9, 3, reason: "")).code {
print("crashesAsExpectedXfail")
expectCrashLater()
fatalError("This should crash")
fatalErrorWithDelayIfNeeded("This should crash")
}
// CHECK: stdout>>> crashesAsExpectedXfail
// CHECK: stderr>>> Fatal error: This should crash:
Expand All @@ -113,7 +133,7 @@ TestSuiteCrashes.test("crashesWithMessagePasses")
.crashOutputMatches("This should crash").code {
print("abcd")
expectCrashLater()
fatalError("This should crash")
fatalErrorWithDelayIfNeeded("This should crash")
}
// CHECK: stdout>>> abcd
// CHECK: stderr>>> Fatal error: This should crash:
Expand All @@ -124,7 +144,7 @@ TestSuiteCrashes.test("crashesWithMessageFails")
.crashOutputMatches("This should crash").code {
print("This should crash")
expectCrashLater()
fatalError("unexpected message")
fatalErrorWithDelayIfNeeded("unexpected message")
}
// CHECK: stdout>>> This should crash
// CHECK: stderr>>> Fatal error: unexpected message:
Expand All @@ -139,7 +159,7 @@ TestSuiteCrashes.test("crashesWithMultipleMessagesPasses")
.code {
print("abcd")
expectCrashLater()
fatalError("This should crash and your little dog too")
fatalErrorWithDelayIfNeeded("This should crash and your little dog too")
}
// CHECK: stdout>>> abcd
// CHECK: stderr>>> Fatal error: This should crash and your little dog too:
Expand All @@ -154,7 +174,7 @@ TestSuiteCrashes.test("crashesWithMultipleMessagesFails")
.code {
print("This should crash")
expectCrashLater()
fatalError("unexpected message and your little dog too")
fatalErrorWithDelayIfNeeded("unexpected message and your little dog too")
}
// CHECK: stdout>>> This should crash
// CHECK: stderr>>> Fatal error: unexpected message and your little dog too:
Expand Down