Skip to content

Commit

Permalink
Merge pull request #19 from wacumov/master
Browse files Browse the repository at this point in the history
Ensure that all test cases run on Linux and setup CI
  • Loading branch information
Cosmo committed Oct 19, 2020
2 parents 9e89a33 + ef67d49 commit fa4b650
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 4 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/UnitTests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: UnitTests

on:
push:
branches:
- master

jobs:
test_on_macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Build
run: swift build
- name: Test
run: swift test
test_on_linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build
run: swift build
- name: Test
run: swift test
7 changes: 6 additions & 1 deletion Tests/BinaryKitTests/BinaryKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ final class BinaryKitTests: XCTestCase {

// MARK: -

static var allTests = [
static var allTests: Linux.TestList<BinaryKitTests> = [
("testBitIndex", testBitIndex),
("testBit", testBit),
("testBits", testBits),
Expand All @@ -337,9 +337,14 @@ final class BinaryKitTests: XCTestCase {
("testByteIndex", testByteIndex),
("testBytes", testBytes),
("testBytesRange", testBytesRange),
("testMixedReadByte", testMixedReadByte),
("testMixedReadBytes", testMixedReadBytes),
("testReadBytesThrowsBeforeReading", testReadBytesThrowsBeforeReading),
("testReadBitsThrowsBeforeReading", testReadBitsThrowsBeforeReading),
("testHexInit", testHexInit),
("testNibble", testNibble),
("testStringAndCharacter", testStringAndCharacter),
("testBool", testBool),
("testFinders", testFinders),
("testWrite", testWrite),
("testWriteInt", testWriteInt),
Expand Down
58 changes: 55 additions & 3 deletions Tests/BinaryKitTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,61 @@
import XCTest

#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
public func allTests() -> [Linux.TestCase] {
return [
testCase(BinaryKitTests.allTests),
Linux.makeTestCase(using: BinaryKitTests.allTests),
]
}

#if canImport(ObjectiveC)
internal final class LinuxVerificationTests: XCTestCase {
func testAllTestsRunOnLinux() {
Linux.testAllTestsRunOnLinux(allTests: allTests())
}
}
#endif

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
}

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)
static func testAllTestsRunOnLinux(allTests: [Linux.TestCase]) {
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
}

0 comments on commit fa4b650

Please sign in to comment.