mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-29 08:42:51 +00:00
Add check to see if running unit tests. This will allow us to skip certain work (like syncing) when running unit tests. Also useful later for self-mocking.
This commit is contained in:
1 parent
b5e3041489
commit
4e9f29d54b
1 file changed
+28
@@ -13,6 +13,34 @@ public enum Platform {
|
||||
|
||||
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "Platform")
|
||||
|
||||
/// Returns true if the app is currently running unit tests.
|
||||
public static var isRunningUnitTests: Bool {
|
||||
return _isRunningUnitTests
|
||||
}
|
||||
|
||||
private static let _isRunningUnitTests: Bool = {
|
||||
// Check multiple indicators to be super-reliable
|
||||
let environment = ProcessInfo.processInfo.environment
|
||||
|
||||
// XCTest sets this environment variable
|
||||
if environment["XCTestConfigurationFilePath"] != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check if XCTest framework is loaded
|
||||
if NSClassFromString("XCTestCase") != nil {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check command line arguments for test-related flags
|
||||
let arguments = ProcessInfo.processInfo.arguments
|
||||
if arguments.contains("-XCTest") || arguments.contains("test") {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}()
|
||||
|
||||
/// Get the path to a subfolder of the application's data folder (often `Application Support`).
|
||||
/// - Parameters:
|
||||
/// - appName: The name of the application.
|
||||
|
||||
Reference in new issue
Block a user