-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from wacumov/master
Ensure that all test cases run on Linux and setup CI
- Loading branch information
Showing
3 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |