0001 // This source file is part of the Swift.org open source project 0002 // 0003 // Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors 0004 // Licensed under Apache License v2.0 with Runtime Library Exception 0005 // 0006 // See http://swift.org/LICENSE.txt for license information 0007 // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors 0008 // 0009 // 0010 // XCTestMain.swift 0011 // This is the main file for the framework. It provides the entry point function 0012 // for running tests and some infrastructure for running them. 0013 // 0014 0015 #if os(Linux) || os(FreeBSD) 0016 import Glibc 0017 #else 0018 import Darwin 0019 #endif 0020 0021 struct XCTFailure{ 0022 var message
XCTAssert.swift:98 handler(XCTFailure(message: message(), failureDescription: result.failureDescription(assertion), expected: result.expected, file: file, line: line))XCTestCase.swift:53 state.failures = [XCTFailure]()XCTestCase.swift:93 let unexpectedFailure = XCTFailure(message: "", failureDescription: "threw error \"\(error)\"", expected: false, file: "<EXPR>", line: 0)XCTestCase.swift:158 var failures = [XCTFailure]()XCTestMain.swift:37 var failures: [XCTFailure]XCTestMain.swift:38 var unexpectedFailures: [XCTFailure] {XCTestMain.swift:89 internal var XCTFailureHandler: (XCTFailure -> Void)?: String 0023 var failureDescription
XCTestMain.swift:29 print("\(file):\(line): \(expected ? "" : "unexpected ")error: \(method) : \(failureDescription) - \(message)"): String 0024 var expected
XCTestMain.swift:29 print("\(file):\(line): \(expected ? "" : "unexpected ")error: \(method) : \(failureDescription) - \(message)"): Bool 0025 var file
XCTestCase.swift:118 if !failure.expected {XCTestMain.swift:29 print("\(file):\(line): \(expected ? "" : "unexpected ")error: \(method) : \(failureDescription) - \(message)")XCTestMain.swift:39 get { return failures.filter({ failure -> Bool in failure.expected == false }) }: StaticString 0026 var line
XCTestMain.swift:29 print("\(file):\(line): \(expected ? "" : "unexpected ")error: \(method) : \(failureDescription) - \(message)"): UInt 0027 0028 func emit
XCTestMain.swift:29 print("\(file):\(line): \(expected ? "" : "unexpected ")error: \(method) : \(failureDescription) - \(message)")(method: String) { 0029 print("\(file):\(line): \(expected ? "" : "unexpected ")error: \(method) : \(failureDescription) - \(message)") 0030 } 0031 } 0032 0033 internal struct XCTRun
XCTestCase.swift:116 failure.emit(state.method){ 0034 var duration
XCTestCase.swift:126 XCTAllRuns.append(XCTRun(duration: duration, method: state.method, passed: state.failures.count == 0, failures: state.failures))XCTestMain.swift:90 internal var XCTAllRuns = [XCTRun](): TimeInterval 0035 var method: String 0036 var passed: Bool 0037 var failures
XCTestMain.swift:73 let (totalDuration, totalFailures, totalUnexpectedFailures) = XCTAllRuns.reduce((0.0, 0, 0)) { totals, run in (totals.0 + run.duration, totals.1 + run.failures.count, totals.2 + run.unexpectedFailures.count) }: [XCTFailure] 0038 var unexpectedFailures
XCTestMain.swift:39 get { return failures.filter({ failure -> Bool in failure.expected == false }) }XCTestMain.swift:73 let (totalDuration, totalFailures, totalUnexpectedFailures) = XCTAllRuns.reduce((0.0, 0, 0)) { totals, run in (totals.0 + run.duration, totals.1 + run.failures.count, totals.2 + run.unexpectedFailures.count) }: [XCTFailure] { 0039 get { return failures.filter({ failure -> Bool in failure.expected == false }) } 0040 } 0041 } 0042 0043 /// Starts a test run for the specified test cases. 0044 /// 0045 /// This function will not return. If the test cases pass, then it will call `exit(0)`. If there is a failure, then it will call `exit(1)`. 0046 /// - Parameter testCases: An array of test cases to run. 0047 @noreturn public func XCTMain(testCases: [XCTestCase]) { 0048 0049 // The test cases are run in a loop within a closure. This closure 0050 // enables the test case "loop" to be "continued" from within the 0051 // test failure handler closure. Thus enabling a set of test cases 0052 // to continue after a test in one of them has failed. 0053 // 0054 // Note: The index (idx) is initialized to -1, do to the fact the that 0055 // test case loop closure always initially increments the index by one to 0056 // move to the test case after the one that had a test that failed. 0057 0058 var idx = -1 0059 XCTMainTestLoop = { () in 0060 idx += 1 0061 while idx < testCases.count { 0062 testCases[idx].invokeTest() 0063 idx += 1 0064 } 0065 } 0066 0067 XCTMainTestLoop!() 0068 0069 postTests() 0070 } 0071 0072 @noreturn internal func postTests
XCTestMain.swift:73 let (totalDuration, totalFailures, totalUnexpectedFailures) = XCTAllRuns.reduce((0.0, 0, 0)) { totals, run in (totals.0 + run.duration, totals.1 + run.failures.count, totals.2 + run.unexpectedFailures.count) }() { 0073 let (totalDuration, totalFailures, totalUnexpectedFailures) = XCTAllRuns.reduce((0.0, 0, 0)) { totals, run in (totals.0 + run.duration, totals.1 + run.failures.count, totals.2 + run.unexpectedFailures.count) } 0074 0075 var testCountSuffix = "s" 0076 if XCTAllRuns.count == 1 { 0077 testCountSuffix = "" 0078 } 0079 var failureSuffix = "s" 0080 if totalFailures == 1 { 0081 failureSuffix = "" 0082 } 0083 0084 print("Total executed \(XCTAllRuns.count) test\(testCountSuffix), with \(totalFailures) failure\(failureSuffix) (\(totalUnexpectedFailures) unexpected) in \(printableStringForTimeInterval(totalDuration)) seconds") 0085 exit(totalFailures > 0 ? 1 : 0) 0086 } 0087 0088 internal var XCTMainTestLoop
XCTestCase.swift:78 postTests()XCTestMain.swift:69 postTests(): (()->Void)? 0089 internal var XCTFailureHandler
XCTestCase.swift:76 XCTMainTestLoop!()XCTestMain.swift:59 XCTMainTestLoop = { () inXCTestMain.swift:67 XCTMainTestLoop!(): (XCTFailure -> Void)? 0090 internal var XCTAllRuns
XCTAssert.swift:97 if let handler = XCTFailureHandler {XCTestCase.swift:55 XCTFailureHandler = { failure inXCTestCase.swift:94 XCTFailureHandler!(unexpectedFailure)XCTestCase.swift:127 XCTFailureHandler = nil= [XCTRun]() 0091
XCTestCase.swift:126 XCTAllRuns.append(XCTRun(duration: duration, method: state.method, passed: state.failures.count == 0, failures: state.failures))XCTestMain.swift:73 let (totalDuration, totalFailures, totalUnexpectedFailures) = XCTAllRuns.reduce((0.0, 0, 0)) { totals, run in (totals.0 + run.duration, totals.1 + run.failures.count, totals.2 + run.unexpectedFailures.count) }XCTestMain.swift:76 if XCTAllRuns.count == 1 {XCTestMain.swift:84 print("Total executed \(XCTAllRuns.count) test\(testCountSuffix), with \(totalFailures) failure\(failureSuffix) (\(totalUnexpectedFailures) unexpected) in \(printableStringForTimeInterval(totalDuration)) seconds")