Last active
January 19, 2016 20:20
-
-
Save briancroom/dd7d241fa5cbb887389c to your computer and use it in GitHub Desktop.
Make XCTest tests fail on OS X unless they have been added to `allTests` for Linux support
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
import Foundation | |
import XCTest | |
// XCTestCaseProvider is defined on Linux as part of swift-corelibs-xctest, | |
// but is not available on OS X. By defining this protocol and extension | |
// we ensure that the tests fail on OS X if they haven't been configured properly | |
// to be run on Linux | |
#if !os(Linux) | |
public protocol XCTestCaseProvider { | |
var allTests : [(String, () throws -> Void)] { get } | |
} | |
extension XCTestCase { | |
override public func tearDown() { | |
if let provider = self as? XCTestCaseProvider { | |
provider.assertContainsTest(invocation!.selector.description) | |
} | |
super.tearDown() | |
} | |
} | |
extension XCTestCaseProvider { | |
private func assertContainsTest(name: String) { | |
let contains = self.allTests.contains({ test in | |
return test.0 == name | |
}) | |
XCTAssert(contains, "Test '\(name)' is missing from the allTests array") | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment