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
8 changes: 5 additions & 3 deletions Sources/XCTest/XCTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,20 @@ extension XCTestCase {
tearDown()

totalDuration += duration

var result = "passed"
for failure in failures {
failure.emit(method)
totalFailures += 1
if !failure.expected {
unexpectedFailures += 1
}

let result = failures.count > 0 ? "failed" : "passed"

print("Test Case '\(method)' \(result) (\(printableStringForTimeInterval(duration)) seconds).")
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).")
XCTFailureHandler = nil
}
}
Expand Down
61 changes: 61 additions & 0 deletions Tests/Functional/FailingTestSuite/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// RUN: %{swiftc} %s -o %{built_tests_dir}/FailingTestSuite
// RUN: %{built_tests_dir}/FailingTestSuite > %t || true
// RUN: %{xctest_checker} %t %s
// CHECK: Test Case 'PassingTestCase.test_passes' started.
// CHECK: Test Case 'PassingTestCase.test_passes' passed \(\d+\.\d+ seconds\).
// CHECK: Executed 1 test, with 0 failures \(0 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
// CHECK: Test Case 'FailingTestCase.test_passes' started.
// CHECK: Test Case 'FailingTestCase.test_passes' passed \(\d+\.\d+ seconds\).
// CHECK: Test Case 'FailingTestCase.test_fails' started.
// CHECK: .*/Tests/Functional/FailingTestSuite/main.swift:50: error: FailingTestCase.test_fails : XCTAssertTrue failed - $
// CHECK: Test Case 'FailingTestCase.test_fails' failed \(\d+\.\d+ seconds\).
// CHECK: Test Case 'FailingTestCase.test_fails_with_message' started.
// 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

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

class PassingTestCase: XCTestCase {
var allTests: [(String, () -> ())] {
return [
("test_passes", test_passes),
]
}

func test_passes() {
XCTAssert(true)
}
}

class FailingTestCase: XCTestCase {
var allTests: [(String, () -> ())] {
return [
("test_passes", test_passes),
("test_fails", test_fails),
("test_fails_with_message", test_fails_with_message),
]
}

func test_passes() {
XCTAssert(true)
}

func test_fails() {
XCTAssert(false)
}

func test_fails_with_message() {
XCTAssert(false, "Foo bar.")
}
}

XCTMain([
PassingTestCase(),
FailingTestCase(),
])
10 changes: 10 additions & 0 deletions XCTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
DA78F7F61C4039410082E15B /* compare.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = compare.py; sourceTree = "<group>"; };
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>"; };
EA3E74BB1BF2B6D500635A73 /* build_script.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = build_script.py; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -122,6 +123,7 @@
children = (
DA78F7E91C4039410082E15B /* lit.cfg */,
DA78F7EA1C4039410082E15B /* SingleFailingTestCase */,
DADB975D1C44BE73005E68B6 /* FailingTestSuite */,
DA78F7ED1C4039410082E15B /* xctest_checker */,
);
path = Functional;
Expand Down Expand Up @@ -166,6 +168,14 @@
path = xctest_checker;
sourceTree = "<group>";
};
DADB975D1C44BE73005E68B6 /* FailingTestSuite */ = {
isa = PBXGroup;
children = (
DADB975E1C44BE8B005E68B6 /* main.swift */,
);
path = FailingTestSuite;
sourceTree = "<group>";
};
EA3E74BC1BF2B6D700635A73 /* Linux Build */ = {
isa = PBXGroup;
children = (
Expand Down