File tree Expand file tree Collapse file tree 3 files changed +28
-3
lines changed
Tests/Functional/ArgumentParser Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ internal struct ArgumentParser {
5050
5151 private let arguments : [ String ]
5252
53- init ( arguments: [ String ] = CommandLine . arguments ) {
53+ init ( arguments: [ String ] ) {
5454 self . arguments = arguments
5555 }
5656
Original file line number Diff line number Diff line change 6060/// - Parameter testCases: An array of test cases run, each produced by a call to the `testCase` function
6161/// - seealso: `testCase`
6262public func XCTMain( _ testCases: [ XCTestCaseEntry ] ) -> Never {
63+ XCTMain ( testCases, arguments: CommandLine . arguments)
64+ }
65+ public func XCTMain( _ testCases: [ XCTestCaseEntry ] , arguments: [ String ] ) -> Never {
6366 let testBundle = Bundle . main
6467
65- let executionMode = ArgumentParser ( ) . executionMode
68+ let executionMode = ArgumentParser ( arguments : arguments ) . executionMode
6669
6770 // Apple XCTest behaves differently if tests have been filtered:
6871 // - The root `XCTestSuite` is named "Selected tests" instead of
@@ -96,7 +99,7 @@ public func XCTMain(_ testCases: [XCTestCaseEntry]) -> Never {
9699 let errMsg = " Error: Invalid option \" \( invalid) \" \n "
97100 FileHandle . standardError. write ( errMsg. data ( using: . utf8) ?? Data ( ) )
98101 }
99- let exeName = URL ( fileURLWithPath: CommandLine . arguments [ 0 ] ) . lastPathComponent
102+ let exeName = URL ( fileURLWithPath: arguments [ 0 ] ) . lastPathComponent
100103 let sampleTest = rootTestSuite. list ( ) . first ?? " Tests.FooTestCase/testFoo "
101104 let sampleTests = sampleTest. prefix ( while: { $0 != " / " } )
102105 print ( """
Original file line number Diff line number Diff line change 1+ // RUN: %{swiftc} %s -o %T/ArgumentParser
2+ // RUN: %T/ArgumentParser
3+
4+ #if os(macOS)
5+ import SwiftXCTest
6+ #else
7+ import XCTest
8+ #endif
9+
10+ class ArgumentParsingTestCase : XCTestCase {
11+ static var allTests = {
12+ return [
13+ ( " testFail " , testFail) ,
14+ ( " testSuccess " , testSuccess) ,
15+ ]
16+ } ( )
17+ func testFail( ) { XCTFail ( " failure " ) }
18+ func testSuccess( ) { }
19+ }
20+
21+ let arguments = [ " main " , " \( String ( reflecting: ArgumentParsingTestCase . self) ) /testSuccess " ]
22+ XCTMain ( [ testCase ( ArgumentParsingTestCase . allTests) ] , arguments: arguments)
You can’t perform that action at this time.
0 commit comments