Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Sources/XCTest/XCTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ extension XCTestCase {
if !failure.expected {
unexpectedFailures += 1
}

result = failures.count > 0 ? "failed" : "passed"
XCTAllRuns.append(XCTRun(duration: duration, method: method, passed: failures.count == 0, failures: failures))
}

print("Test Case '\(method)' \(result) (\(printableStringForTimeInterval(duration)) seconds).")
XCTAllRuns.append(XCTRun(duration: duration, method: method, passed: failures.count == 0, failures: failures))
XCTFailureHandler = nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/FailingTestSuite/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// CHECK: .*/Tests/Functional/FailingTestSuite/main.swift:54: error: FailingTestCase.test_fails_with_message : XCTAssertTrue failed - Foo bar.
// CHECK: Test Case 'FailingTestCase.test_fails_with_message' failed \(\d+\.\d+ seconds\).
// CHECK: Executed 3 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
// CHECK: Total executed 2 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
// CHECK: Total executed 4 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds

#if os(Linux) || os(FreeBSD)
import XCTest
Expand Down
51 changes: 51 additions & 0 deletions Tests/Functional/NegativeAccuracyTestCase/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// RUN: %{swiftc} %s -o %{built_tests_dir}/NegativeAccuracyTestCase
// RUN: %{built_tests_dir}/NegativeAccuracyTestCase > %t || true
// RUN: %{xctest_checker} %t %s
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_passes' started.
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_passes' passed \(\d+\.\d+ seconds\).
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_fails' started.
// CHECK: .*/Tests/Functional/NegativeAccuracyTestCase/main.swift:39: error: NegativeAccuracyTestCase.test_equalWithAccuracy_fails : XCTAssertEqualWithAccuracy failed: \(\"0\.0\"\) is not equal to \(\"0\.2\"\) \+\/- \(\"-0\.1\"\) - $
// CHECK: Test Case 'NegativeAccuracyTestCase.test_equalWithAccuracy_fails' failed \(\d+\.\d+ seconds\).
// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_passes' started.
// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_passes' passed \(\d+\.\d+ seconds\).
// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails' started.
// CHECK: .*/Tests/Functional/NegativeAccuracyTestCase/main.swift:47: error: NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails : XCTAssertNotEqualWithAccuracy failed: \("1\.0"\) is equal to \("2\.0"\) \+/- \("-1\.0"\) - $
// CHECK: Test Case 'NegativeAccuracyTestCase.test_notEqualWithAccuracy_fails' failed \(\d+\.\d+ seconds\).
// CHECK: Executed 4 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
// CHECK: Total executed 4 tests, with 2 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds

#if os(Linux) || os(FreeBSD)
import XCTest
#else
import SwiftXCTest
#endif

// Regression test for https://github.com/apple/swift-corelibs-xctest/pull/7
class NegativeAccuracyTestCase: XCTestCase {
var allTests: [(String, () -> ())] {
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),
]
}

func test_equalWithAccuracy_passes() {
XCTAssertEqualWithAccuracy(0, 0.1, accuracy: -0.1)
}

func test_equalWithAccuracy_fails() {
XCTAssertEqualWithAccuracy(0, 0.2, accuracy: -0.1)
}

func test_notEqualWithAccuracy_passes() {
XCTAssertNotEqualWithAccuracy(1, 2, -0.5)
}

func test_notEqualWithAccuracy_fails() {
XCTAssertNotEqualWithAccuracy(1, 2, -1)
}
}

XCTMain([NegativeAccuracyTestCase()])
10 changes: 10 additions & 0 deletions XCTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
DA78F7F81C4039410082E15B /* main.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = main.py; sourceTree = "<group>"; };
DA78F7FA1C4039410082E15B /* xctest_checker.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = xctest_checker.py; sourceTree = "<group>"; };
DADB975E1C44BE8B005E68B6 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
DADB97581C406879005E68B6 /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
EA3E74BB1BF2B6D500635A73 /* build_script.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = build_script.py; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -124,6 +125,7 @@
DA78F7E91C4039410082E15B /* lit.cfg */,
DA78F7EA1C4039410082E15B /* SingleFailingTestCase */,
DADB975D1C44BE73005E68B6 /* FailingTestSuite */,
DADB97571C406879005E68B6 /* NegativeAccuracyTestCase */,
DA78F7ED1C4039410082E15B /* xctest_checker */,
);
path = Functional;
Expand Down Expand Up @@ -176,6 +178,14 @@
path = FailingTestSuite;
sourceTree = "<group>";
};
DADB97571C406879005E68B6 /* NegativeAccuracyTestCase */ = {
isa = PBXGroup;
children = (
DADB97581C406879005E68B6 /* main.swift */,
);
path = NegativeAccuracyTestCase;
sourceTree = "<group>";
};
EA3E74BC1BF2B6D700635A73 /* Linux Build */ = {
isa = PBXGroup;
children = (
Expand Down