Skip to content

Commit 8e1de85

Browse files
authored
Make XCTMain test observations configurable
Currently, XCTest uses `PrintObserver` as a default observation. While it is possible to add other custom observations through `XCTestObservationCenter.shared.addTestObserver`, it doesn't prevent the default `PrintObserver` from printing the default output. In certain situations this is undesirable, especially when you'd like to get a custom observation output through stdout. This change allows passing a custom observation through a third new argument to `XCTMain` to replace the default observation. The existing two-argument overload is still available, so this doesn't have any impact on existing users.
1 parent d05886a commit 8e1de85

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Sources/XCTest/Public/XCTestMain.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,16 @@
6262
public func XCTMain(_ testCases: [XCTestCaseEntry]) -> Never {
6363
XCTMain(testCases, arguments: CommandLine.arguments)
6464
}
65+
6566
public func XCTMain(_ testCases: [XCTestCaseEntry], arguments: [String]) -> Never {
67+
XCTMain(testCases, arguments: arguments, observation: PrintObserver())
68+
}
69+
70+
public func XCTMain(
71+
_ testCases: [XCTestCaseEntry],
72+
arguments: [String],
73+
observation: XCTestObservation
74+
) -> Never {
6675
let testBundle = Bundle.main
6776

6877
let executionMode = ArgumentParser(arguments: arguments).executionMode
@@ -128,7 +137,7 @@ public func XCTMain(_ testCases: [XCTestCaseEntry], arguments: [String]) -> Neve
128137
case .run(selectedTestNames: _):
129138
// Add a test observer that prints test progress to stdout.
130139
let observationCenter = XCTestObservationCenter.shared
131-
observationCenter.addTestObserver(PrintObserver())
140+
observationCenter.addTestObserver(observation)
132141

133142
observationCenter.testBundleWillStart(testBundle)
134143
rootTestSuite.run()

0 commit comments

Comments
 (0)