File tree 3 files changed +28
-3
lines changed
Tests/Functional/ArgumentParser
3 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ internal struct ArgumentParser {
50
50
51
51
private let arguments : [ String ]
52
52
53
- init ( arguments: [ String ] = CommandLine . arguments ) {
53
+ init ( arguments: [ String ] ) {
54
54
self . arguments = arguments
55
55
}
56
56
Original file line number Diff line number Diff line change 60
60
/// - Parameter testCases: An array of test cases run, each produced by a call to the `testCase` function
61
61
/// - seealso: `testCase`
62
62
public func XCTMain( _ testCases: [ XCTestCaseEntry ] ) -> Never {
63
+ XCTMain ( testCases, arguments: CommandLine . arguments)
64
+ }
65
+ public func XCTMain( _ testCases: [ XCTestCaseEntry ] , arguments: [ String ] ) -> Never {
63
66
let testBundle = Bundle . main
64
67
65
- let executionMode = ArgumentParser ( ) . executionMode
68
+ let executionMode = ArgumentParser ( arguments : arguments ) . executionMode
66
69
67
70
// Apple XCTest behaves differently if tests have been filtered:
68
71
// - The root `XCTestSuite` is named "Selected tests" instead of
@@ -96,7 +99,7 @@ public func XCTMain(_ testCases: [XCTestCaseEntry]) -> Never {
96
99
let errMsg = " Error: Invalid option \" \( invalid) \" \n "
97
100
FileHandle . standardError. write ( errMsg. data ( using: . utf8) ?? Data ( ) )
98
101
}
99
- let exeName = URL ( fileURLWithPath: CommandLine . arguments [ 0 ] ) . lastPathComponent
102
+ let exeName = URL ( fileURLWithPath: arguments [ 0 ] ) . lastPathComponent
100
103
let sampleTest = rootTestSuite. list ( ) . first ?? " Tests.FooTestCase/testFoo "
101
104
let sampleTests = sampleTest. prefix ( while: { $0 != " / " } )
102
105
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