Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Make XCTest tests fail on OS X unless they have been added to `allTests` for Linux support
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