forked from JohnSundell/Plot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinuxCompatibility.swift
55 lines (46 loc) · 1.59 KB
/
LinuxCompatibility.swift
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
/**
* Plot
* Copyright (c) John Sundell 2019
* MIT license, see LICENSE file for details
*/
import XCTest
public enum Linux {}
public extension Linux {
typealias TestCase = (testCaseClass: XCTestCase.Type, allTests: TestManifest)
typealias TestManifest = [(String, TestRunner)]
typealias TestRunner = (XCTestCase) throws -> Void
typealias TestList<T: XCTestCase> = [(String, Test<T>)]
typealias Test<T: XCTestCase> = (T) -> () throws -> Void
}
internal extension Linux {
static func makeTestCase<T: XCTestCase>(using list: TestList<T>) -> TestCase {
let manifest: TestManifest = list.map { name, function in
(name, { type in
try function(type as! T)()
})
}
return (T.self, manifest)
}
}
#if canImport(ObjectiveC)
internal final class LinuxVerificationTests: XCTestCase {
func testAllTestsRunOnLinux() {
for testCase in allTests() {
let type = testCase.testCaseClass
let testNames: [String] = type.defaultTestSuite.tests.map { test in
let components = test.name.components(separatedBy: .whitespaces)
return components[1].replacingOccurrences(of: "]", with: "")
}
let linuxTestNames = Set(testCase.allTests.map { $0.0 })
for name in testNames {
if !linuxTestNames.contains(name) {
XCTFail("""
\(type).\(name) does not run on Linux.
Please add it to \(type).allTests.
""")
}
}
}
}
}
#endif