1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//
// XCAbstractTest.swift
// An abstract base class that XCTestCase and XCTestSuite inherit from.
// The purpose of this class is to mirror the design of Apple XCTest.
//
/// An abstract base class for testing. `XCTestCase` and `XCTestSuite` extend
/// `XCTest` to provide for creating, managing, and executing tests. Most
/// developers will not need to subclass `XCTest` directly.
open class XCTest {
/// Test's name. Must be overridden by subclasses.
open var name: String {
fatalError("Must be overridden by subclasses.")
}
/// Number of test cases. Must be overridden by subclasses.
open var testCaseCount: Int {
fatalError("Must be overridden by subclasses.")
}
/// The `XCTestRun` subclass that will be instantiated when the test is run
/// to hold the test's results. Must be overridden by subclasses.
open var testRunClass: AnyClass? {
fatalError("Must be overridden by subclasses.")
}
/// The test run object that executed the test, an instance of
/// testRunClass. If the test has not yet been run, this will be nil.
open private(set) var testRun: XCTestRun? = nil
#if DISABLE_XCTWAITER
internal var performTask: Task<Void, Never>?
internal func _performAsync(_ run: XCTestRun) async {
fatalError("Must be overridden by subclasses.")
}
internal func _runAsync() async {
guard let testRunType = testRunClass as? XCTestRun.Type else {
fatalError("XCTest.testRunClass must be a kind of XCTestRun.")
}
testRun = testRunType.init(test: self)
await _performAsync(testRun!)
}
#endif
/// The method through which tests are executed. Must be overridden by
/// subclasses.
#if DISABLE_XCTWAITER
@available(*, unavailable)
#endif
open func perform(_ run: XCTestRun) {
fatalError("Must be overridden by subclasses.")
}
/// Creates an instance of the `testRunClass` and passes it as a parameter
/// to `perform()`.
#if DISABLE_XCTWAITER
@available(*, unavailable)
#endif
open func run() {
#if !DISABLE_XCTWAITER
guard let testRunType = testRunClass as? XCTestRun.Type else {
fatalError("XCTest.testRunClass must be a kind of XCTestRun.")
}
testRun = testRunType.init(test: self)
perform(testRun!)
#endif
}
/// Async setup method called before the invocation of `setUpWithError` for each test method in the class.
@available(macOS 12.0, *)
open func setUp() async throws {}
/// Setup method called before the invocation of `setUp` and the test method
/// for each test method in the class.
open func setUpWithError() throws {}
/// Setup method called before the invocation of each test method in the
/// class.
open func setUp() {}
/// Teardown method called after the invocation of each test method in the
/// class.
open func tearDown() {}
/// Teardown method called after the invocation of the test method and `tearDown`
/// for each test method in the class.
open func tearDownWithError() throws {}
/// Async teardown method which is called after the invocation of `tearDownWithError`
/// for each test method in the class.
@available(macOS 12.0, *)
open func tearDown() async throws {}
// FIXME: This initializer is required due to a Swift compiler bug on Linux.
// It should be removed once the bug is fixed.
public init() {}
}
|