Skip to content

Commit bb10ca8

Browse files
authored
Updates to support Swift 6 language version (#650)
Some minor NFC changes to resolve strict concurrency checking warnings/errors and the warning about the change in meaning for `#file`.
1 parent 6a7abc0 commit bb10ca8

16 files changed

+55
-60
lines changed

Sources/ArgumentParser/Utilities/Platform.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,19 @@ extension CommandLine {
1313
/// Accesses the command line arguments in a concurrency-safe way.
1414
///
1515
/// Workaround for https://github.com/apple/swift/issues/66213
16-
static let _staticArguments: [String] =
17-
UnsafeBufferPointer(start: unsafeArgv, count: Int(argc))
18-
.compactMap { String(validatingUTF8: $0!)
19-
}
16+
static let _staticArguments: [String] = Self.arguments
2017
}
2118

2219
#if canImport(Glibc)
23-
import Glibc
20+
@preconcurrency import Glibc
2421
#elseif canImport(Musl)
25-
import Musl
22+
@preconcurrency import Musl
2623
#elseif canImport(Darwin)
2724
import Darwin
2825
#elseif canImport(CRT)
29-
import CRT
26+
@preconcurrency import CRT
3027
#elseif canImport(WASILibc)
31-
import WASILibc
28+
@preconcurrency import WASILibc
3229
#endif
3330

3431
enum Platform {}

Sources/ArgumentParserTestHelpers/TestHelpers.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ extension XCTestExpectation {
7777
public func AssertResultFailure<T, U: Error>(
7878
_ expression: @autoclosure () -> Result<T, U>,
7979
_ message: @autoclosure () -> String = "",
80-
file: StaticString = #file,
80+
file: StaticString = #filePath,
8181
line: UInt = #line)
8282
{
8383
switch expression() {
@@ -89,7 +89,7 @@ public func AssertResultFailure<T, U: Error>(
8989
}
9090
}
9191

92-
public func AssertErrorMessage<A>(_ type: A.Type, _ arguments: [String], _ errorMessage: String, file: StaticString = #file, line: UInt = #line) where A: ParsableArguments {
92+
public func AssertErrorMessage<A>(_ type: A.Type, _ arguments: [String], _ errorMessage: String, file: StaticString = #filePath, line: UInt = #line) where A: ParsableArguments {
9393
do {
9494
_ = try A.parse(arguments)
9595
XCTFail("Parsing should have failed.", file: file, line: line)
@@ -99,7 +99,7 @@ public func AssertErrorMessage<A>(_ type: A.Type, _ arguments: [String], _ error
9999
}
100100
}
101101

102-
public func AssertFullErrorMessage<A>(_ type: A.Type, _ arguments: [String], _ errorMessage: String, file: StaticString = #file, line: UInt = #line) where A: ParsableArguments {
102+
public func AssertFullErrorMessage<A>(_ type: A.Type, _ arguments: [String], _ errorMessage: String, file: StaticString = #filePath, line: UInt = #line) where A: ParsableArguments {
103103
do {
104104
_ = try A.parse(arguments)
105105
XCTFail("Parsing should have failed.", file: (file), line: line)
@@ -109,7 +109,7 @@ public func AssertFullErrorMessage<A>(_ type: A.Type, _ arguments: [String], _ e
109109
}
110110
}
111111

112-
public func AssertParse<A>(_ type: A.Type, _ arguments: [String], file: StaticString = #file, line: UInt = #line, closure: (A) throws -> Void) where A: ParsableArguments {
112+
public func AssertParse<A>(_ type: A.Type, _ arguments: [String], file: StaticString = #filePath, line: UInt = #line, closure: (A) throws -> Void) where A: ParsableArguments {
113113
do {
114114
let parsed = try type.parse(arguments)
115115
try closure(parsed)
@@ -119,7 +119,7 @@ public func AssertParse<A>(_ type: A.Type, _ arguments: [String], file: StaticSt
119119
}
120120
}
121121

122-
public func AssertParseCommand<A: ParsableCommand>(_ rootCommand: ParsableCommand.Type, _ type: A.Type, _ arguments: [String], file: StaticString = #file, line: UInt = #line, closure: (A) throws -> Void) {
122+
public func AssertParseCommand<A: ParsableCommand>(_ rootCommand: ParsableCommand.Type, _ type: A.Type, _ arguments: [String], file: StaticString = #filePath, line: UInt = #line, closure: (A) throws -> Void) {
123123
do {
124124
let command = try rootCommand.parseAsRoot(arguments)
125125
guard let aCommand = command as? A else {
@@ -136,7 +136,7 @@ public func AssertParseCommand<A: ParsableCommand>(_ rootCommand: ParsableComman
136136
public func AssertEqualStrings(
137137
actual: String,
138138
expected: String,
139-
file: StaticString = #file,
139+
file: StaticString = #filePath,
140140
line: UInt = #line
141141
) {
142142
// If the input strings are not equal, create a simple diff for debugging...
@@ -207,7 +207,7 @@ public func AssertHelp<T: ParsableArguments>(
207207
for _: T.Type,
208208
columns: Int? = 80,
209209
equals expected: String,
210-
file: StaticString = #file,
210+
file: StaticString = #filePath,
211211
line: UInt = #line
212212
) {
213213
let flag: String
@@ -246,7 +246,7 @@ public func AssertHelp<T: ParsableCommand, U: ParsableCommand>(
246246
root _: U.Type,
247247
columns: Int? = 80,
248248
equals expected: String,
249-
file: StaticString = #file,
249+
file: StaticString = #filePath,
250250
line: UInt = #line
251251
) {
252252
let includeHidden: Bool
@@ -271,7 +271,7 @@ public func AssertHelp<T: ParsableCommand, U: ParsableCommand>(
271271

272272
public func AssertDump<T: ParsableArguments>(
273273
for _: T.Type, equals expected: String,
274-
file: StaticString = #file, line: UInt = #line
274+
file: StaticString = #filePath, line: UInt = #line
275275
) throws {
276276
do {
277277
_ = try T.parse(["--experimental-dump-help"])
@@ -284,7 +284,7 @@ public func AssertDump<T: ParsableArguments>(
284284
try AssertJSONEqualFromString(actual: T._dumpHelp(), expected: expected, for: ToolInfoV0.self, file: file, line: line)
285285
}
286286

287-
public func AssertJSONEqualFromString<T: Codable & Equatable>(actual: String, expected: String, for type: T.Type, file: StaticString = #file, line: UInt = #line) throws {
287+
public func AssertJSONEqualFromString<T: Codable & Equatable>(actual: String, expected: String, for type: T.Type, file: StaticString = #filePath, line: UInt = #line) throws {
288288
if #available(macOS 10.13, iOS 11.0, tvOS 11.0, watchOS 4.0, *) {
289289
AssertEqualStrings(actual: actual, expected: expected, file: file, line: line)
290290
}
@@ -309,7 +309,7 @@ extension XCTest {
309309
command: String,
310310
expected: String? = nil,
311311
exitCode: ExitCode = .success,
312-
file: StaticString = #file, line: UInt = #line) throws
312+
file: StaticString = #filePath, line: UInt = #line) throws
313313
{
314314
try AssertExecuteCommand(
315315
command: command.split(separator: " ").map(String.init),
@@ -323,7 +323,7 @@ extension XCTest {
323323
command: [String],
324324
expected: String? = nil,
325325
exitCode: ExitCode = .success,
326-
file: StaticString = #file, line: UInt = #line) throws
326+
file: StaticString = #filePath, line: UInt = #line) throws
327327
{
328328
#if os(Windows)
329329
throw XCTSkip("Unsupported on this platform")
@@ -385,7 +385,7 @@ extension XCTest {
385385
public func AssertJSONOutputEqual(
386386
command: String,
387387
expected: String,
388-
file: StaticString = #file,
388+
file: StaticString = #filePath,
389389
line: UInt = #line
390390
) throws {
391391
#if os(Windows)
@@ -439,7 +439,7 @@ extension XCTest {
439439
multiPage: Bool,
440440
command: String,
441441
expected: String,
442-
file: StaticString = #file,
442+
file: StaticString = #filePath,
443443
line: UInt = #line
444444
) throws {
445445
#if os(Windows)

Tests/ArgumentParserEndToEndTests/AsyncCommandEndToEndTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ actor AsyncStatusCheck {
3232
}
3333
}
3434

35+
@MainActor
3536
var statusCheck = AsyncStatusCheck()
3637

3738
// MARK: AsyncParsableCommand.main() testing

Tests/ArgumentParserEndToEndTests/NestedCommandEndToEndTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fileprivate struct Foo: ParsableCommand {
5454
}
5555
}
5656

57-
fileprivate func AssertParseFooCommand<A>(_ type: A.Type, _ arguments: [String], file: StaticString = #file, line: UInt = #line, closure: (A) throws -> Void) where A: ParsableCommand {
57+
fileprivate func AssertParseFooCommand<A>(_ type: A.Type, _ arguments: [String], file: StaticString = #filePath, line: UInt = #line, closure: (A) throws -> Void) where A: ParsableCommand {
5858
AssertParseCommand(Foo.self, type, arguments, file: file, line: line, closure: closure)
5959
}
6060

Tests/ArgumentParserEndToEndTests/SubcommandEndToEndTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ extension SubcommandEndToEndTests {
110110
}
111111
}
112112

113-
fileprivate var mathDidRun = false
114-
115113
fileprivate struct Math: ParsableCommand {
116114
enum Operation: String, ExpressibleByArgument {
117115
case add
@@ -127,20 +125,22 @@ fileprivate struct Math: ParsableCommand {
127125
@Argument(help: "The first operand")
128126
var operands: [Int] = []
129127

128+
var didRun = false
129+
130130
mutating func run() {
131131
XCTAssertEqual(operation, .multiply)
132132
XCTAssertTrue(verbose)
133133
XCTAssertEqual(operands, [5, 11])
134-
mathDidRun = true
134+
didRun = true
135135
}
136136
}
137137

138138
extension SubcommandEndToEndTests {
139139
func testParsing_SingleCommand() throws {
140-
var mathCommand = try Math.parseAsRoot(["--operation", "multiply", "-v", "5", "11"])
141-
XCTAssertFalse(mathDidRun)
142-
try mathCommand.run()
143-
XCTAssertTrue(mathDidRun)
140+
var mathCommand = try Math.parseAsRoot(["--operation", "multiply", "-v", "5", "11"]) as! Math
141+
XCTAssertFalse(mathCommand.didRun)
142+
mathCommand.run()
143+
XCTAssertTrue(mathCommand.didRun)
144144
}
145145
}
146146

Tests/ArgumentParserEndToEndTests/TransformEndToEndTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ extension Convert {
3636

3737
fileprivate struct FooOption: Convert, ParsableArguments {
3838

39-
static var usageString: String = """
39+
static let usageString: String = """
4040
Usage: foo_option --string <int_str>
4141
See 'foo_option --help' for more information.
4242
"""
43-
static var help: String = "Help: --string <int_str> Convert string to integer\n"
43+
static let help: String = "Help: --string <int_str> Convert string to integer\n"
4444

4545
@Option(help: ArgumentHelp("Convert string to integer", valueName: "int_str"),
4646
transform: { try convert($0) })
@@ -49,11 +49,11 @@ fileprivate struct FooOption: Convert, ParsableArguments {
4949

5050
fileprivate struct BarOption: Convert, ParsableCommand {
5151

52-
static var usageString: String = """
52+
static let usageString: String = """
5353
Usage: bar-option [--strings <int_str> ...]
5454
See 'bar-option --help' for more information.
5555
"""
56-
static var help: String = "Help: --strings <int_str> Convert a list of strings to an array of integers\n"
56+
static let help: String = "Help: --strings <int_str> Convert a list of strings to an array of integers\n"
5757

5858
@Option(help: ArgumentHelp("Convert a list of strings to an array of integers", valueName: "int_str"),
5959
transform: { try convert($0) })
@@ -99,11 +99,11 @@ extension TransformEndToEndTests {
9999

100100
fileprivate struct FooArgument: Convert, ParsableArguments {
101101

102-
static var usageString: String = """
102+
static let usageString: String = """
103103
Usage: foo_argument <int_str>
104104
See 'foo_argument --help' for more information.
105105
"""
106-
static var help: String = "Help: <int_str> Convert string to integer\n"
106+
static let help: String = "Help: <int_str> Convert string to integer\n"
107107

108108
enum FooError: Error {
109109
case outOfBounds
@@ -116,11 +116,11 @@ fileprivate struct FooArgument: Convert, ParsableArguments {
116116

117117
fileprivate struct BarArgument: Convert, ParsableCommand {
118118

119-
static var usageString: String = """
119+
static let usageString: String = """
120120
Usage: bar-argument [<int_str> ...]
121121
See 'bar-argument --help' for more information.
122122
"""
123-
static var help: String = "Help: <int_str> Convert a list of strings to an array of integers\n"
123+
static let help: String = "Help: <int_str> Convert a list of strings to an array of integers\n"
124124

125125
@Argument(help: ArgumentHelp("Convert a list of strings to an array of integers", valueName: "int_str"),
126126
transform: { try convert($0) })

Tests/ArgumentParserEndToEndTests/ValidationEndToEndTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ fileprivate enum UserValidationError: LocalizedError {
2828
}
2929

3030
fileprivate struct Foo: ParsableArguments {
31-
static var usageString: String = """
31+
static let usageString: String = """
3232
Usage: foo [--count <count>] [<names> ...] [--version] [--throw]
3333
See 'foo --help' for more information.
3434
"""
3535

36-
static var helpString: String = """
36+
static let helpString: String = """
3737
USAGE: foo [--count <count>] [<names> ...] [--version] [--throw]
3838
3939
ARGUMENTS:

Tests/ArgumentParserPackageManagerTests/HelpTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ struct Simple: ParsableArguments {
168168
@Option() var min: Int?
169169
@Argument() var max: Int
170170

171-
static var helpText = """
171+
static let helpText = """
172172
USAGE: simple [--verbose] [--min <min>] <max>
173173
174174
ARGUMENTS:

Tests/ArgumentParserPackageManagerTests/PackageManager/Config.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension Package {
1717
}
1818

1919
extension Package.Config {
20-
public static var configuration = CommandConfiguration(
20+
public static let configuration = CommandConfiguration(
2121
subcommands: [GetMirror.self, SetMirror.self, UnsetMirror.self])
2222

2323
/// Print mirror configuration for the given package dependency

Tests/ArgumentParserUnitTests/CompletionScriptTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ extension CompletionScriptTests {
131131
func verifyCustomOutput(
132132
_ arg: String,
133133
expectedOutput: String,
134-
file: StaticString = #file, line: UInt = #line
134+
file: StaticString = #filePath, line: UInt = #line
135135
) throws {
136136
do {
137137
_ = try Custom.parse(["---completion", "--", arg])

Tests/ArgumentParserUnitTests/DumpHelpGenerationTests.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ import XCTest
1212
import ArgumentParserTestHelpers
1313
@testable import ArgumentParser
1414

15-
final class DumpHelpGenerationTests: XCTestCase {
16-
public static let allTests = [
17-
("testDumpExampleCommands", testDumpExampleCommands),
18-
("testDumpA", testDumpA)
19-
]
20-
}
15+
final class DumpHelpGenerationTests: XCTestCase {}
2116

2217
extension DumpHelpGenerationTests {
2318
struct A: ParsableCommand {

Tests/ArgumentParserUnitTests/HelpGenerationTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ extension HelpGenerationTests {
283283
struct H: ParsableCommand {
284284
struct CommandWithVeryLongName: ParsableCommand {}
285285
struct ShortCommand: ParsableCommand {
286-
static var configuration: CommandConfiguration = CommandConfiguration(abstract: "Test short command name.")
286+
static let configuration: CommandConfiguration = CommandConfiguration(abstract: "Test short command name.")
287287
}
288288
struct AnotherCommandWithVeryLongName: ParsableCommand {
289-
static var configuration: CommandConfiguration = CommandConfiguration(abstract: "Test long command name.")
289+
static let configuration: CommandConfiguration = CommandConfiguration(abstract: "Test long command name.")
290290
}
291291
struct AnotherCommand: ParsableCommand {
292292
@Option()
@@ -474,7 +474,7 @@ extension HelpGenerationTests {
474474
}
475475

476476
struct Foo: ParsableCommand {
477-
public static var configuration = CommandConfiguration(
477+
public static let configuration = CommandConfiguration(
478478
commandName: "foo",
479479
abstract: "Perform some foo",
480480
subcommands: [
@@ -681,7 +681,7 @@ extension HelpGenerationTests {
681681
struct AllValues: ParsableCommand {
682682
enum Manual: Int, ExpressibleByArgument {
683683
case foo
684-
static var allValueStrings = ["bar"]
684+
static let allValueStrings = ["bar"]
685685
}
686686

687687
enum UnspecializedSynthesized: Int, CaseIterable, ExpressibleByArgument {

Tests/ArgumentParserUnitTests/NameSpecificationTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ extension NameSpecificationTests {
4242
}
4343
}
4444

45-
fileprivate func Assert(nameSpecification: NameSpecification, key: String, parent: InputKey? = nil, makeNames expected: [Name], file: StaticString = #file, line: UInt = #line) {
45+
fileprivate func Assert(nameSpecification: NameSpecification, key: String, parent: InputKey? = nil, makeNames expected: [Name], file: StaticString = #filePath, line: UInt = #line) {
4646
let names = nameSpecification.makeNames(InputKey(name: key, parent: parent))
4747
Assert(names: names, expected: expected, file: file, line: line)
4848
}
4949

50-
fileprivate func Assert<N>(names: [N], expected: [N], file: StaticString = #file, line: UInt = #line) where N: Equatable {
50+
fileprivate func Assert<N>(names: [N], expected: [N], file: StaticString = #filePath, line: UInt = #line) where N: Equatable {
5151
names.forEach {
5252
XCTAssert(expected.contains($0), "Unexpected name '\($0)'.", file: (file), line: line)
5353
}

Tests/ArgumentParserUnitTests/SplitArgumentTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension ArgumentParser.SplitArguments.InputIndex: Swift.ExpressibleByIntegerLi
1919
}
2020
}
2121

22-
private func AssertIndexEqual(_ sut: SplitArguments, at index: Int, inputIndex: Int, subIndex: SplitArguments.SubIndex, file: StaticString = #file, line: UInt = #line) {
22+
private func AssertIndexEqual(_ sut: SplitArguments, at index: Int, inputIndex: Int, subIndex: SplitArguments.SubIndex, file: StaticString = #filePath, line: UInt = #line) {
2323
guard index < sut.elements.endIndex else {
2424
XCTFail("Element index \(index) is out of range. sur only has \(sut.elements.count) elements.", file: (file), line: line)
2525
return
@@ -34,7 +34,7 @@ private func AssertIndexEqual(_ sut: SplitArguments, at index: Int, inputIndex:
3434
}
3535
}
3636

37-
private func AssertElementEqual(_ sut: SplitArguments, at index: Int, _ element: SplitArguments.Element.Value, file: StaticString = #file, line: UInt = #line) {
37+
private func AssertElementEqual(_ sut: SplitArguments, at index: Int, _ element: SplitArguments.Element.Value, file: StaticString = #filePath, line: UInt = #line) {
3838
guard index < sut.elements.endIndex else {
3939
XCTFail("Element index \(index) is out of range. sur only has \(sut.elements.count) elements.", file: (file), line: line)
4040
return

0 commit comments

Comments
 (0)