Skip to content

[XCTestCase] Workaround SR-1129 using public var #87

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

Merged
Merged
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
25 changes: 13 additions & 12 deletions Sources/XCTest/XCTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ public class XCTestCase: XCTest {
/// https://bugs.swift.org/browse/SR-1129 for details.
public var _name: String

/// The set of expectations made upon this test case.
/// - Note: FIXME: This is meant to be a `private var`, but is marked as
/// `public` here to work around a Swift compiler bug on Linux. To ensure
/// compatibility of tests between swift-corelibs-xctest and Apple XCTest,
/// this property should not be modified. See
/// https://bugs.swift.org/browse/SR-1129 for details.
public var _allExpectations = [XCTestExpectation]()

public required override init() {
_name = "\(self.dynamicType).<unknown>"
}
Expand All @@ -62,12 +70,6 @@ private func test<T: XCTestCase>(testFunc: T -> () throws -> Void) -> XCTestCase
}
}

// FIXME: Expectations should be stored in an instance variable defined on
// `XCTestCase`, but when so defined Linux tests fail with "hidden symbol
// isn't defined". Use a global for the time being, as this seems to
// appease the Linux compiler.
private var XCTAllExpectations = [XCTestExpectation]()

extension XCTestCase {

public var continueAfterFailure: Bool {
Expand Down Expand Up @@ -124,8 +126,7 @@ extension XCTestCase {
}

testCase.tearDown()
testCase.failIfExpectationsNotWaitedFor(XCTAllExpectations)
XCTAllExpectations = []
testCase.failIfExpectationsNotWaitedFor(testCase._allExpectations)

observationCenter.testCaseDidFinish(testCase)

Expand Down Expand Up @@ -195,7 +196,7 @@ extension XCTestCase {
file: file,
line: line,
testCase: self)
XCTAllExpectations.append(expectation)
_allExpectations.append(expectation)
return expectation
}

Expand Down Expand Up @@ -232,7 +233,7 @@ extension XCTestCase {
// the test to stop cold. swift-corelibs-xctest does not stop,
// and executes the rest of the test. This discrepancy should be
// fixed.
if XCTAllExpectations.count == 0 {
if _allExpectations.count == 0 {
let failure = XCTFailure(
message: "call made to wait without any expectations having been set.",
failureDescription: "API violation",
Expand Down Expand Up @@ -261,7 +262,7 @@ extension XCTestCase {
let timeoutDate = NSDate(timeIntervalSinceNow: timeout)
repeat {
unfulfilledDescriptions = []
for expectation in XCTAllExpectations {
for expectation in _allExpectations {
if !expectation.fulfilled {
unfulfilledDescriptions.append(expectation.description)
}
Expand Down Expand Up @@ -294,7 +295,7 @@ extension XCTestCase {

// We've recorded all the failures; clear the expectations that
// were set for this test case.
XCTAllExpectations = []
_allExpectations = []

// The handler is invoked regardless of whether the test passed.
if let completionHandler = handler {
Expand Down