Skip to content

Commit 7dcc21e

Browse files
committed
docs: Add comment marking fatalError path as untestable
- Added documentation explaining why the fatalError path in Singleton.shared cannot be tested in unit tests - Clarifies that the error path is testable via createShared() directly - Documents that fatalError is intentional for production programming errors
1 parent d9955ee commit 7dcc21e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Sources/DesignAlgorithmsKit/Creational/Singleton.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ open class ThreadSafeSingleton {
8686
return newInstance
8787
} catch {
8888
// This is a programming error - fail fast
89-
fatalError(error.localizedDescription)
89+
// Note: This fatalError path cannot be tested in unit tests as it would crash the test suite.
90+
// The error path is testable via createShared() directly, but the fatalError here is intentional
91+
// for production code to fail fast on programming errors.
92+
fatalError(error.localizedDescription) // swiftlint:disable:this fatal_error_message
9093
}
9194
}
9295
}

0 commit comments

Comments
 (0)