Skip to content

Commit 0143cfa

Browse files
committed
[Tests] Add regression tests for pull request #7
#7 fixed a problem with XCTAssertEqualsWithAccuracy. This test ensures that fix does not regress.
1 parent ef71de2 commit 0143cfa

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
@@ -45,6 +45,7 @@
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>"; };
4747
DADB975E1C44BE8B005E68B6 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
48+
DADB97581C406879005E68B6 /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
4849
EA3E74BB1BF2B6D500635A73 /* build_script.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = build_script.py; sourceTree = "<group>"; };
4950
/* End PBXFileReference section */
5051

@@ -124,6 +125,7 @@
124125
DA78F7E91C4039410082E15B /* lit.cfg */,
125126
DA78F7EA1C4039410082E15B /* SingleFailingTestCase */,
126127
DADB975D1C44BE73005E68B6 /* FailingTestSuite */,
128+
DADB97571C406879005E68B6 /* NegativeAccuracyTestCase */,
127129
DA78F7ED1C4039410082E15B /* xctest_checker */,
128130
);
129131
path = Functional;
@@ -176,6 +178,14 @@
176178
path = FailingTestSuite;
177179
sourceTree = "<group>";
178180
};
181+
DADB97571C406879005E68B6 /* NegativeAccuracyTestCase */ = {
182+
isa = PBXGroup;
183+
children = (
184+
DADB97581C406879005E68B6 /* main.swift */,
185+
);
186+
path = NegativeAccuracyTestCase;
187+
sourceTree = "<group>";
188+
};
179189
EA3E74BC1BF2B6D700635A73 /* Linux Build */ = {
180190
isa = PBXGroup;
181191
children = (

0 commit comments

Comments
 (0)