Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tooling to verify that all tests run on Linux #9

Merged
merged 2 commits into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tests/InkTests/CodeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ final class CodeTests: XCTestCase {
}

extension CodeTests {
static var allTests: [(String, TestClosure<CodeTests>)] {
static var allTests: Linux.TestList<CodeTests> {
return [
("testInlineCode", testInlineCode),
("testCodeBlockWithJustBackticks", testCodeBlockWithJustBackticks),
Expand Down
2 changes: 1 addition & 1 deletion Tests/InkTests/HTMLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ final class HTMLTests: XCTestCase {
}

extension HTMLTests {
static var allTests: [(String, TestClosure<HTMLTests>)] {
static var allTests: Linux.TestList<HTMLTests> {
return [
("testTopLevelHTML", testTopLevelHTML),
("testNestedTopLevelHTML", testNestedTopLevelHTML),
Expand Down
2 changes: 1 addition & 1 deletion Tests/InkTests/HeadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class HeadingTests: XCTestCase {
}

extension HeadingTests {
static var allTests: [(String, TestClosure<HeadingTests>)] {
static var allTests: Linux.TestList<HeadingTests> {
return [
("testHeading", testHeading),
("testHeadingsSeparatedBySingleNewline", testHeadingsSeparatedBySingleNewline),
Expand Down
2 changes: 1 addition & 1 deletion Tests/InkTests/HorizontalLineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class HorizontalLineTests: XCTestCase {
}

extension HorizontalLineTests {
static var allTests: [(String, TestClosure<HorizontalLineTests>)] {
static var allTests: Linux.TestList<HorizontalLineTests> {
return [
("testHorizonalLineWithDashes", testHorizonalLineWithDashes),
("testHorizontalLineWithDashesAtTheStartOfString", testHorizontalLineWithDashesAtTheStartOfString),
Expand Down
2 changes: 1 addition & 1 deletion Tests/InkTests/ImageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class ImageTests: XCTestCase {
}

extension ImageTests {
static var allTests: [(String, TestClosure<ImageTests>)] {
static var allTests: Linux.TestList<ImageTests> {
return [
("testImageWithURL", testImageWithURL),
("testImageWithReference", testImageWithReference),
Expand Down
2 changes: 1 addition & 1 deletion Tests/InkTests/LinkTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final class LinkTests: XCTestCase {
}

extension LinkTests {
static var allTests: [(String, TestClosure<LinkTests>)] {
static var allTests: Linux.TestList<LinkTests> {
return [
("testLinkWithURL", testLinkWithURL),
("testLinkWithReference", testLinkWithReference),
Expand Down
55 changes: 55 additions & 0 deletions Tests/InkTests/LinuxCompatibility.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Ink
* 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
2 changes: 1 addition & 1 deletion Tests/InkTests/ListTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ final class ListTests: XCTestCase {
}

extension ListTests {
static var allTests: [(String, TestClosure<ListTests>)] {
static var allTests: Linux.TestList<ListTests> {
return [
("testOrderedList", testOrderedList),
("testOrderedListWithoutIncrementedNumbers", testOrderedListWithoutIncrementedNumbers),
Expand Down
2 changes: 1 addition & 1 deletion Tests/InkTests/MetadataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ final class MetadataTests: XCTestCase {
}

extension MetadataTests {
static var allTests: [(String, TestClosure<MetadataTests>)] {
static var allTests: Linux.TestList<MetadataTests> {
return [
("testParsingMetadata", testParsingMetadata),
("testDiscardingEmptyMetadataValues", testDiscardingEmptyMetadataValues),
Expand Down
2 changes: 1 addition & 1 deletion Tests/InkTests/ModifierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final class ModifierTests: XCTestCase {
}

extension ModifierTests {
static var allTests: [(String, TestClosure<ModifierTests>)] {
static var allTests: Linux.TestList<ModifierTests> {
return [
("testModifierInput", testModifierInput),
("testInitializingParserWithModifiers", testInitializingParserWithModifiers),
Expand Down
9 changes: 0 additions & 9 deletions Tests/InkTests/TestClosure.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Tests/InkTests/TextFormattingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ final class TextFormattingTests: XCTestCase {
}

extension TextFormattingTests {
static var allTests: [(String, TestClosure<TextFormattingTests>)] {
static var allTests: Linux.TestList<TextFormattingTests> {
return [
("testParagraph", testParagraph),
("testItalicText", testItalicText),
Expand Down
24 changes: 11 additions & 13 deletions Tests/InkTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@

import XCTest

#if !canImport(ObjectiveC)
public func allTests() -> [XCTestCaseEntry] {
public func allTests() -> [Linux.TestCase] {
return [
testCase(CodeTests.allTests),
testCase(HeadingTests.allTests),
testCase(HorizontalLineTests.allTests),
testCase(HTMLTests.allTests),
testCase(ImageTests.allTests),
testCase(LinkTests.allTests),
testCase(ListTests.allTests),
testCase(MetadataTests.allTests),
testCase(ModifierTests.allTests),
testCase(TextFormattingTests.allTests)
Linux.makeTestCase(using: CodeTests.allTests),
Linux.makeTestCase(using: HeadingTests.allTests),
Linux.makeTestCase(using: HorizontalLineTests.allTests),
Linux.makeTestCase(using: HTMLTests.allTests),
Linux.makeTestCase(using: ImageTests.allTests),
Linux.makeTestCase(using: LinkTests.allTests),
Linux.makeTestCase(using: ListTests.allTests),
Linux.makeTestCase(using: MetadataTests.allTests),
Linux.makeTestCase(using: ModifierTests.allTests),
Linux.makeTestCase(using: TextFormattingTests.allTests)
]
}
#endif