diff --git a/.github/workflows/UnitTests.yml b/.github/workflows/UnitTests.yml new file mode 100644 index 0000000..cfea09d --- /dev/null +++ b/.github/workflows/UnitTests.yml @@ -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 diff --git a/Tests/BinaryKitTests/BinaryKitTests.swift b/Tests/BinaryKitTests/BinaryKitTests.swift index 1b0e8f6..fb13de9 100644 --- a/Tests/BinaryKitTests/BinaryKitTests.swift +++ b/Tests/BinaryKitTests/BinaryKitTests.swift @@ -328,7 +328,7 @@ final class BinaryKitTests: XCTestCase { // MARK: - - static var allTests = [ + static var allTests: Linux.TestList = [ ("testBitIndex", testBitIndex), ("testBit", testBit), ("testBits", testBits), @@ -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), diff --git a/Tests/BinaryKitTests/XCTestManifests.swift b/Tests/BinaryKitTests/XCTestManifests.swift index f5ae436..959a714 100644 --- a/Tests/BinaryKitTests/XCTestManifests.swift +++ b/Tests/BinaryKitTests/XCTestManifests.swift @@ -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 = [(String, Test)] + typealias Test = (T) -> () throws -> Void +} + +extension Linux { + static func makeTestCase(using list: TestList) -> 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 +}