 @objc(QCKSpecRunner)
 @objcMembers
 class QuickSpecRunner: NSObject {
-    static func runSpec(_ specClass: QuickSpec.Type) -> TestRun? {
+    static func runSpec(_ specClass: QuickSpec.Type) -> XCTestRun? {
         return qck_runSpec(specClass)
     }
 
-    static func runSpecs(_ specClasses: [QuickSpec.Type]) -> TestRun? {
+    static func runSpecs(_ specClasses: [QuickSpec.Type]) -> XCTestRun? {
         return qck_runSpecs(specClasses)
     }
 }

 @return An XCTestRun instance that contains information such as the number of failures, etc.
 */
@discardableResult
func qck_runSpecs(_ specClasses: [QuickSpec.Type]) -> TestRun? {
    return World.anotherWorld { world -> TestRun? in
        QuickConfiguration.configureSubclassesIfNeeded(world: world)

        world.isRunningAdditionalSuites = true
        defer { world.isRunningAdditionalSuites = false }

        #if canImport(Darwin)
        let suite = XCTestSuite(name: "MySpecs")
        for specClass in specClasses {
            let test = specClass.defaultTestSuite
            suite.addTest(test)
        }

        let result: TestRun? = XCTestObservationCenter.shared.qck_suspendObservation {
            suite.run()
            return suite.testRun
        }
        return result
        #else
        let result: TestRun = XCTestObservationCenter.shared.qck_suspendObservation {
            var executionCount: UInt = 0
            var hadUnexpectedFailure = false

            let fails = gatherFailingExpectations(silently: true) {
                for specClass in specClasses {
                    for (_, test) in specClass.allTests {
                        do {
                            try test(specClass.init())()
                        } catch {
                            hadUnexpectedFailure = true
                        }
                        executionCount += 1
                    }
                }
            }

            return TestRun(executionCount: executionCount, hasSucceeded: fails.isEmpty && !hadUnexpectedFailure)
        }
        return result
        #endif
    }
}


import Foundation
import XCTest
@testable import Quick

#if !canImport(Darwin)
// Based on https://github.com/apple/swift-corelibs-xctest/blob/51afda0bc782b2d6a2f00fbdca58943faf6ccecd/Sources/XCTest/Private/XCTestCaseSuite.swift#L14-L42
private final class TestCaseSuite: XCTestSuite {
    let specClass: QuickSpec.Type

    init(specClass: QuickSpec.Type) {
        self.specClass = specClass
        super.init(name: String(describing: specClass))

        for (testName, testClosure) in specClass.allTests {
            let testCase = specClass.init(name: testName, testClosure: { testCase in
                // swiftlint:disable:next force_cast
                try testClosure(testCase as! QuickSpec)()
            })
            addTest(testCase)
        }
    }

    override func setUp() {
        specClass.setUp()
    }

    override func tearDown() {
        specClass.tearDown()
    }
}
#endif

