Skip to content

Commit fa4b650

Browse files
authored
Merge pull request #19 from wacumov/master
Ensure that all test cases run on Linux and setup CI
2 parents 9e89a33 + ef67d49 commit fa4b650

File tree

3 files changed

+85
-4
lines changed

3 files changed

+85
-4
lines changed

.github/workflows/UnitTests.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: UnitTests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
test_on_macos:
10+
runs-on: macos-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Build
14+
run: swift build
15+
- name: Test
16+
run: swift test
17+
test_on_linux:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Build
22+
run: swift build
23+
- name: Test
24+
run: swift test

Tests/BinaryKitTests/BinaryKitTests.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ final class BinaryKitTests: XCTestCase {
328328

329329
// MARK: -
330330

331-
static var allTests = [
331+
static var allTests: Linux.TestList<BinaryKitTests> = [
332332
("testBitIndex", testBitIndex),
333333
("testBit", testBit),
334334
("testBits", testBits),
@@ -337,9 +337,14 @@ final class BinaryKitTests: XCTestCase {
337337
("testByteIndex", testByteIndex),
338338
("testBytes", testBytes),
339339
("testBytesRange", testBytesRange),
340+
("testMixedReadByte", testMixedReadByte),
341+
("testMixedReadBytes", testMixedReadBytes),
342+
("testReadBytesThrowsBeforeReading", testReadBytesThrowsBeforeReading),
343+
("testReadBitsThrowsBeforeReading", testReadBitsThrowsBeforeReading),
340344
("testHexInit", testHexInit),
341345
("testNibble", testNibble),
342346
("testStringAndCharacter", testStringAndCharacter),
347+
("testBool", testBool),
343348
("testFinders", testFinders),
344349
("testWrite", testWrite),
345350
("testWriteInt", testWriteInt),
+55-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,61 @@
11
import XCTest
22

3-
#if !canImport(ObjectiveC)
4-
public func allTests() -> [XCTestCaseEntry] {
3+
public func allTests() -> [Linux.TestCase] {
54
return [
6-
testCase(BinaryKitTests.allTests),
5+
Linux.makeTestCase(using: BinaryKitTests.allTests),
76
]
87
}
8+
9+
#if canImport(ObjectiveC)
10+
internal final class LinuxVerificationTests: XCTestCase {
11+
func testAllTestsRunOnLinux() {
12+
Linux.testAllTestsRunOnLinux(allTests: allTests())
13+
}
14+
}
915
#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

Comments
 (0)