Files
swift-system/Tests/SystemTests/MockingTest.swift
T
Michael Ilseman d7611ca8ad Internalize SystemInternals
Scrap the separate module SystemInternals and instead have it be a
subdirectory. Adjust all access control accordingly. One day, when Swift gets
proper submodules or supermodules (i.e. resilience domains), we can reinstate
it. For now, a separate module makes binary distribution much more
complicated.
2021-02-25 21:14:46 -07: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
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
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)
}
}