Skip to content

Commit 3ec43ad

Browse files
committed
[Tests] Add regression tests for pull request swiftlang#7
swiftlang#7 fix a problem with XCTAssertEqualsWithAccuracy. This test ensures that fix does not regress.
1 parent 8181c16 commit 3ec43ad

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// RUN: %{swiftc} %s -o %{built_tests_dir}/NegativeAccuracyTestCase
2+
// RUN: %{built_tests_dir}/NegativeAccuracyTestCase > %t || true
3+
// RUN: %{xctest_checker} %t %s
4+
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_passes' started.
5+
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_passes' passed \(\d+\.\d+ seconds\).
6+
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_fails' started.
7+
// CHECK: .*/Tests/Functional/NegativeAccuracyTestCase/main.swift:39: error: NegativeAccuracyTestCase.test_equalWithAccuracy_fails : XCTAssertEqualWithAccuracy failed: \(\"0\.0\"\) is not equal to \(\"0\.2\"\) \+\/- \(\"-0\.1\"\) - $
8+
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_fails' failed \(\d+\.\d+ seconds\).
9+
// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_passes' started.
10+
// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_passes' passed \(\d+\.\d+ seconds\).
11+
// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails' started.
12+
// CHECK: .*/Tests/Functional/NegativeAccuracyTestCase/main.swift:47: error: NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails : XCTAssertNotEqualWithAccuracy failed: \("1\.0"\) is equal to \("2\.0"\) \+/- \("-1\.0"\) - $
13+
// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails' failed \(\d+\.\d+ seconds\).
14+
// CHECK: Executed 4 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
15+
// CHECK: Total executed 4 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
16+
17+
#if os(Linux) || os(FreeBSD)
18+
import XCTest
19+
#else
20+
import SwiftXCTest
21+
#endif
22+
23+
// Regression test for https://github.com/apple/swift-corelibs-xctest/pull/7
24+
class NegativeAccuracyTestCase: XCTestCase {
25+
var allTests: [(String, () -> ())] {
26+
return [
27+
("test_equalWithAccuracy_passes", test_equalWithAccuracy_passes),
28+
("test_equalWithAccuracy_fails", test_equalWithAccuracy_fails),
29+
("test_notEqualWithAccuracy_passes", test_notEqualWithAccuracy_passes),
30+
("test_notEqualWithAccuracy_fails", test_notEqualWithAccuracy_fails),
31+
]
32+
}
33+
34+
func test_equalWithAccuracy_passes() {
35+
XCTAssertEqualWithAccuracy(0, 0.1, accuracy: -0.1)
36+
}
37+
38+
func test_equalWithAccuracy_fails() {
39+
XCTAssertEqualWithAccuracy(0, 0.2, accuracy: -0.1)
40+
}
41+
42+
func test_notEqualWithAccuracy_passes() {
43+
XCTAssertNotEqualWithAccuracy(1, 2, -0.5)
44+
}
45+
46+
func test_notEqualWithAccuracy_fails() {
47+
XCTAssertNotEqualWithAccuracy(1, 2, -1)
48+
}
49+
}
50+
51+
XCTMain([NegativeAccuracyTestCase()])

XCTest.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
DA78F7F61C4039410082E15B /* compare.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = compare.py; sourceTree = "<group>"; };
4545
DA78F7F81C4039410082E15B /* main.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = main.py; sourceTree = "<group>"; };
4646
DA78F7FA1C4039410082E15B /* xctest_checker.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = xctest_checker.py; sourceTree = "<group>"; };
47+
DADB97581C406879005E68B6 /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
4748
EA3E74BB1BF2B6D500635A73 /* build_script.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = build_script.py; sourceTree = "<group>"; };
4849
/* End PBXFileReference section */
4950

@@ -122,6 +123,7 @@
122123
children = (
123124
DA78F7E91C4039410082E15B /* lit.cfg */,
124125
DA78F7EA1C4039410082E15B /* SingleFailingTestCase */,
126+
DADB97571C406879005E68B6 /* NegativeAccuracyTestCase */,
125127
DA78F7ED1C4039410082E15B /* xctest_checker */,
126128
);
127129
path = Functional;
@@ -166,6 +168,14 @@
166168
path = xctest_checker;
167169
sourceTree = "<group>";
168170
};
171+
DADB97571C406879005E68B6 /* NegativeAccuracyTestCase */ = {
172+
isa = PBXGroup;
173+
children = (
174+
DADB97581C406879005E68B6 /* main.swift */,
175+
);
176+
path = NegativeAccuracyTestCase;
177+
sourceTree = "<group>";
178+
};
169179
EA3E74BC1BF2B6D700635A73 /* Linux Build */ = {
170180
isa = PBXGroup;
171181
children = (

0 commit comments

Comments
 (0)