Skip to content

Ignore the --testing-library argument we are going to start passing from SwiftPM. #490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
31 changes: 30 additions & 1 deletion Sources/XCTest/Private/ArgumentParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,37 @@ internal struct ArgumentParser {

private let arguments: [String]

/// Filter out arguments from an arguments array that XCTest doesn't care about.
///
/// - Parameters:
/// - arguments: The arguments array to filter.
///
/// - Returns: A copy of `arguments` with ignored arguments removed.
private static func removeIgnoredArguments(from arguments: [String]) -> [String] {
var result = [String]()
result.reserveCapacity(arguments.count)

var iterator = arguments.makeIterator()
while let argument = iterator.next() {
// Filter out any arguments of the form "--testing-library=xctest".
if argument.starts(with: "--testing-library=") {
continue
}

// Next, filter out any split arguments ("--testing-library xctest")
if argument == "--testing-library" {
_ = iterator.next() // skip subsequent value
continue
}

result.append(argument)
}

return result
}

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

var executionMode: ExecutionMode {
Expand Down
22 changes: 22 additions & 0 deletions Tests/Functional/ArgumentParserWithIgnoredArgs/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// RUN: %{swiftc} %s -o %T/ArgumentParserWithIgnoredArgs
// RUN: %T/ArgumentParserWithIgnoredArgs

#if os(macOS)
import SwiftXCTest
#else
import XCTest
#endif

class ArgumentParsingWithIgnoredArgsTestCase: XCTestCase {
static var allTests = {
return [
("testFail", testFail),
("testSuccess", testSuccess),
]
}()
func testFail() { XCTFail("failure") }
func testSuccess() { }
}

let arguments = ["main", "--testing-library=xctest", "--testing-library", "xctest", "\(String(reflecting: ArgumentParsingWithIgnoredArgsTestCase.self))/testSuccess", "--testing-library",]
XCTMain([testCase(ArgumentParsingWithIgnoredArgsTestCase.allTests)], arguments: arguments)