Skip to content

Instantly share code, notes, and snippets.

@briancroom
Last active January 19, 2016 20:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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
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