|
1 | 1 | import XCTest
|
2 | 2 |
|
3 |
| -#if !canImport(ObjectiveC) |
4 |
| -public func allTests() -> [XCTestCaseEntry] { |
| 3 | +public func allTests() -> [Linux.TestCase] { |
5 | 4 | return [
|
6 |
| - testCase(BinaryKitTests.allTests), |
| 5 | + Linux.makeTestCase(using: BinaryKitTests.allTests), |
7 | 6 | ]
|
8 | 7 | }
|
| 8 | + |
| 9 | +#if canImport(ObjectiveC) |
| 10 | +internal final class LinuxVerificationTests: XCTestCase { |
| 11 | + func testAllTestsRunOnLinux() { |
| 12 | + Linux.testAllTestsRunOnLinux(allTests: allTests()) |
| 13 | + } |
| 14 | +} |
9 | 15 | #endif
|
| 16 | + |
| 17 | +public enum Linux {} |
| 18 | + |
| 19 | +public extension Linux { |
| 20 | + typealias TestCase = (testCaseClass: XCTestCase.Type, allTests: TestManifest) |
| 21 | + typealias TestManifest = [(String, TestRunner)] |
| 22 | + typealias TestRunner = (XCTestCase) throws -> Void |
| 23 | + typealias TestList<T: XCTestCase> = [(String, Test<T>)] |
| 24 | + typealias Test<T: XCTestCase> = (T) -> () throws -> Void |
| 25 | +} |
| 26 | + |
| 27 | +extension Linux { |
| 28 | + static func makeTestCase<T: XCTestCase>(using list: TestList<T>) -> TestCase { |
| 29 | + let manifest: TestManifest = list.map { name, function in |
| 30 | + (name, { type in |
| 31 | + try function(type as! T)() |
| 32 | + }) |
| 33 | + } |
| 34 | + |
| 35 | + return (T.self, manifest) |
| 36 | + } |
| 37 | + |
| 38 | + #if canImport(ObjectiveC) |
| 39 | + static func testAllTestsRunOnLinux(allTests: [Linux.TestCase]) { |
| 40 | + for testCase in allTests { |
| 41 | + let type = testCase.testCaseClass |
| 42 | + |
| 43 | + let testNames: [String] = type.defaultTestSuite.tests.map { test in |
| 44 | + let components = test.name.components(separatedBy: .whitespaces) |
| 45 | + return components[1].replacingOccurrences(of: "]", with: "") |
| 46 | + } |
| 47 | + |
| 48 | + let linuxTestNames = Set(testCase.allTests.map { $0.0 }) |
| 49 | + |
| 50 | + for name in testNames { |
| 51 | + if !linuxTestNames.contains(name) { |
| 52 | + XCTFail(""" |
| 53 | + \(type).\(name) does not run on Linux. |
| 54 | + Please add it to \(type).allTests. |
| 55 | + """) |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + #endif |
| 61 | +} |
0 commit comments