Skip to content

Commit 6d99bc0

Browse files
authored
Merge pull request #193 from briancroom/update-assertions-with-accuracy
[SR-5247] Add the new spellings for the *WithAccuracy assertion functions
2 parents 521f7c4 + ad87721 commit 6d99bc0

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

Sources/XCTest/Public/XCTAssert.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ private enum _XCTAssertion {
3030
var name: String? {
3131
switch(self) {
3232
case .equal: return "XCTAssertEqual"
33-
case .equalWithAccuracy: return "XCTAssertEqualWithAccuracy"
33+
case .equalWithAccuracy: return "XCTAssertEqual"
3434
case .greaterThan: return "XCTAssertGreaterThan"
3535
case .greaterThanOrEqual: return "XCTAssertGreaterThanOrEqual"
3636
case .lessThan: return "XCTAssertLessThan"
3737
case .lessThanOrEqual: return "XCTAssertLessThanOrEqual"
3838
case .notEqual: return "XCTAssertNotEqual"
39-
case .notEqualWithAccuracy: return "XCTAssertNotEqualWithAccuracy"
39+
case .notEqualWithAccuracy: return "XCTAssertNotEqual"
4040
case .`nil`: return "XCTAssertNil"
4141
case .notNil: return "XCTAssertNotNil"
4242
case .`true`: return "XCTAssertTrue"
@@ -224,7 +224,7 @@ public func XCTAssertEqual<T, U: Equatable>(_ expression1: @autoclosure () throw
224224
}
225225
}
226226

227-
public func XCTAssertEqualWithAccuracy<T: FloatingPoint>(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) {
227+
public func XCTAssertEqual<T: FloatingPoint>(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) {
228228
_XCTEvaluateAssertion(.equalWithAccuracy, message: message, file: file, line: line) {
229229
let (value1, value2) = (try expression1(), try expression2())
230230
if abs(value1.distance(to: value2)) <= abs(accuracy.distance(to: T(0))) {
@@ -235,6 +235,11 @@ public func XCTAssertEqualWithAccuracy<T: FloatingPoint>(_ expression1: @autoclo
235235
}
236236
}
237237

238+
@available(*, deprecated, renamed: "XCTAssertEqual(_:_:accuracy:file:line:)")
239+
public func XCTAssertEqualWithAccuracy<T: FloatingPoint>(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) {
240+
XCTAssertEqual(expression1, expression2, accuracy: accuracy, message, file: file, line: line)
241+
}
242+
238243
public func XCTAssertFalse(_ expression: @autoclosure () throws -> Bool, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) {
239244
_XCTEvaluateAssertion(.`false`, message: message, file: file, line: line) {
240245
let value = try expression()
@@ -367,7 +372,7 @@ public func XCTAssertNotEqual<T, U: Equatable>(_ expression1: @autoclosure () th
367372
}
368373
}
369374

370-
public func XCTAssertNotEqualWithAccuracy<T: FloatingPoint>(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) {
375+
public func XCTAssertNotEqual<T: FloatingPoint>(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) {
371376
_XCTEvaluateAssertion(.notEqualWithAccuracy, message: message, file: file, line: line) {
372377
let (value1, value2) = (try expression1(), try expression2())
373378
if abs(value1.distance(to: value2)) > abs(accuracy.distance(to: T(0))) {
@@ -378,6 +383,11 @@ public func XCTAssertNotEqualWithAccuracy<T: FloatingPoint>(_ expression1: @auto
378383
}
379384
}
380385

386+
@available(*, deprecated, renamed: "XCTAssertNotEqual(_:_:accuracy:file:line:)")
387+
public func XCTAssertNotEqualWithAccuracy<T: FloatingPoint>(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, _ accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) {
388+
XCTAssertNotEqual(expression1, expression2, accuracy: accuracy, message, file: file, line: line)
389+
}
390+
381391
public func XCTAssertNotNil(_ expression: @autoclosure () throws -> Any?, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) {
382392
_XCTEvaluateAssertion(.notNil, message: message, file: file, line: line) {
383393
let value = try expression()

Tests/Functional/FailureMessagesTestCase/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ class FailureMessagesTestCase: XCTestCase {
9494
}
9595

9696
// CHECK: Test Case 'FailureMessagesTestCase.testAssertEqualWithAccuracy' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
97-
// CHECK: test.swift:[[@LINE+3]]: error: FailureMessagesTestCase.testAssertEqualWithAccuracy : XCTAssertEqualWithAccuracy failed: \("1\.0"\) is not equal to \("2\.0"\) \+/- \("0\.1"\) - message
97+
// CHECK: test.swift:[[@LINE+3]]: error: FailureMessagesTestCase.testAssertEqualWithAccuracy : XCTAssertEqual failed: \("1\.0"\) is not equal to \("2\.0"\) \+/- \("0\.1"\) - message
9898
// CHECK: Test Case 'FailureMessagesTestCase.testAssertEqualWithAccuracy' failed \(\d+\.\d+ seconds\)
9999
func testAssertEqualWithAccuracy() {
100-
XCTAssertEqualWithAccuracy(1, 2, accuracy: 0.1, "message", file: "test.swift")
100+
XCTAssertEqual(1, 2, accuracy: 0.1, "message", file: "test.swift")
101101
}
102102

103103
// CHECK: Test Case 'FailureMessagesTestCase.testAssertFalse' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
@@ -185,10 +185,10 @@ class FailureMessagesTestCase: XCTestCase {
185185
}
186186

187187
// CHECK: Test Case 'FailureMessagesTestCase.testAssertNotEqualWithAccuracy' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
188-
// CHECK: test.swift:[[@LINE+3]]: error: FailureMessagesTestCase.testAssertNotEqualWithAccuracy : XCTAssertNotEqualWithAccuracy failed: \("1\.0"\) is equal to \("1\.0"\) \+/- \("0\.1"\) - message
188+
// CHECK: test.swift:[[@LINE+3]]: error: FailureMessagesTestCase.testAssertNotEqualWithAccuracy : XCTAssertNotEqual failed: \("1\.0"\) is equal to \("1\.0"\) \+/- \("0\.1"\) - message
189189
// CHECK: Test Case 'FailureMessagesTestCase.testAssertNotEqualWithAccuracy' failed \(\d+\.\d+ seconds\)
190190
func testAssertNotEqualWithAccuracy() {
191-
XCTAssertNotEqualWithAccuracy(1, 1, 0.1, "message", file: "test.swift")
191+
XCTAssertNotEqual(1, 1, accuracy: 0.1, "message", file: "test.swift")
192192
}
193193

194194
// CHECK: Test Case 'FailureMessagesTestCase.testAssertNotNil' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+

Tests/Functional/NegativeAccuracyTestCase/main.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,27 @@ class NegativeAccuracyTestCase: XCTestCase {
2727
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
2828
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_passes' passed \(\d+\.\d+ seconds\)
2929
func test_equalWithAccuracy_passes() {
30-
XCTAssertEqualWithAccuracy(0, 0.1, accuracy: -0.1)
30+
XCTAssertEqual(0, 0.1, accuracy: -0.1)
3131
}
3232

3333
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
34-
// CHECK: .*/NegativeAccuracyTestCase/main.swift:[[@LINE+3]]: error: NegativeAccuracyTestCase.test_equalWithAccuracy_fails : XCTAssertEqualWithAccuracy failed: \(\"0\.0\"\) is not equal to \(\"0\.2\"\) \+\/- \(\"-0\.1\"\) - $
34+
// CHECK: .*/NegativeAccuracyTestCase/main.swift:[[@LINE+3]]: error: NegativeAccuracyTestCase.test_equalWithAccuracy_fails : XCTAssertEqual failed: \(\"0\.0\"\) is not equal to \(\"0\.2\"\) \+\/- \(\"-0\.1\"\) - $
3535
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_fails' failed \(\d+\.\d+ seconds\)
3636
func test_equalWithAccuracy_fails() {
37-
XCTAssertEqualWithAccuracy(0, 0.2, accuracy: -0.1)
37+
XCTAssertEqual(0, 0.2, accuracy: -0.1)
3838
}
3939

4040
// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
4141
// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_passes' passed \(\d+\.\d+ seconds\)
4242
func test_notEqualWithAccuracy_passes() {
43-
XCTAssertNotEqualWithAccuracy(1, 2, -0.5)
43+
XCTAssertNotEqual(1, 2, accuracy: -0.5)
4444
}
4545

4646
// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
47-
// CHECK: .*/NegativeAccuracyTestCase/main.swift:[[@LINE+3]]: error: NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails : XCTAssertNotEqualWithAccuracy failed: \("1\.0"\) is equal to \("2\.0"\) \+/- \("-1\.0"\) - $
47+
// CHECK: .*/NegativeAccuracyTestCase/main.swift:[[@LINE+3]]: error: NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails : XCTAssertNotEqual failed: \("1\.0"\) is equal to \("2\.0"\) \+/- \("-1\.0"\) - $
4848
// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails' failed \(\d+\.\d+ seconds\)
4949
func test_notEqualWithAccuracy_fails() {
50-
XCTAssertNotEqualWithAccuracy(1, 2, -1)
50+
XCTAssertNotEqual(1, 2, accuracy: -1)
5151
}
5252
}
5353
// CHECK: Test Suite 'NegativeAccuracyTestCase' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+

build_script.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def build(args):
9191
"-configuration {style_options} "
9292
"SWIFT_EXEC=\"{swiftc}\" "
9393
"SWIFT_LINK_OBJC_RUNTIME=YES "
94+
"INDEX_ENABLE_DATA_STORE=NO "
9495
"SYMROOT=\"{build_dir}\" OBJROOT=\"{build_dir}\"".format(
9596
swiftc=swiftc,
9697
build_dir=build_dir,
@@ -122,6 +123,7 @@ def test(args):
122123
"-configuration {style_options} "
123124
"SWIFT_EXEC=\"{swiftc}\" "
124125
"SWIFT_LINK_OBJC_RUNTIME=YES "
126+
"INDEX_ENABLE_DATA_STORE=NO "
125127
"SYMROOT=\"{build_dir}\" OBJROOT=\"{build_dir}\" ".format(
126128
swiftc=swiftc,
127129
build_dir=build_dir,

0 commit comments

Comments
 (0)