diff --git a/Sources/XCTest/XCTestCase.swift b/Sources/XCTest/XCTestCase.swift index e43d1cbf2..3bb0c65ce 100644 --- a/Sources/XCTest/XCTestCase.swift +++ b/Sources/XCTest/XCTestCase.swift @@ -55,6 +55,8 @@ extension XCTestCase { tearDown() totalDuration += duration + + var result = "passed" for failure in failures { failure.emit(method) totalFailures += 1 @@ -62,11 +64,11 @@ extension XCTestCase { 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 } } diff --git a/Tests/Functional/FailingTestSuite/main.swift b/Tests/Functional/FailingTestSuite/main.swift new file mode 100644 index 000000000..c7aa2e54f --- /dev/null +++ b/Tests/Functional/FailingTestSuite/main.swift @@ -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(), +]) diff --git a/XCTest.xcodeproj/project.pbxproj b/XCTest.xcodeproj/project.pbxproj index d9f3f9b9f..7bd867ffa 100644 --- a/XCTest.xcodeproj/project.pbxproj +++ b/XCTest.xcodeproj/project.pbxproj @@ -44,6 +44,7 @@ DA78F7F61C4039410082E15B /* compare.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = compare.py; sourceTree = ""; }; DA78F7F81C4039410082E15B /* main.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = main.py; sourceTree = ""; }; DA78F7FA1C4039410082E15B /* xctest_checker.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = xctest_checker.py; sourceTree = ""; }; + DADB975E1C44BE8B005E68B6 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; EA3E74BB1BF2B6D500635A73 /* build_script.py */ = {isa = PBXFileReference; lastKnownFileType = text.script.python; path = build_script.py; sourceTree = ""; }; /* End PBXFileReference section */ @@ -122,6 +123,7 @@ children = ( DA78F7E91C4039410082E15B /* lit.cfg */, DA78F7EA1C4039410082E15B /* SingleFailingTestCase */, + DADB975D1C44BE73005E68B6 /* FailingTestSuite */, DA78F7ED1C4039410082E15B /* xctest_checker */, ); path = Functional; @@ -166,6 +168,14 @@ path = xctest_checker; sourceTree = ""; }; + DADB975D1C44BE73005E68B6 /* FailingTestSuite */ = { + isa = PBXGroup; + children = ( + DADB975E1C44BE8B005E68B6 /* main.swift */, + ); + path = FailingTestSuite; + sourceTree = ""; + }; EA3E74BC1BF2B6D700635A73 /* Linux Build */ = { isa = PBXGroup; children = (