Skip to content

Commit 3da9a31

Browse files
committed
Add logging to .unwrapped() and move it to Utilities.
1 parent 662f631 commit 3da9a31

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

TestFoundation/TestNSCalendar.swift

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,6 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10-
enum TestError: Error {
11-
case unexpectedNil
12-
}
13-
14-
extension Optional {
15-
func unwrapped() throws -> Wrapped {
16-
if let x = self {
17-
return x
18-
} else {
19-
XCTFail()
20-
throw TestError.unexpectedNil
21-
}
22-
}
23-
}
24-
2510
class TestNSCalendar: XCTestCase {
2611
func test_initWithCalendarIdentifier() {
2712
var calMaybe = NSCalendar(calendarIdentifier: NSCalendar.Identifier("Not a calendar"))

TestFoundation/Utilities.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,18 @@ func _checkHashing<Source: Hashable, Target: Hashable, S: Sequence>(
113113
file: file, line: line)
114114
}
115115
}
116+
117+
enum TestError: Error {
118+
case unexpectedNil
119+
}
120+
121+
extension Optional {
122+
func unwrapped(_ fn: String = #function, file: StaticString = #file, line: UInt = #line) throws -> Wrapped {
123+
if let x = self {
124+
return x
125+
} else {
126+
XCTFail("Tried to invoke .unwrapped() on nil in \(file):\(line):\(fn)")
127+
throw TestError.unexpectedNil
128+
}
129+
}
130+
}

0 commit comments

Comments
 (0)