Skip to content

Commit 62041e6

Browse files
Soften app host failure message (#50)
* Soften app host failure message The way we detect app hosts triggers more often than we expected, especially in async tests, so let's make it sound a bit more informational instead of a loud warning that makes the false positive sound more definitive. * wip * Update XCTFail.swift --------- Co-authored-by: Brandon Williams <[email protected]>
1 parent f239923 commit 62041e6

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

Sources/XCTestDynamicOverlay/XCTFail.swift

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,36 +76,20 @@ import Foundation
7676
guard callStack.allSatisfy({ frame in !isTestFrame(frame) })
7777
else { return }
7878

79-
let displayName =
80-
Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String
81-
?? Bundle.main.object(forInfoDictionaryKey: kCFBundleNameKey as String) as? String
82-
?? "Unknown host application"
83-
84-
let bundleIdentifier = Bundle.main.bundleIdentifier ?? "Unknown bundle identifier"
85-
8679
if !message.contains(where: \.isNewline) {
8780
message.append("")
8881
}
8982

9083
message.append(
9184
"""
9285
86+
87+
━━┉┅
88+
Note: This failure was emitted from tests running in a host application\
89+
\(Bundle.main.bundleIdentifier.map { " (\($0))" }).
9390
94-
┏━━━━━━━━━━━━━━━━━┉┅
95-
┃ ⚠︎ Warning:
96-
97-
┃ This failure was emitted from a host application outside the test stack.
98-
99-
┃ Host application:
100-
\(displayName) (\(bundleIdentifier))
101-
102-
┃ The host application may have emitted this failure when it first launched,
103-
┃ outside this current test that happens to be running.
104-
105-
┃ Consider setting the test target's host application to "None," or prevent
106-
┃ the host application from performing the code path that emits failure.
107-
┗━━━━━━━━━━━━━━━━━┉┅
108-
▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄
91+
This can lead to false positives, where failures could have emitted from live application \
92+
code at launch time, and not from the current test.
10993
11094
For more information (and workarounds), see "Testing gotchas":
11195

0 commit comments

Comments
 (0)