|
| 1 | +// RUN: %{swiftc} %s -o %T/InfinityAccuracyTestCase |
| 2 | +// RUN: %T/InfinityAccuracyTestCase > %t || true |
| 3 | +// RUN: %{xctest_checker} %t %s |
| 4 | + |
| 5 | +#if os(macOS) |
| 6 | + import SwiftXCTest |
| 7 | +#else |
| 8 | + import XCTest |
| 9 | +#endif |
| 10 | + |
| 11 | +// Regression test for https://bugs.swift.org/browse/SR-13047 |
| 12 | + |
| 13 | +// CHECK: Test Suite 'All tests' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ |
| 14 | +// CHECK: Test Suite '.*\.xctest' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ |
| 15 | + |
| 16 | +// CHECK: Test Suite 'InfinityAccuracyTestCase' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ |
| 17 | +class InfinityAccuracyTestCase: XCTestCase { |
| 18 | + static var allTests = { |
| 19 | + return [ |
| 20 | + ("test_equalWithAccuracy_double_passes", test_equalWithAccuracy_double_passes), |
| 21 | + ("test_equalWithAccuracy_float_passes", test_equalWithAccuracy_float_passes), |
| 22 | + ("test_equalWithAccuracy_fails", test_equalWithAccuracy_fails), |
| 23 | + ("test_notEqualWithAccuracy_passes", test_notEqualWithAccuracy_passes), |
| 24 | + ("test_notEqualWithAccuracy_fails", test_notEqualWithAccuracy_fails), |
| 25 | + ] |
| 26 | + }() |
| 27 | + |
| 28 | +// CHECK: Test Case 'InfinityAccuracyTestCase.test_equalWithAccuracy_double_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ |
| 29 | +// CHECK: Test Case 'InfinityAccuracyTestCase.test_equalWithAccuracy_double_passes' passed \(\d+\.\d+ seconds\) |
| 30 | + func test_equalWithAccuracy_double_passes() { |
| 31 | + XCTAssertEqual(-Double.infinity, -Double.infinity, accuracy: 1e-6) |
| 32 | + XCTAssertEqual(Double.infinity, Double.infinity, accuracy: 1e-6) |
| 33 | + } |
| 34 | + |
| 35 | +// CHECK: Test Case 'InfinityAccuracyTestCase.test_equalWithAccuracy_float_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ |
| 36 | +// CHECK: Test Case 'InfinityAccuracyTestCase.test_equalWithAccuracy_float_passes' passed \(\d+\.\d+ seconds\) |
| 37 | + func test_equalWithAccuracy_float_passes() { |
| 38 | + XCTAssertEqual(-Float.infinity, -Float.infinity, accuracy: 1e-6) |
| 39 | + XCTAssertEqual(Float.infinity, Float.infinity, accuracy: 1e-6) |
| 40 | + } |
| 41 | + |
| 42 | +// CHECK: Test Case 'InfinityAccuracyTestCase.test_equalWithAccuracy_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ |
| 43 | +// CHECK: .*[/\\]InfinityAccuracyTestCase[/\\]main.swift:[[@LINE+3]]: error: InfinityAccuracyTestCase.test_equalWithAccuracy_fails : XCTAssertEqual failed: \(\"-inf\"\) is not equal to \(\"inf\"\) \+\/- \(\"1e-06"\) - $ |
| 44 | +// CHECK: Test Case 'InfinityAccuracyTestCase.test_equalWithAccuracy_fails' failed \(\d+\.\d+ seconds\) |
| 45 | + func test_equalWithAccuracy_fails() { |
| 46 | + XCTAssertEqual(-Double.infinity, Double.infinity, accuracy: 1e-6) |
| 47 | + } |
| 48 | + |
| 49 | +// CHECK: Test Case 'InfinityAccuracyTestCase.test_notEqualWithAccuracy_passes' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ |
| 50 | +// CHECK: Test Case 'InfinityAccuracyTestCase.test_notEqualWithAccuracy_passes' passed \(\d+\.\d+ seconds\) |
| 51 | + func test_notEqualWithAccuracy_passes() { |
| 52 | + XCTAssertNotEqual(-Double.infinity, Double.infinity, accuracy: 1e-6) |
| 53 | + } |
| 54 | + |
| 55 | +// CHECK: Test Case 'InfinityAccuracyTestCase.test_notEqualWithAccuracy_fails' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ |
| 56 | +// CHECK: .*[/\\]InfinityAccuracyTestCase[/\\]main.swift:[[@LINE+3]]: error: InfinityAccuracyTestCase.test_notEqualWithAccuracy_fails : XCTAssertNotEqual failed: \("-inf"\) is equal to \("-inf"\) \+/- \("1e-06"\) - $ |
| 57 | +// CHECK: Test Case 'InfinityAccuracyTestCase.test_notEqualWithAccuracy_fails' failed \(\d+\.\d+ seconds\) |
| 58 | + func test_notEqualWithAccuracy_fails() { |
| 59 | + XCTAssertNotEqual(-Double.infinity, -Double.infinity, accuracy: 1e-6) |
| 60 | + } |
| 61 | +} |
| 62 | +// CHECK: Test Suite 'InfinityAccuracyTestCase' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ |
| 63 | +// CHECK: \t Executed \d+ tests, with \d+ failures \(\d+ unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds |
| 64 | + |
| 65 | +XCTMain([testCase(InfinityAccuracyTestCase.allTests)]) |
| 66 | + |
| 67 | +// CHECK: Test Suite '.*\.xctest' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ |
| 68 | +// CHECK: \t Executed \d+ tests, with \d+ failures \(\d+ unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds |
| 69 | +// CHECK: Test Suite 'All tests' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+ |
| 70 | +// CHECK: \t Executed \d+ tests, with \d+ failures \(\d+ unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds |
0 commit comments