Skip to content
Open
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
40 changes: 25 additions & 15 deletions Sources/XCTest/Private/ArgumentParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,31 @@ internal struct ArgumentParser {

init(arguments: [String]) {
self.arguments = arguments
}

var executionMode: ExecutionMode {
if arguments.count <= 1 {
return .run(selectedTestNames: nil)
} else if arguments[1] == "--list-tests" || arguments[1] == "-l" {
return .list(type: .humanReadable)
} else if arguments[1] == "--dump-tests-json" {
return .list(type: .json)
} else if arguments[1] == "--help" || arguments[1] == "-h" {
return .help(invalidOption: nil)
} else if let fst = arguments[1].first, fst == "-" {
return .help(invalidOption: arguments[1])
} else {
return .run(selectedTestNames: arguments[1].split(separator: ",").map(String.init))
var iterator = arguments.dropFirst().makeIterator()
while let argument = iterator.next() {
switch argument {
case "--list-tests", "-l":
executionMode = .list(type: .humanReadable)
case "--dump-tests-json":
executionMode = .list(type: .json)
case "--help", "-h":
executionMode = .help(invalidOption: nil)
case "--testing-library":
// Ignore this argument, it's already been handled by the main() that called into XCTMain().
_ = iterator.next() // skip value
case _ where argument.starts(with: "--testing-library="):
// Same as above, but in the form "--testing-library=xctest".
break
default:
if argument.first == "-" {
executionMode = .help(invalidOption: argument)
} else {
let testNames = argument.split(separator: ",").map(String.init)
executionMode = .run(selectedTestNames: testNames)
}
}
}
}

var executionMode: ExecutionMode = .run(selectedTestNames: nil)
}