Files
swift-system/Tests/SystemTests/MockingTest.swift
Karoy Lorentey 1daa0c9677 Unify availability annotations and synchronize them with macOS 12 / iOS 15
Availability annotations now follow a rigid syntax that mentions the swift-system version that introduced the entry point:

```
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
public func greeting() -> String {
  "Hello"
}
```

This is designed to be processed by automated source generation tools.
2021-12-20 17:10:59 -08:00

51 lines
1.5 KiB
Swift

/*
This source file is part of the Swift System open source project
Copyright (c) 2020 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
*/
import XCTest
#if SYSTEM_PACKAGE
@testable import SystemPackage
#else
@testable import System
#endif
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
final class MockingTest: XCTestCase {
func testMocking() {
XCTAssertFalse(mockingEnabled)
MockingDriver.withMockingEnabled { driver in
XCTAssertTrue(mockingEnabled)
XCTAssertTrue(driver === currentMockingDriver)
XCTAssertEqual(driver.forceErrno, .none)
let forced = ForceErrno.always(errno: 42)
driver.forceErrno = forced
XCTAssertEqual(driver.forceErrno, forced)
// Test that a nested call swaps in a new driver and restores the old one after
MockingDriver.withMockingEnabled { nestedDriver in
XCTAssertTrue(mockingEnabled)
XCTAssertTrue(nestedDriver === currentMockingDriver)
XCTAssertFalse(nestedDriver === driver)
XCTAssertEqual(nestedDriver.forceErrno, .none)
}
XCTAssertTrue(mockingEnabled)
XCTAssertEqual(driver.forceErrno, forced)
}
XCTAssertFalse(mockingEnabled)
// Mocking should be enabled even if we do not refer to the driver
MockingDriver.withMockingEnabled { _ in
XCTAssertTrue(mockingEnabled)
}
XCTAssertFalse(mockingEnabled)
}
}