From 1f180d73a0a792958dc7d4680d257103bff9fd57 Mon Sep 17 00:00:00 2001 From: gormster Date: Fri, 10 Jan 2020 21:58:01 +1100 Subject: [PATCH 1/3] Make XCTAssertEqual with accuracy more generic Equality with accuracy isn't limited to floating point tests. Sometimes integer (or other numeric types) need to be accurate within certain bounds for the purposes of testing. This change allows any numeric type that has magnitude and distance to be used with `XCTAssertEqual(_:_:accuracy:)` and `XCTAssertNotEqual(_:_:accuracy:)`. --- Sources/XCTest/Public/XCTAssert.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/XCTest/Public/XCTAssert.swift b/Sources/XCTest/Public/XCTAssert.swift index 9dbb954ae..1381ad72b 100644 --- a/Sources/XCTest/Public/XCTAssert.swift +++ b/Sources/XCTest/Public/XCTAssert.swift @@ -171,12 +171,12 @@ public func XCTAssertEqual(_ expression1: @autoclosure () throws - } } -public func XCTAssertEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { +public func XCTAssertEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { _XCTEvaluateAssertion(.equalWithAccuracy, message: message(), file: file, line: line) { let (value1, value2) = (try expression1(), try expression2()) // Test with equality first to handle comparing inf/-inf with itself. if value1 == value2 || - abs(value1.distance(to: value2)) <= abs(accuracy.distance(to: T(0))) { + abs(value1.distance(to: value2)) <= abs(accuracy.distance(to: T.zero)) { return .success } else { return .expectedFailure("(\"\(value1)\") is not equal to (\"\(value2)\") +/- (\"\(accuracy)\")") @@ -266,10 +266,10 @@ public func XCTAssertNotEqual(_ expression1: @autoclosure () throw } } -public func XCTAssertNotEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { +public func XCTAssertNotEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { _XCTEvaluateAssertion(.notEqualWithAccuracy, message: message(), file: file, line: line) { let (value1, value2) = (try expression1(), try expression2()) - if abs(value1.distance(to: value2)) > abs(accuracy.distance(to: T(0))) { + if abs(value1.distance(to: value2)) > abs(accuracy.distance(to: T.zero)) { return .success } else { return .expectedFailure("(\"\(value1)\") is equal to (\"\(value2)\") +/- (\"\(accuracy)\")") From 8b25762d6965bc834b9c1ad7e54e2fba049c87d5 Mon Sep 17 00:00:00 2001 From: gormster Date: Mon, 13 Jan 2020 17:18:29 +1100 Subject: [PATCH 2/3] Added regression test for generic equal with accuracy Didn't bother changing the name of the test case, though. Seemed like a big change for no real benefit. Also fixed one malformed (though still working) regex in the existing test checks. --- .../NegativeAccuracyTestCase/main.swift | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/Tests/Functional/NegativeAccuracyTestCase/main.swift b/Tests/Functional/NegativeAccuracyTestCase/main.swift index 87be1fa56..d98250917 100644 --- a/Tests/Functional/NegativeAccuracyTestCase/main.swift +++ b/Tests/Functional/NegativeAccuracyTestCase/main.swift @@ -9,6 +9,7 @@ #endif // Regression test for https://github.com/apple/swift-corelibs-xctest/pull/7 +// and https://github.com/apple/swift-corelibs-xctest/pull/294 // CHECK: Test Suite 'All tests' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ // CHECK: Test Suite '.*\.xctest' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ @@ -21,6 +22,10 @@ class NegativeAccuracyTestCase: XCTestCase { ("test_equalWithAccuracy_fails", test_equalWithAccuracy_fails), ("test_notEqualWithAccuracy_passes", test_notEqualWithAccuracy_passes), ("test_notEqualWithAccuracy_fails", test_notEqualWithAccuracy_fails), + ("test_equalWithAccuracy_int_passes", test_equalWithAccuracy_int_passes), + ("test_equalWithAccuracy_int_fails", test_equalWithAccuracy_int_fails), + ("test_notEqualWithAccuracy_int_passes", test_notEqualWithAccuracy_int_passes), + ("test_notEqualWithAccuracy_int_fails", test_notEqualWithAccuracy_int_fails), ] }() @@ -31,7 +36,7 @@ class NegativeAccuracyTestCase: XCTestCase { } // CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: .*[/\\]NegativeAccuracyTestCase[/\\]main.swift:[[@LINE+3]]: error: NegativeAccuracyTestCase.test_equalWithAccuracy_fails : XCTAssertEqual failed: \(\"0\.0\"\) is not equal to \(\"0\.2\"\) \+\/- \(\"-0\.1\"\) - $ +// CHECK: .*[/\\]NegativeAccuracyTestCase[/\\]main.swift:[[@LINE+3]]: error: NegativeAccuracyTestCase.test_equalWithAccuracy_fails : XCTAssertEqual failed: \("0\.0"\) is not equal to \("0\.2"\) \+\/- \("-0\.1"\) - $ // CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_fails' failed \(\d+\.\d+ seconds\) func test_equalWithAccuracy_fails() { XCTAssertEqual(0, 0.2, accuracy: -0.1) @@ -40,22 +45,49 @@ class NegativeAccuracyTestCase: XCTestCase { // CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ // CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_passes' passed \(\d+\.\d+ seconds\) func test_notEqualWithAccuracy_passes() { - XCTAssertNotEqual(1, 2, accuracy: -0.5) + XCTAssertNotEqual(1.0, 2.0, accuracy: -0.5) } // CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ // CHECK: .*[/\\]NegativeAccuracyTestCase[/\\]main.swift:[[@LINE+3]]: error: NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails : XCTAssertNotEqual failed: \("1\.0"\) is equal to \("2\.0"\) \+/- \("-1\.0"\) - $ // CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails' failed \(\d+\.\d+ seconds\) func test_notEqualWithAccuracy_fails() { - XCTAssertNotEqual(1, 2, accuracy: -1) + XCTAssertNotEqual(1.0, 2.0, accuracy: -1.0) } + +// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_int_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_int_passes' passed \(\d+\.\d+ seconds\) + func test_equalWithAccuracy_int_passes() { + XCTAssertEqual(10, 11, accuracy: 1) + } + +// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_int_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: .*[/\\]NegativeAccuracyTestCase[/\\]main.swift:[[@LINE+3]]: error: NegativeAccuracyTestCase.test_equalWithAccuracy_int_fails : XCTAssertEqual failed: \("10"\) is not equal to \("8"\) \+\/- \("1"\) - $ +// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_int_fails' failed \(\d+\.\d+ seconds\) + func test_equalWithAccuracy_int_fails() { + XCTAssertEqual(10, 8, accuracy: 1) + } + +// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_int_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_int_passes' passed \(\d+\.\d+ seconds\) + func test_notEqualWithAccuracy_int_passes() { + XCTAssertNotEqual(-1, 5, accuracy: 5) + } + +// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_int_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: .*[/\\]NegativeAccuracyTestCase[/\\]main.swift:[[@LINE+3]]: error: NegativeAccuracyTestCase.test_notEqualWithAccuracy_int_fails : XCTAssertNotEqual failed: \("0"\) is equal to \("5"\) \+/- \("5"\) - $ +// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_int_fails' failed \(\d+\.\d+ seconds\) + func test_notEqualWithAccuracy_int_fails() { + XCTAssertNotEqual(0, 5, accuracy: 5) + } + } // CHECK: Test Suite 'NegativeAccuracyTestCase' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: \t Executed 4 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds +// CHECK: \t Executed 8 tests, with 4 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds XCTMain([testCase(NegativeAccuracyTestCase.allTests)]) // CHECK: Test Suite '.*\.xctest' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: \t Executed 4 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds +// CHECK: \t Executed 8 tests, with 4 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds // CHECK: Test Suite 'All tests' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: \t Executed 4 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds +// CHECK: \t Executed 8 tests, with 4 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds From 1f2cd76aca860397ccaa68a47b055c74dafaf81c Mon Sep 17 00:00:00 2001 From: Stuart Montgomery Date: Mon, 23 Nov 2020 20:46:48 -0600 Subject: [PATCH 3/3] Update PR changes to no longer require Stridable, consolidate all "equality with accuracy" tests, and add more tests --- Sources/XCTest/Public/XCTAssert.swift | 37 +++- .../EqualityWithAccuracy/main.swift | 160 ++++++++++++++++++ .../InfinityAccuracyTestCase/main.swift | 70 -------- .../NegativeAccuracyTestCase/main.swift | 93 ---------- 4 files changed, 191 insertions(+), 169 deletions(-) create mode 100644 Tests/Functional/EqualityWithAccuracy/main.swift delete mode 100644 Tests/Functional/InfinityAccuracyTestCase/main.swift delete mode 100644 Tests/Functional/NegativeAccuracyTestCase/main.swift diff --git a/Sources/XCTest/Public/XCTAssert.swift b/Sources/XCTest/Public/XCTAssert.swift index 1381ad72b..109f2721a 100644 --- a/Sources/XCTest/Public/XCTAssert.swift +++ b/Sources/XCTest/Public/XCTAssert.swift @@ -171,12 +171,29 @@ public func XCTAssertEqual(_ expression1: @autoclosure () throws - } } -public func XCTAssertEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { +private func areEqual(_ exp1: T, _ exp2: T, accuracy: T) -> Bool { + // Test with equality first to handle comparing inf/-inf with itself. + if exp1 == exp2 { + return true + } else { + // NaN values are handled implicitly, since the <= operator returns false when comparing any value to NaN. + let difference = (exp1.magnitude > exp2.magnitude) ? exp1 - exp2 : exp2 - exp1 + return difference.magnitude <= accuracy.magnitude + } +} + +public func XCTAssertEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { + _XCTAssertEqual(try expression1(), try expression2(), accuracy: accuracy, message(), file: file, line: line) +} + +public func XCTAssertEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { + _XCTAssertEqual(try expression1(), try expression2(), accuracy: accuracy, message(), file: file, line: line) +} + +private func _XCTAssertEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { _XCTEvaluateAssertion(.equalWithAccuracy, message: message(), file: file, line: line) { let (value1, value2) = (try expression1(), try expression2()) - // Test with equality first to handle comparing inf/-inf with itself. - if value1 == value2 || - abs(value1.distance(to: value2)) <= abs(accuracy.distance(to: T.zero)) { + if areEqual(value1, value2, accuracy: accuracy) { return .success } else { return .expectedFailure("(\"\(value1)\") is not equal to (\"\(value2)\") +/- (\"\(accuracy)\")") @@ -266,10 +283,18 @@ public func XCTAssertNotEqual(_ expression1: @autoclosure () throw } } -public func XCTAssertNotEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { +public func XCTAssertNotEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { + _XCTAssertNotEqual(try expression1(), try expression2(), accuracy: accuracy, message(), file: file, line: line) +} + +public func XCTAssertNotEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { + _XCTAssertNotEqual(try expression1(), try expression2(), accuracy: accuracy, message(), file: file, line: line) +} + +private func _XCTAssertNotEqual(_ expression1: @autoclosure () throws -> T, _ expression2: @autoclosure () throws -> T, accuracy: T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line) { _XCTEvaluateAssertion(.notEqualWithAccuracy, message: message(), file: file, line: line) { let (value1, value2) = (try expression1(), try expression2()) - if abs(value1.distance(to: value2)) > abs(accuracy.distance(to: T.zero)) { + if !areEqual(value1, value2, accuracy: accuracy) { return .success } else { return .expectedFailure("(\"\(value1)\") is equal to (\"\(value2)\") +/- (\"\(accuracy)\")") diff --git a/Tests/Functional/EqualityWithAccuracy/main.swift b/Tests/Functional/EqualityWithAccuracy/main.swift new file mode 100644 index 000000000..c8090629b --- /dev/null +++ b/Tests/Functional/EqualityWithAccuracy/main.swift @@ -0,0 +1,160 @@ +// RUN: %{swiftc} %s -o %T/EqualityWithAccuracy +// RUN: %T/EqualityWithAccuracy > %t || true +// RUN: %{xctest_checker} %t %s + +#if os(macOS) + import SwiftXCTest +#else + import XCTest +#endif + +// Regression test for https://github.com/apple/swift-corelibs-xctest/pull/7 +// and https://github.com/apple/swift-corelibs-xctest/pull/294 + +// CHECK: Test Suite 'All tests' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: Test Suite '.*\.xctest' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ + +// CHECK: Test Suite 'EqualityWithAccuracyTests' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +class EqualityWithAccuracyTests: XCTestCase { + static var allTests = { + return [ + ("test_equalWithAccuracy_passes", test_equalWithAccuracy_passes), + ("test_equalWithAccuracy_fails", test_equalWithAccuracy_fails), + ("test_notEqualWithAccuracy_passes", test_notEqualWithAccuracy_passes), + ("test_notEqualWithAccuracy_fails", test_notEqualWithAccuracy_fails), + ("test_equalWithAccuracy_int_passes", test_equalWithAccuracy_int_passes), + ("test_equalWithAccuracy_int_fails", test_equalWithAccuracy_int_fails), + ("test_notEqualWithAccuracy_int_passes", test_notEqualWithAccuracy_int_passes), + ("test_notEqualWithAccuracy_int_fails", test_notEqualWithAccuracy_int_fails), + ("test_equalWithAccuracy_infinity_fails", test_equalWithAccuracy_infinity_fails), + ("test_notEqualWithAccuracy_infinity_fails", test_notEqualWithAccuracy_infinity_fails), + ("test_equalWithAccuracy_nan_fails", test_equalWithAccuracy_nan_fails), + ] + }() + +// CHECK: Test Case 'EqualityWithAccuracyTests.test_equalWithAccuracy_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: Test Case 'EqualityWithAccuracyTests.test_equalWithAccuracy_passes' passed \(\d+\.\d+ seconds\) + func test_equalWithAccuracy_passes() { + XCTAssertEqual(0, 0.1, accuracy: -0.1) + XCTAssertEqual(1, 1, accuracy: 0) + XCTAssertEqual(0, 0, accuracy: 0) + XCTAssertEqual(0, 1, accuracy: 1) + XCTAssertEqual(0, 1, accuracy: 1.01) + XCTAssertEqual(1, 1.09, accuracy: 0.1) + XCTAssertEqual(1 as Float, 1.09, accuracy: 0.1) + XCTAssertEqual(1 as Float32, 1.09, accuracy: 0.1) + XCTAssertEqual(1 as Float64, 1.09, accuracy: 0.1) + XCTAssertEqual(1 as CGFloat, 1.09, accuracy: 0.1) + XCTAssertEqual(1 as Double, 1.09, accuracy: 0.1) + XCTAssertEqual(1 as Int, 2, accuracy: 5) + XCTAssertEqual(1 as UInt, 4, accuracy: 5) + XCTAssertEqual(1, -1, accuracy: 2) + XCTAssertEqual(-2, -4, accuracy: 2) + XCTAssertEqual(Double.infinity, .infinity, accuracy: 0) + XCTAssertEqual(Double.infinity, .infinity, accuracy: 1) + XCTAssertEqual(Double.infinity, .infinity, accuracy: 1e-6) + XCTAssertEqual(-Double.infinity, -.infinity, accuracy: 1) + XCTAssertEqual(Double.infinity, .infinity, accuracy: 1e-6) + XCTAssertEqual(Double.infinity, .infinity, accuracy: 1e6) + XCTAssertEqual(Double.infinity, .infinity, accuracy: .infinity) + XCTAssertEqual(Double.infinity, -.infinity, accuracy: .infinity) + XCTAssertEqual(Float.infinity, .infinity, accuracy: 1e-6) + XCTAssertEqual(Double.infinity, .infinity - 1, accuracy: 0) + } + +// CHECK: Test Case 'EqualityWithAccuracyTests.test_equalWithAccuracy_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: .*[/\\]EqualityWithAccuracy[/\\]main.swift:[[@LINE+3]]: error: EqualityWithAccuracyTests.test_equalWithAccuracy_fails : XCTAssertEqual failed: \("0\.0"\) is not equal to \("0\.2"\) \+\/- \("-0\.1"\) - $ +// CHECK: Test Case 'EqualityWithAccuracyTests.test_equalWithAccuracy_fails' failed \(\d+\.\d+ seconds\) + func test_equalWithAccuracy_fails() { + XCTAssertEqual(0, 0.2, accuracy: -0.1) + } + +// CHECK: Test Case 'EqualityWithAccuracyTests.test_notEqualWithAccuracy_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: Test Case 'EqualityWithAccuracyTests.test_notEqualWithAccuracy_passes' passed \(\d+\.\d+ seconds\) + func test_notEqualWithAccuracy_passes() { + XCTAssertNotEqual(1.0, 2.0, accuracy: -0.5) + XCTAssertNotEqual(0, 1, accuracy: 0.1) + XCTAssertNotEqual(1, 1.11, accuracy: 0.1) + XCTAssertNotEqual(1 as Float, 1.11, accuracy: 0.1) + XCTAssertNotEqual(1 as Float32, 1.11, accuracy: 0.1) + XCTAssertNotEqual(1 as Float64, 1.11, accuracy: 0.1) + XCTAssertNotEqual(1 as CGFloat, 1.11, accuracy: 0.1) + XCTAssertNotEqual(1 as Double, 1.11, accuracy: 0.1) + XCTAssertNotEqual(1 as Int, 10, accuracy: 5) + XCTAssertNotEqual(1 as UInt, 10, accuracy: 5) + XCTAssertNotEqual(1, -1, accuracy: 1) + XCTAssertNotEqual(-2, -4, accuracy: 1) + XCTAssertNotEqual(Double.nan, Double.nan, accuracy: 0) + XCTAssertNotEqual(1, Double.nan, accuracy: 0) + XCTAssertNotEqual(Double.nan, 1, accuracy: 0) + XCTAssertNotEqual(Double.nan, 1, accuracy: .nan) + XCTAssertNotEqual(Double.infinity, -.infinity, accuracy: 0) + XCTAssertNotEqual(Double.infinity, -.infinity, accuracy: 1) + XCTAssertNotEqual(Double.infinity, -.infinity, accuracy: 1e-6) + XCTAssertNotEqual(Double.infinity, -.infinity, accuracy: 1e6) + } + +// CHECK: Test Case 'EqualityWithAccuracyTests.test_notEqualWithAccuracy_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: .*[/\\]EqualityWithAccuracy[/\\]main.swift:[[@LINE+3]]: error: EqualityWithAccuracyTests.test_notEqualWithAccuracy_fails : XCTAssertNotEqual failed: \("1\.0"\) is equal to \("2\.0"\) \+/- \("-1\.0"\) - $ +// CHECK: Test Case 'EqualityWithAccuracyTests.test_notEqualWithAccuracy_fails' failed \(\d+\.\d+ seconds\) + func test_notEqualWithAccuracy_fails() { + XCTAssertNotEqual(1.0, 2.0, accuracy: -1.0) + } + +// CHECK: Test Case 'EqualityWithAccuracyTests.test_equalWithAccuracy_int_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: Test Case 'EqualityWithAccuracyTests.test_equalWithAccuracy_int_passes' passed \(\d+\.\d+ seconds\) + func test_equalWithAccuracy_int_passes() { + XCTAssertEqual(10, 11, accuracy: 1) + } + +// CHECK: Test Case 'EqualityWithAccuracyTests.test_equalWithAccuracy_int_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: .*[/\\]EqualityWithAccuracy[/\\]main.swift:[[@LINE+3]]: error: EqualityWithAccuracyTests.test_equalWithAccuracy_int_fails : XCTAssertEqual failed: \("10"\) is not equal to \("8"\) \+\/- \("1"\) - $ +// CHECK: Test Case 'EqualityWithAccuracyTests.test_equalWithAccuracy_int_fails' failed \(\d+\.\d+ seconds\) + func test_equalWithAccuracy_int_fails() { + XCTAssertEqual(10, 8, accuracy: 1) + } + +// CHECK: Test Case 'EqualityWithAccuracyTests.test_notEqualWithAccuracy_int_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: Test Case 'EqualityWithAccuracyTests.test_notEqualWithAccuracy_int_passes' passed \(\d+\.\d+ seconds\) + func test_notEqualWithAccuracy_int_passes() { + XCTAssertNotEqual(-1, 5, accuracy: 5) + } + +// CHECK: Test Case 'EqualityWithAccuracyTests.test_notEqualWithAccuracy_int_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: .*[/\\]EqualityWithAccuracy[/\\]main.swift:[[@LINE+3]]: error: EqualityWithAccuracyTests.test_notEqualWithAccuracy_int_fails : XCTAssertNotEqual failed: \("0"\) is equal to \("5"\) \+/- \("5"\) - $ +// CHECK: Test Case 'EqualityWithAccuracyTests.test_notEqualWithAccuracy_int_fails' failed \(\d+\.\d+ seconds\) + func test_notEqualWithAccuracy_int_fails() { + XCTAssertNotEqual(0, 5, accuracy: 5) + } + +// CHECK: Test Case 'EqualityWithAccuracyTests.test_equalWithAccuracy_infinity_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: .*[/\\]EqualityWithAccuracy[/\\]main.swift:[[@LINE+3]]: error: EqualityWithAccuracyTests.test_equalWithAccuracy_infinity_fails : XCTAssertEqual failed: \(\"-inf\"\) is not equal to \(\"inf\"\) \+\/- \(\"1e-06"\) - $ +// CHECK: Test Case 'EqualityWithAccuracyTests.test_equalWithAccuracy_infinity_fails' failed \(\d+\.\d+ seconds\) + func test_equalWithAccuracy_infinity_fails() { + XCTAssertEqual(-Double.infinity, .infinity, accuracy: 1e-6) + } + +// CHECK: Test Case 'EqualityWithAccuracyTests.test_notEqualWithAccuracy_infinity_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: .*[/\\]EqualityWithAccuracy[/\\]main.swift:[[@LINE+3]]: error: EqualityWithAccuracyTests.test_notEqualWithAccuracy_infinity_fails : XCTAssertNotEqual failed: \("-inf"\) is equal to \("-inf"\) \+/- \("1e-06"\) - $ +// CHECK: Test Case 'EqualityWithAccuracyTests.test_notEqualWithAccuracy_infinity_fails' failed \(\d+\.\d+ seconds\) + func test_notEqualWithAccuracy_infinity_fails() { + XCTAssertNotEqual(-Double.infinity, -.infinity, accuracy: 1e-6) + } + +// CHECK: Test Case 'EqualityWithAccuracyTests.test_equalWithAccuracy_nan_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: .*[/\\]EqualityWithAccuracy[/\\]main.swift:[[@LINE+3]]: error: EqualityWithAccuracyTests.test_equalWithAccuracy_nan_fails : XCTAssertEqual failed: \("nan"\) is not equal to \("nan"\) \+/- \("0.0"\) - $ +// CHECK: Test Case 'EqualityWithAccuracyTests.test_equalWithAccuracy_nan_fails' failed \(\d+\.\d+ seconds\) + func test_equalWithAccuracy_nan_fails() { + XCTAssertEqual(Double.nan, Double.nan, accuracy: 0) + } + +} +// CHECK: Test Suite 'EqualityWithAccuracyTests' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: \t Executed 11 tests, with 7 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds + +XCTMain([testCase(EqualityWithAccuracyTests.allTests)]) + +// CHECK: Test Suite '.*\.xctest' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: \t Executed 11 tests, with 7 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds +// CHECK: Test Suite 'All tests' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ +// CHECK: \t Executed 11 tests, with 7 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds diff --git a/Tests/Functional/InfinityAccuracyTestCase/main.swift b/Tests/Functional/InfinityAccuracyTestCase/main.swift deleted file mode 100644 index 3f27ccfeb..000000000 --- a/Tests/Functional/InfinityAccuracyTestCase/main.swift +++ /dev/null @@ -1,70 +0,0 @@ -// RUN: %{swiftc} %s -o %T/InfinityAccuracyTestCase -// RUN: %T/InfinityAccuracyTestCase > %t || true -// RUN: %{xctest_checker} %t %s - -#if os(macOS) - import SwiftXCTest -#else - import XCTest -#endif - -// Regression test for https://bugs.swift.org/browse/SR-13047 - -// CHECK: Test Suite 'All tests' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: Test Suite '.*\.xctest' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ - -// CHECK: Test Suite 'InfinityAccuracyTestCase' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -class InfinityAccuracyTestCase: XCTestCase { - static var allTests = { - return [ - ("test_equalWithAccuracy_double_passes", test_equalWithAccuracy_double_passes), - ("test_equalWithAccuracy_float_passes", test_equalWithAccuracy_float_passes), - ("test_equalWithAccuracy_fails", test_equalWithAccuracy_fails), - ("test_notEqualWithAccuracy_passes", test_notEqualWithAccuracy_passes), - ("test_notEqualWithAccuracy_fails", test_notEqualWithAccuracy_fails), - ] - }() - -// CHECK: Test Case 'InfinityAccuracyTestCase.test_equalWithAccuracy_double_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: Test Case 'InfinityAccuracyTestCase.test_equalWithAccuracy_double_passes' passed \(\d+\.\d+ seconds\) - func test_equalWithAccuracy_double_passes() { - XCTAssertEqual(-Double.infinity, -Double.infinity, accuracy: 1e-6) - XCTAssertEqual(Double.infinity, Double.infinity, accuracy: 1e-6) - } - -// CHECK: Test Case 'InfinityAccuracyTestCase.test_equalWithAccuracy_float_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: Test Case 'InfinityAccuracyTestCase.test_equalWithAccuracy_float_passes' passed \(\d+\.\d+ seconds\) - func test_equalWithAccuracy_float_passes() { - XCTAssertEqual(-Float.infinity, -Float.infinity, accuracy: 1e-6) - XCTAssertEqual(Float.infinity, Float.infinity, accuracy: 1e-6) - } - -// CHECK: Test Case 'InfinityAccuracyTestCase.test_equalWithAccuracy_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: .*[/\\]InfinityAccuracyTestCase[/\\]main.swift:[[@LINE+3]]: error: InfinityAccuracyTestCase.test_equalWithAccuracy_fails : XCTAssertEqual failed: \(\"-inf\"\) is not equal to \(\"inf\"\) \+\/- \(\"1e-06"\) - $ -// CHECK: Test Case 'InfinityAccuracyTestCase.test_equalWithAccuracy_fails' failed \(\d+\.\d+ seconds\) - func test_equalWithAccuracy_fails() { - XCTAssertEqual(-Double.infinity, Double.infinity, accuracy: 1e-6) - } - -// CHECK: Test Case 'InfinityAccuracyTestCase.test_notEqualWithAccuracy_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: Test Case 'InfinityAccuracyTestCase.test_notEqualWithAccuracy_passes' passed \(\d+\.\d+ seconds\) - func test_notEqualWithAccuracy_passes() { - XCTAssertNotEqual(-Double.infinity, Double.infinity, accuracy: 1e-6) - } - -// CHECK: Test Case 'InfinityAccuracyTestCase.test_notEqualWithAccuracy_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: .*[/\\]InfinityAccuracyTestCase[/\\]main.swift:[[@LINE+3]]: error: InfinityAccuracyTestCase.test_notEqualWithAccuracy_fails : XCTAssertNotEqual failed: \("-inf"\) is equal to \("-inf"\) \+/- \("1e-06"\) - $ -// CHECK: Test Case 'InfinityAccuracyTestCase.test_notEqualWithAccuracy_fails' failed \(\d+\.\d+ seconds\) - func test_notEqualWithAccuracy_fails() { - XCTAssertNotEqual(-Double.infinity, -Double.infinity, accuracy: 1e-6) - } -} -// CHECK: Test Suite 'InfinityAccuracyTestCase' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: \t Executed \d+ tests, with \d+ failures \(\d+ unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds - -XCTMain([testCase(InfinityAccuracyTestCase.allTests)]) - -// CHECK: Test Suite '.*\.xctest' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: \t Executed \d+ tests, with \d+ failures \(\d+ unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds -// CHECK: Test Suite 'All tests' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: \t Executed \d+ tests, with \d+ failures \(\d+ unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds diff --git a/Tests/Functional/NegativeAccuracyTestCase/main.swift b/Tests/Functional/NegativeAccuracyTestCase/main.swift deleted file mode 100644 index d98250917..000000000 --- a/Tests/Functional/NegativeAccuracyTestCase/main.swift +++ /dev/null @@ -1,93 +0,0 @@ -// RUN: %{swiftc} %s -o %T/NegativeAccuracyTestCase -// RUN: %T/NegativeAccuracyTestCase > %t || true -// RUN: %{xctest_checker} %t %s - -#if os(macOS) - import SwiftXCTest -#else - import XCTest -#endif - -// Regression test for https://github.com/apple/swift-corelibs-xctest/pull/7 -// and https://github.com/apple/swift-corelibs-xctest/pull/294 - -// CHECK: Test Suite 'All tests' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: Test Suite '.*\.xctest' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ - -// CHECK: Test Suite 'NegativeAccuracyTestCase' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -class NegativeAccuracyTestCase: XCTestCase { - static var allTests = { - return [ - ("test_equalWithAccuracy_passes", test_equalWithAccuracy_passes), - ("test_equalWithAccuracy_fails", test_equalWithAccuracy_fails), - ("test_notEqualWithAccuracy_passes", test_notEqualWithAccuracy_passes), - ("test_notEqualWithAccuracy_fails", test_notEqualWithAccuracy_fails), - ("test_equalWithAccuracy_int_passes", test_equalWithAccuracy_int_passes), - ("test_equalWithAccuracy_int_fails", test_equalWithAccuracy_int_fails), - ("test_notEqualWithAccuracy_int_passes", test_notEqualWithAccuracy_int_passes), - ("test_notEqualWithAccuracy_int_fails", test_notEqualWithAccuracy_int_fails), - ] - }() - -// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_passes' passed \(\d+\.\d+ seconds\) - func test_equalWithAccuracy_passes() { - XCTAssertEqual(0, 0.1, accuracy: -0.1) - } - -// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: .*[/\\]NegativeAccuracyTestCase[/\\]main.swift:[[@LINE+3]]: error: NegativeAccuracyTestCase.test_equalWithAccuracy_fails : XCTAssertEqual failed: \("0\.0"\) is not equal to \("0\.2"\) \+\/- \("-0\.1"\) - $ -// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_fails' failed \(\d+\.\d+ seconds\) - func test_equalWithAccuracy_fails() { - XCTAssertEqual(0, 0.2, accuracy: -0.1) - } - -// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_passes' passed \(\d+\.\d+ seconds\) - func test_notEqualWithAccuracy_passes() { - XCTAssertNotEqual(1.0, 2.0, accuracy: -0.5) - } - -// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: .*[/\\]NegativeAccuracyTestCase[/\\]main.swift:[[@LINE+3]]: error: NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails : XCTAssertNotEqual failed: \("1\.0"\) is equal to \("2\.0"\) \+/- \("-1\.0"\) - $ -// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails' failed \(\d+\.\d+ seconds\) - func test_notEqualWithAccuracy_fails() { - XCTAssertNotEqual(1.0, 2.0, accuracy: -1.0) - } - -// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_int_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_int_passes' passed \(\d+\.\d+ seconds\) - func test_equalWithAccuracy_int_passes() { - XCTAssertEqual(10, 11, accuracy: 1) - } - -// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_int_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: .*[/\\]NegativeAccuracyTestCase[/\\]main.swift:[[@LINE+3]]: error: NegativeAccuracyTestCase.test_equalWithAccuracy_int_fails : XCTAssertEqual failed: \("10"\) is not equal to \("8"\) \+\/- \("1"\) - $ -// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_int_fails' failed \(\d+\.\d+ seconds\) - func test_equalWithAccuracy_int_fails() { - XCTAssertEqual(10, 8, accuracy: 1) - } - -// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_int_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_int_passes' passed \(\d+\.\d+ seconds\) - func test_notEqualWithAccuracy_int_passes() { - XCTAssertNotEqual(-1, 5, accuracy: 5) - } - -// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_int_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: .*[/\\]NegativeAccuracyTestCase[/\\]main.swift:[[@LINE+3]]: error: NegativeAccuracyTestCase.test_notEqualWithAccuracy_int_fails : XCTAssertNotEqual failed: \("0"\) is equal to \("5"\) \+/- \("5"\) - $ -// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_int_fails' failed \(\d+\.\d+ seconds\) - func test_notEqualWithAccuracy_int_fails() { - XCTAssertNotEqual(0, 5, accuracy: 5) - } - -} -// CHECK: Test Suite 'NegativeAccuracyTestCase' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: \t Executed 8 tests, with 4 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds - -XCTMain([testCase(NegativeAccuracyTestCase.allTests)]) - -// CHECK: Test Suite '.*\.xctest' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: \t Executed 8 tests, with 4 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds -// CHECK: Test Suite 'All tests' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ -// CHECK: \t Executed 8 tests, with 4 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds