From f270bd8134e4a683fa42c185381a31df6a3569e8 Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Fri, 7 Nov 2025 09:49:23 -0500 Subject: [PATCH 1/4] Add support for the `--testing-library` argument. This PR adds support for `--testing library xctest` for consistency with Swift Testing. (We just ignore it at this layer as the main function of the test executable handles it for us.) --- Sources/XCTest/Private/ArgumentParser.swift | 40 +++++++++++++-------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/Sources/XCTest/Private/ArgumentParser.swift b/Sources/XCTest/Private/ArgumentParser.swift index d30f86fbf..140d47335 100644 --- a/Sources/XCTest/Private/ArgumentParser.swift +++ b/Sources/XCTest/Private/ArgumentParser.swift @@ -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)) + for var i in arguments.dropFirst().indices { + let argument = arguments[j] + switch argument { + case "--list-tests": + 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(). + i = arguments.index(after: i) // 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) } From 17fbfdaed2b03f277cdf2f15112057f7c72267e6 Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Fri, 7 Nov 2025 11:06:49 -0500 Subject: [PATCH 2/4] Update Sources/XCTest/Private/ArgumentParser.swift Co-authored-by: Stuart Montgomery --- Sources/XCTest/Private/ArgumentParser.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/XCTest/Private/ArgumentParser.swift b/Sources/XCTest/Private/ArgumentParser.swift index 140d47335..018eb4cb1 100644 --- a/Sources/XCTest/Private/ArgumentParser.swift +++ b/Sources/XCTest/Private/ArgumentParser.swift @@ -55,7 +55,7 @@ internal struct ArgumentParser { for var i in arguments.dropFirst().indices { let argument = arguments[j] switch argument { - case "--list-tests": + case "--list-tests", "-l": executionMode = .list(type: .humanReadable) case "--dump-tests-json": executionMode = .list(type: .json) From 8aa21c819d5f27031fbd795188310b4ef9f45619 Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Fri, 7 Nov 2025 11:09:00 -0500 Subject: [PATCH 3/4] Fix typo --- Sources/XCTest/Private/ArgumentParser.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/XCTest/Private/ArgumentParser.swift b/Sources/XCTest/Private/ArgumentParser.swift index 018eb4cb1..77151c430 100644 --- a/Sources/XCTest/Private/ArgumentParser.swift +++ b/Sources/XCTest/Private/ArgumentParser.swift @@ -53,7 +53,7 @@ internal struct ArgumentParser { init(arguments: [String]) { self.arguments = arguments for var i in arguments.dropFirst().indices { - let argument = arguments[j] + let argument = arguments[i] switch argument { case "--list-tests", "-l": executionMode = .list(type: .humanReadable) From c79d875d9c97bedaf45eb73a9e0e7b73190ef37a Mon Sep 17 00:00:00 2001 From: Jonathan Grynspan Date: Fri, 7 Nov 2025 16:04:35 -0500 Subject: [PATCH 4/4] Use an iterator instead --- Sources/XCTest/Private/ArgumentParser.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/XCTest/Private/ArgumentParser.swift b/Sources/XCTest/Private/ArgumentParser.swift index 77151c430..11b33db48 100644 --- a/Sources/XCTest/Private/ArgumentParser.swift +++ b/Sources/XCTest/Private/ArgumentParser.swift @@ -52,8 +52,8 @@ internal struct ArgumentParser { init(arguments: [String]) { self.arguments = arguments - for var i in arguments.dropFirst().indices { - let argument = arguments[i] + var iterator = arguments.dropFirst().makeIterator() + while let argument = iterator.next() { switch argument { case "--list-tests", "-l": executionMode = .list(type: .humanReadable) @@ -63,7 +63,7 @@ internal struct ArgumentParser { executionMode = .help(invalidOption: nil) case "--testing-library": // Ignore this argument, it's already been handled by the main() that called into XCTMain(). - i = arguments.index(after: i) // skip value + _ = iterator.next() // skip value case _ where argument.starts(with: "--testing-library="): // Same as above, but in the form "--testing-library=xctest". break