Skip to content

Commit 576ed79

Browse files
committed
Merge pull request #93 from briancroom/error-constants
Add constants for XCTest error domain and codes
2 parents 9ff1724 + ef5ed8d commit 576ed79

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

Sources/XCTest/XCTestCase.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ extension XCTestCase {
296296
if unfulfilledDescriptions.count > 0 {
297297
// If the test failed, send an error object.
298298
error = NSError(
299-
domain: "org.swift.XCTestErrorDomain",
300-
code: 0,
299+
domain: XCTestErrorDomain,
300+
code: XCTestErrorCode.timeoutWhileWaiting.rawValue,
301301
userInfo: [:])
302302
}
303303
completionHandler(error)

Sources/XCTest/XCTestErrors.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This source file is part of the Swift.org open source project
2+
//
3+
// Copyright (c) 2016 Apple Inc. and the Swift project authors
4+
// Licensed under Apache License v2.0 with Runtime Library Exception
5+
//
6+
// See http://swift.org/LICENSE.txt for license information
7+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8+
//
9+
//
10+
// XCTestErrors.swift
11+
// Constants used in errors produced by the XCTest library.
12+
//
13+
14+
/// The domain used by errors produced by the XCTest library.
15+
public let XCTestErrorDomain = "org.swift.XCTestErrorDomain"
16+
17+
/// Error codes for errors in the XCTestErrorDomain.
18+
public enum XCTestErrorCode : Int {
19+
/// Indicates that one or more expectations failed to be fulfilled in time
20+
/// during a call to `waitForExpectations(withTimeout:handler:)`
21+
case timeoutWhileWaiting
22+
23+
/// Indicates that a test assertion failed while waiting for expectations
24+
/// during a call to `waitForExpectations(withTimeout:handler:)`
25+
/// FIXME: swift-corelibs-xctest does not currently produce this error code.
26+
case failureWhileWaiting
27+
}

Tests/Functional/Asynchronous/Handler/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class HandlerTestCase: XCTestCase {
2424
var handlerWasCalled = false
2525
self.waitForExpectations(withTimeout: 0.2) { error in
2626
XCTAssertNotNil(error, "Expectation handlers for unfulfilled expectations should not be nil.")
27-
XCTAssertTrue(error!.domain.hasSuffix("XCTestErrorDomain"), "The last component of the error domain should match Objective-C XCTest.")
28-
XCTAssertEqual(error!.code, 0, "The error code should match Objective-C XCTest.")
27+
XCTAssertEqual(error?.domain, XCTestErrorDomain, "The error domain should be XCTest's own error domain")
28+
XCTAssertEqual(error?.code, XCTestErrorCode.timeoutWhileWaiting.rawValue, "The error code should indicate that a timeout occurred")
2929
handlerWasCalled = true
3030
}
3131
XCTAssertTrue(handlerWasCalled)

XCTest.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
AE7DD60C1C8F0513006FC722 /* XCTestObservation.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE7DD60B1C8F0513006FC722 /* XCTestObservation.swift */; };
1414
AE9596DF1C96911F001A9EF0 /* ObjectWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE9596DE1C96911F001A9EF0 /* ObjectWrapper.swift */; };
1515
AE9596E11C9692B8001A9EF0 /* XCTestObservationCenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE9596E01C9692B8001A9EF0 /* XCTestObservationCenter.swift */; };
16+
AED59FF61CB5394800F49260 /* XCTestErrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = AED59FF51CB5394800F49260 /* XCTestErrors.swift */; };
1617
C265F66F1C3AEB6A00520CF9 /* XCTAssert.swift in Sources */ = {isa = PBXBuildFile; fileRef = C265F6691C3AEB6A00520CF9 /* XCTAssert.swift */; };
1718
C265F6701C3AEB6A00520CF9 /* XCTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = C265F66A1C3AEB6A00520CF9 /* XCTestCase.swift */; };
1819
C265F6721C3AEB6A00520CF9 /* XCTestMain.swift in Sources */ = {isa = PBXBuildFile; fileRef = C265F66C1C3AEB6A00520CF9 /* XCTestMain.swift */; };
@@ -46,6 +47,7 @@
4647
AE7DD60B1C8F0513006FC722 /* XCTestObservation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCTestObservation.swift; sourceTree = "<group>"; };
4748
AE9596DE1C96911F001A9EF0 /* ObjectWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectWrapper.swift; sourceTree = "<group>"; };
4849
AE9596E01C9692B8001A9EF0 /* XCTestObservationCenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCTestObservationCenter.swift; sourceTree = "<group>"; };
50+
AED59FF51CB5394800F49260 /* XCTestErrors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCTestErrors.swift; sourceTree = "<group>"; };
4951
B1384A411C1B3E8700EDF031 /* CONTRIBUTING.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = CONTRIBUTING.md; sourceTree = "<group>"; };
5052
B1384A421C1B3E8700EDF031 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
5153
B1384A431C1B3E8700EDF031 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
@@ -130,6 +132,7 @@
130132
C265F66A1C3AEB6A00520CF9 /* XCTestCase.swift */,
131133
DA7714F81CA87DEF001EA745 /* XCTestSuiteRun.swift */,
132134
DA7714FA1CA87DFB001EA745 /* XCTestCaseRun.swift */,
135+
AED59FF51CB5394800F49260 /* XCTestErrors.swift */,
133136
DADB979B1C51BDA2005E68B6 /* XCTestExpectation.swift */,
134137
C265F66C1C3AEB6A00520CF9 /* XCTestMain.swift */,
135138
AE7DD60B1C8F0513006FC722 /* XCTestObservation.swift */,
@@ -282,6 +285,7 @@
282285
DA7FB3431CA4EA4000F024F9 /* XCTestSuite.swift in Sources */,
283286
DA7714F91CA87DEF001EA745 /* XCTestSuiteRun.swift in Sources */,
284287
AE9596DF1C96911F001A9EF0 /* ObjectWrapper.swift in Sources */,
288+
AED59FF61CB5394800F49260 /* XCTestErrors.swift in Sources */,
285289
C265F6721C3AEB6A00520CF9 /* XCTestMain.swift in Sources */,
286290
);
287291
runOnlyForDeploymentPostprocessing = 0;

0 commit comments

Comments
 (0)