Update the project to Swift 5.4 (#125)

* Update the project to Swift 5.4

- Splash now uses the Swift 5.4 toolchain.
- Since Swift 5.4 now enables automatic test discovery on all supported
   platforms, all of the infrastructure that was previously used to maintain
   Linux unit testing compatibility has now been removed.

* Remove LinuxMain.swift
This commit is contained in:
John Sundell 2021-06-14 10:33:59 +02:00 committed by GitHub
parent 4df8c3e76a
commit 7f87f191b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 9 additions and 431 deletions

View File

@ -1,4 +1,4 @@
// swift-tools-version:5.2
// swift-tools-version:5.4
/**
* Splash
@ -19,19 +19,19 @@ let package = Package(
],
targets: [
.target(name: "Splash"),
.target(
.executableTarget(
name: "SplashMarkdown",
dependencies: ["Splash"]
),
.target(
.executableTarget(
name: "SplashHTMLGen",
dependencies: ["Splash"]
),
.target(
.executableTarget(
name: "SplashImageGen",
dependencies: ["Splash"]
),
.target(
.executableTarget(
name: "SplashTokenizer",
dependencies: ["Splash"]
),

View File

@ -1,12 +0,0 @@
/**
* Splash
* Copyright (c) John Sundell 2018
* MIT license - see LICENSE.md
*/
import XCTest
import SplashTests
var tests = [XCTestCaseEntry]()
tests += SplashTests.makeLinuxTests()
XCTMain(tests)

View File

@ -1,28 +0,0 @@
/**
* Splash
* Copyright (c) John Sundell 2019
* MIT license - see LICENSE.md
*/
import Foundation
import XCTest
/// Abstract base class for all Splash tests
class SplashTestCase: XCTestCase {
#if os(macOS)
func testHasLinuxVerificationTest() {
let concreteType = type(of: self)
guard concreteType != SyntaxHighlighterTestCase.self else {
return
}
guard concreteType != SplashTestCase.self else {
return
}
XCTAssertTrue(concreteType.testNames.contains("testAllTestsRunOnLinux"),
"\(concreteType) doesn't have a test that verifies that its tests run on Linux")
}
#endif
}

View File

@ -10,7 +10,7 @@ import Splash
/// Test case used as an abstract base class for all tests relating to
/// syntax highlighting. For all such tests, the Swift grammar is used.
class SyntaxHighlighterTestCase: SplashTestCase {
class SyntaxHighlighterTestCase: XCTestCase {
private(set) var highlighter: SyntaxHighlighter<OutputFormatMock>!
private(set) var builder: OutputBuilderMock!

View File

@ -1,37 +0,0 @@
/**
* Splash
* Copyright (c) John Sundell 2018
* MIT license - see LICENSE.md
*/
import Foundation
import XCTest
struct TestCaseVerifier<Case: XCTestCase> {
static func verifyLinuxTests(_ tests: [(String, TestClosure<Case>)]) -> Bool {
#if os(macOS)
let testNames = Set(tests.map { $0.0 })
for name in Case.testNames {
guard name != "testAllTestsRunOnLinux" else {
continue
}
guard name != "testHasLinuxVerificationTest" else {
continue
}
guard testNames.contains(name) else {
XCTFail("""
Test case \(Case.self) does not include test \(name) on Linux.
Please add it to the test case's 'allTests' array.
""")
return false
}
}
#endif
return true
}
}

View File

@ -1,10 +0,0 @@
/**
* Splash
* Copyright (c) John Sundell 2018
* MIT license - see LICENSE.md
*/
import Foundation
import XCTest
typealias TestClosure<T: XCTestCase> = (T) -> () throws -> Void

View File

@ -1,21 +0,0 @@
/**
* Splash
* Copyright (c) John Sundell 2018
* MIT license - see LICENSE.md
*/
import Foundation
import XCTest
#if os(macOS)
extension XCTestCase {
static var testNames: [String] {
return defaultTestSuite.tests.map { test in
let components = test.name.components(separatedBy: .whitespaces)
return components[1].replacingOccurrences(of: "]", with: "")
}
}
}
#endif

View File

@ -1,26 +0,0 @@
/**
* Splash
* Copyright (c) John Sundell 2018
* MIT license - see LICENSE.md
*/
import XCTest
#if os(Linux)
public func makeLinuxTests() -> [XCTestCaseEntry] {
return [
testCase(ClosureTests.allTests),
testCase(CommentTests.allTests),
testCase(DeclarationTests.allTests),
testCase(EnumTests.allTests),
testCase(FunctionCallTests.allTests),
testCase(LiteralTests.allTests),
testCase(OptionalTests.allTests),
testCase(PreprocessorTests.allTests),
testCase(StatementTests.allTests),
testCase(MarkdownTests.allTests)
]
}
#endif

View File

@ -259,28 +259,4 @@ final class ClosureTests: SyntaxHighlighterTestCase {
.plainText("}")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
}
extension ClosureTests {
static var allTests: [(String, TestClosure<ClosureTests>)] {
return [
("testTrailingClosureWithArguments", testTrailingClosureWithArguments),
("testTrailingClosureWithoutParanthesis", testTrailingClosureWithoutParanthesis),
("testEmptyTrailingClosure", testEmptyTrailingClosure),
("testClosureArgumentWithSingleArgument", testClosureArgumentWithSingleArgument),
("testClosureArgumentWithMultipleArguments", testClosureArgumentWithMultipleArguments),
("testEscapingClosureArgument", testEscapingClosureArgument),
("testClosureWithInoutArgument", testClosureWithInoutArgument),
("testPassingClosureAsArgument", testPassingClosureAsArgument),
("testNestedEscapingClosure", testNestedEscapingClosure),
("testClosureArgumentShorthands", testClosureArgumentShorthands),
("testClosureWithWeakSelfCaptureList", testClosureWithWeakSelfCaptureList),
("testClosureWithUnownedSelfCaptureList", testClosureWithUnownedSelfCaptureList),
("testClosureWithSingleFunctionCall", testClosureWithSingleFunctionCall)
]
}
}

View File

@ -358,31 +358,4 @@ final class CommentTests: SyntaxHighlighterTestCase {
.plainText("}")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
}
extension CommentTests {
static var allTests: [(String, TestClosure<CommentTests>)] {
return [
("testSingleLineComment", testSingleLineComment),
("testMultiLineComment", testMultiLineComment),
("testMultiLineCommentWithDoubleAsterisks", testMultiLineCommentWithDoubleAsterisks),
("testMutliLineDocumentationComment", testMutliLineDocumentationComment),
("testCommentStartingWithPunctuation", testCommentStartingWithPunctuation),
("testCommentEndingWithComma", testCommentEndingWithComma),
("testCommentPrecededByComma", testCommentPrecededByComma),
("testCommentWithNumber", testCommentWithNumber),
("testCommentWithNoWhiteSpaceToPunctuation", testCommentWithNoWhiteSpaceToPunctuation),
("testCommentsNextToCurlyBrackets", testCommentsNextToCurlyBrackets),
("testCommentWithinGenericTypeList", testCommentWithinGenericTypeList),
("testCommentsNextToGenericTypeList", testCommentsNextToGenericTypeList),
("testCommentsNextToInitialization", testCommentsNextToInitialization),
("testCommentsNextToProtocolName", testCommentsNextToProtocolName),
("testCommentsAfterOptionalTypes", testCommentsAfterOptionalTypes),
("testCommentsAfterArrayTypes", testCommentsAfterArrayTypes)
]
}
}

View File

@ -1326,67 +1326,4 @@ final class DeclarationTests: SyntaxHighlighterTestCase {
.plainText("}")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
}
extension DeclarationTests {
static var allTests: [(String, TestClosure<DeclarationTests>)] {
return [
("testFunctionDeclaration", testFunctionDeclaration),
("testRequiredFunctionDeclaration", testRequiredFunctionDeclaration),
("testPublicFunctionDeclarationWithDocumentationEndingWithDot", testPublicFunctionDeclarationWithDocumentationEndingWithDot),
("testFunctionDeclarationWithEmptyExternalLabel", testFunctionDeclarationWithEmptyExternalLabel),
("testFunctionDeclarationWithKeywordArgumentLabel", testFunctionDeclarationWithKeywordArgumentLabel),
("testFunctionDeclarationWithKeywordArgumentLabelOnNewLine", testFunctionDeclarationWithKeywordArgumentLabelOnNewLine),
("testGenericFunctionDeclarationWithKeywordArgumentLabel", testGenericFunctionDeclarationWithKeywordArgumentLabel),
("testGenericFunctionDeclarationWithoutConstraints", testGenericFunctionDeclarationWithoutConstraints),
("testGenericFunctionDeclarationWithSingleConstraint", testGenericFunctionDeclarationWithSingleConstraint),
("testGenericFunctionDeclarationWithMultipleConstraints", testGenericFunctionDeclarationWithMultipleConstraints),
("testGenericFunctionDeclarationWithGenericParameter", testGenericFunctionDeclarationWithGenericParameter),
("testFunctionDeclarationWithGenericReturnType", testFunctionDeclarationWithGenericReturnType),
("testGenericStructDeclaration", testGenericStructDeclaration),
("testClassDeclaration", testClassDeclaration),
("testCompactClassDeclarationWithInitializer", testCompactClassDeclarationWithInitializer),
("testClassDeclarationWithDeinit", testClassDeclarationWithDeinit),
("testClassDeclarationWithMultipleProtocolConformances", testClassDeclarationWithMultipleProtocolConformances),
("testSubclassDeclaration", testSubclassDeclaration),
("testGenericSubclassDeclaration", testGenericSubclassDeclaration),
("testProtocolDeclaration", testProtocolDeclaration),
("testProtocolDeclarationWithAssociatedTypes", testProtocolDeclarationWithAssociatedTypes),
("testExtensionDeclaration", testExtensionDeclaration),
("testExtensionDeclarationWithConvenienceInitializer", testExtensionDeclarationWithConvenienceInitializer),
("testExtensionDeclarationWithConstraint", testExtensionDeclarationWithConstraint),
("testLazyPropertyDeclaration", testLazyPropertyDeclaration),
("testDynamicPropertyDeclaration", testDynamicPropertyDeclaration),
("testGenericPropertyDeclaration", testGenericPropertyDeclaration),
("testPropertyDeclarationWithWillSet", testPropertyDeclarationWithWillSet),
("testPropertyDeclarationWithDidSet", testPropertyDeclarationWithDidSet),
("testPropertyWithCommentedDidSet", testPropertyWithCommentedDidSet),
("testPropertyWithSetterAccessLevel", testPropertyWithSetterAccessLevel),
("testPropertyDeclarationAfterCommentEndingWithVarKeyword", testPropertyDeclarationAfterCommentEndingWithVarKeyword),
("testPropertyDeclarationWithStaticPropertyDefaultValue", testPropertyDeclarationWithStaticPropertyDefaultValue),
("testSubscriptDeclaration", testSubscriptDeclaration),
("testGenericSubscriptDeclaration", testGenericSubscriptDeclaration),
("testDeferDeclaration", testDeferDeclaration),
("testFunctionDeclarationWithInOutParameter", testFunctionDeclarationWithInOutParameter),
("testFunctionDeclarationWithIgnoredParameter", testFunctionDeclarationWithIgnoredParameter),
("testFunctionDeclarationWithNonEscapedKeywordAsName", testFunctionDeclarationWithNonEscapedKeywordAsName),
("testFunctionDeclarationWithEscapedKeywordAsName", testFunctionDeclarationWithEscapedKeywordAsName),
("testFunctionDeclarationWithPreProcessors", testFunctionDeclarationWithPreProcessors),
("testNonMutatingFunction", testNonMutatingFunction),
("testRethrowingFunctionDeclaration", testRethrowingFunctionDeclaration),
("testFunctionDeclarationWithOpaqueReturnType", testFunctionDeclarationWithOpaqueReturnType),
("testPrefixFunctionDeclaration", testPrefixFunctionDeclaration),
("testEnumDeclarationWithSomeCase", testEnumDeclarationWithSomeCase),
("testIndirectEnumDeclaration", testIndirectEnumDeclaration),
("testPropertyWrapperDeclaration", testPropertyWrapperDeclaration),
("testWrappedPropertyDeclarations", testWrappedPropertyDeclarations),
("testWrappedPropertyDeclarationUsingNestedType", testWrappedPropertyDeclarationUsingNestedType),
("testWrappedPropertyDeclarationUsingExplicitType", testWrappedPropertyDeclarationUsingExplicitType),
("testGenericInitializerDeclaration", testGenericInitializerDeclaration)
]
}
}

View File

@ -57,19 +57,4 @@ final class EnumTests: SyntaxHighlighterTestCase {
.plainText("]")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
}
extension EnumTests {
static var allTests: [(String, TestClosure<EnumTests>)] {
return [
("testEnumDotSyntaxInAssignment", testEnumDotSyntaxInAssignment),
("testEnumDotSyntaxAsArgument", testEnumDotSyntaxAsArgument),
("testEnumDotSyntaxWithAssociatedValueTreatedAsCall", testEnumDotSyntaxWithAssociatedValueTreatedAsCall),
("testUsingEnumInSubscript", testUsingEnumInSubscript)
]
}
}

View File

@ -249,32 +249,4 @@ final class FunctionCallTests: SyntaxHighlighterTestCase {
.plainText("}")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
}
extension FunctionCallTests {
static var allTests: [(String, TestClosure<FunctionCallTests>)] {
return [
("testFunctionCallWithIntegers", testFunctionCallWithIntegers),
("testFunctionCallWithNil", testFunctionCallWithNil),
("testImplicitInitializerCall", testImplicitInitializerCall),
("testExplicitInitializerCall", testExplicitInitializerCall),
("testExplicitInitializerCallUsingTrailingClosureSyntax", testExplicitInitializerCallUsingTrailingClosureSyntax),
("testDotSyntaxInitializerCall", testDotSyntaxInitializerCall),
("testAccessingPropertyAfterFunctionCallWithoutArguments", testAccessingPropertyAfterFunctionCallWithoutArguments),
("testAccessingPropertyAfterFunctionCallWithArguments", testAccessingPropertyAfterFunctionCallWithArguments),
("testCallingStaticMethodOnGenericType", testCallingStaticMethodOnGenericType),
("testPassingTypeToFunction", testPassingTypeToFunction),
("testPassingBoolToUnnamedArgument", testPassingBoolToUnnamedArgument),
("testIndentedFunctionCalls", testIndentedFunctionCalls),
("testXCTAssertCalls", testXCTAssertCalls),
("testUsingTryKeywordWithinFunctionCall", testUsingTryKeywordWithinFunctionCall),
("testCallingFunctionsWithProjectedPropertyWrapperValues", testCallingFunctionsWithProjectedPropertyWrapperValues),
("testCallingFunctionWithInoutProjectedPropertyWrapperValue", testCallingFunctionWithInoutProjectedPropertyWrapperValue),
("testCallingMethodWithSameNameAsKeywordWithTrailingClosureSyntax", testCallingMethodWithSameNameAsKeywordWithTrailingClosureSyntax)
]
}
}

View File

@ -2,7 +2,7 @@ import Foundation
import XCTest
import Splash
final class HTMLOutputFormatTests: SplashTestCase {
final class HTMLOutputFormatTests: XCTestCase {
private var highlighter: SyntaxHighlighter<HTMLOutputFormat>!
override func setUp() {
@ -39,18 +39,4 @@ final class HTMLOutputFormatTests: SplashTestCase {
<span class="comment">// Hey I'm a comment!</span>
""")
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
}
extension HTMLOutputFormatTests {
static var allTests: [(String, TestClosure<HTMLOutputFormatTests>)] {
return [
("testBasicGeneration", testBasicGeneration),
("testStrippingGreaterAndLessThanCharactersFromOutput", testStrippingGreaterAndLessThanCharactersFromOutput),
("testCommentMerging", testCommentMerging)
]
}
}

View File

@ -310,34 +310,4 @@ final class LiteralTests: SyntaxHighlighterTestCase {
.plainText(")")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
}
extension LiteralTests {
static var allTests: [(String, TestClosure<LiteralTests>)] {
return [
("testStringLiteral", testStringLiteral),
("testStringLiteralPassedToFunction", testStringLiteralPassedToFunction),
("testStringLiteralWithEscapedQuote", testStringLiteralWithEscapedQuote),
("testStringLiteralWithAttribute", testStringLiteralWithAttribute),
("testStringLiteralInterpolation", testStringLiteralInterpolation),
("testStringLiteralWithInterpolatedClosureArgumentShorthand", testStringLiteralWithInterpolatedClosureArgumentShorthand),
("testStringLiteralWithCustomIterpolation", testStringLiteralWithCustomIterpolation),
("testStringLiteralWithInterpolationSurroundedByBrackets", testStringLiteralWithInterpolationSurroundedByBrackets),
("testStringLiteralWithInterpolationPrefixedByPunctuation", testStringLiteralWithInterpolationPrefixedByPunctuation),
("testStringLiteralWithInterpolationContainingString", testStringLiteralWithInterpolationContainingString),
("testMultiLineStringLiteral", testMultiLineStringLiteral),
("testSingleLineRawStringLiteral", testSingleLineRawStringLiteral),
("testMultiLineRawStringLiteral", testMultiLineRawStringLiteral),
("testRawStringWithInterpolation", testRawStringWithInterpolation),
("testStringLiteralContainingOnlyNewLine", testStringLiteralContainingOnlyNewLine),
("testDoubleLiteral", testDoubleLiteral),
("testIntegerLiteralWithSeparators", testIntegerLiteralWithSeparators),
("testKeyPathLiteral", testKeyPathLiteral),
("testKeyPathLiteralsAsArguments", testKeyPathLiteralsAsArguments)
]
}
}

View File

@ -7,7 +7,7 @@
import XCTest
import Splash
final class MarkdownTests: SplashTestCase {
final class MarkdownTests: XCTestCase {
private var decorator: MarkdownDecorator!
override func setUp() {
@ -106,19 +106,4 @@ final class MarkdownTests: SplashTestCase {
XCTAssertEqual(decorator.decorate(markdown), expectedResult)
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
}
extension MarkdownTests {
static var allTests: [(String, TestClosure<MarkdownTests>)] {
return [
("testConvertingCodeBlock", testConvertingCodeBlock),
("testSkippingHighlightingForCodeBlock", testSkippingHighlightingForCodeBlock),
("testEscapingSpecialCharactersWithinHighlightedCodeBlock", testEscapingSpecialCharactersWithinHighlightedCodeBlock),
("testEscapingSpecialCharactersWithinSkippedCodeBlock", testEscapingSpecialCharactersWithinSkippedCodeBlock)
]
}
}

View File

@ -42,18 +42,4 @@ final class OptionalTests: SyntaxHighlighterTestCase {
.plainText("()")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
}
extension OptionalTests {
static var allTests: [(String, TestClosure<OptionalTests>)] {
return [
("testAssigningPropertyWithOptionalChaining", testAssigningPropertyWithOptionalChaining),
("testReadingPropertyWithOptionalChaining", testReadingPropertyWithOptionalChaining),
("testCallingMethodwithOptionalChaining", testCallingMethodwithOptionalChaining)
]
}
}

View File

@ -101,21 +101,4 @@ final class PreprocessorTests: SyntaxHighlighterTestCase {
.plainText(")")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
}
extension PreprocessorTests {
static var allTests: [(String, TestClosure<PreprocessorTests>)] {
return [
("testPreprocessing", testPreprocessing),
("testSelector", testSelector),
("testFunctionAttribute", testFunctionAttribute),
("testAvailabilityCheck", testAvailabilityCheck),
("testWarningDirective", testWarningDirective),
("testErrorDirective", testErrorDirective)
]
}
}

View File

@ -467,33 +467,4 @@ final class StatementTests: SyntaxHighlighterTestCase {
.plainText("queryItems")
])
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
}
extension StatementTests {
static var allTests: [(String, TestClosure<StatementTests>)] {
return [
("testImportStatement", testImportStatement),
("testImportStatementWithSubmodule", testImportStatementWithSubmodule),
("testChainedIfElseStatements", testChainedIfElseStatements),
("testIfLetStatementWithKeywordSymbolName", testIfLetStatementWithKeywordSymbolName),
("testGuardStatementUnwrappingWeakSelf", testGuardStatementUnwrappingWeakSelf),
("testSwitchStatement", testSwitchStatement),
("testSwitchStatementWithSingleAssociatedValue", testSwitchStatementWithSingleAssociatedValue),
("testSwitchStatementWithMultipleAssociatedValues", testSwitchStatementWithMultipleAssociatedValues),
("testSwitchStatementWithFallthrough", testSwitchStatementWithFallthrough),
("testSwitchStatementWithTypePatternMatching", testSwitchStatementWithTypePatternMatching),
("testSwitchStatementWithOptional", testSwitchStatementWithOptional),
("testSwitchStatementWithProperty", testSwitchStatementWithProperty),
("testForStatementWithStaticProperty", testForStatementWithStaticProperty),
("testForStatementWithContinue", testForStatementWithContinue),
("testRepeatWhileStatement", testRepeatWhileStatement),
("testInitializingTypeWithLeadingUnderscore", testInitializingTypeWithLeadingUnderscore),
("testCallingFunctionWithLeadingUnderscore", testCallingFunctionWithLeadingUnderscore),
("testTernaryOperationContainingNil", testTernaryOperationContainingNil)
]
}
}

View File

@ -8,7 +8,7 @@ import Foundation
import XCTest
import Splash
final class TokenTypeTests: SplashTestCase {
final class TokenTypeTests: XCTestCase {
func testConvertingToString() {
let standardType = TokenType.comment
XCTAssertEqual(standardType.string, "comment")
@ -16,16 +16,4 @@ final class TokenTypeTests: SplashTestCase {
let customType = TokenType.custom("MyCustomType")
XCTAssertEqual(customType.string, "MyCustomType")
}
func testAllTestsRunOnLinux() {
XCTAssertTrue(TestCaseVerifier.verifyLinuxTests((type(of: self)).allTests))
}
}
extension TokenTypeTests {
static var allTests: [(String, TestClosure<TokenTypeTests>)] {
return [
("testConvertingToString", testConvertingToString)
]
}
}