Skip to content

Commit 37f3ad1

Browse files
authored
Ensure default property values for __CommandLineArguments_v0 are all nil. (#463)
We should default to `nil` (i.e. "unspecified") for command-line argument values that aren't specified. This ensures consistent default behaviour whether specifying command-line arguments individually or specifying `--experimental-configuration-path` (or a combination thereof). ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent a36ed06 commit 37f3ad1

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

Sources/Testing/EntryPoints/EntryPoint.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func entryPoint(passing args: consuming __CommandLineArguments_v0?, eventHandler
3232

3333
do {
3434
let args = try args ?? parseCommandLineArguments(from: CommandLine.arguments)
35-
if args.listTests ?? true {
35+
if args.listTests ?? false {
3636
for testID in await listTestsForEntryPoint(Test.all) {
3737
#if SWT_TARGET_OS_APPLE && !SWT_NO_FILE_IO
3838
try? FileHandle.stdout.write("\(testID)\n")
@@ -153,19 +153,19 @@ public struct __CommandLineArguments_v0: Sendable {
153153
public init() {}
154154

155155
/// The value of the `--list-tests` argument.
156-
public var listTests: Bool? = false
156+
public var listTests: Bool?
157157

158158
/// The value of the `--parallel` or `--no-parallel` argument.
159-
public var parallel: Bool? = true
159+
public var parallel: Bool?
160160

161161
/// The value of the `--verbose` argument.
162-
public var verbose: Bool? = false
162+
public var verbose: Bool?
163163

164164
/// The value of the `--very-verbose` argument.
165-
public var veryVerbose: Bool? = false
165+
public var veryVerbose: Bool?
166166

167167
/// The value of the `--quiet` argument.
168-
public var quiet: Bool? = false
168+
public var quiet: Bool?
169169

170170
/// Storage for the ``verbosity`` property.
171171
private var _verbosity: Int?
@@ -226,7 +226,7 @@ public struct __CommandLineArguments_v0: Sendable {
226226
///
227227
/// - Warning: The behavior of this property will change when the ABI version
228228
/// 0 JSON schema is finalized.
229-
public var experimentalEventStreamVersion: Int? = nil
229+
public var experimentalEventStreamVersion: Int?
230230

231231
/// The value(s) of the `--filter` argument.
232232
public var filter: [String]?

Tests/TestingTests/SwiftPMTests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,34 @@ struct SwiftPMTests {
167167
}
168168

169169
#if canImport(Foundation)
170+
@Test("--experimental-configuration-path argument")
171+
func configurationPath() async throws {
172+
let tempDirPath = try temporaryDirectory()
173+
let temporaryFilePath = appendPathComponent("\(UInt64.random(in: 0 ..< .max))", to: tempDirPath)
174+
defer {
175+
_ = remove(temporaryFilePath)
176+
}
177+
do {
178+
let fileHandle = try FileHandle(forWritingAtPath: temporaryFilePath)
179+
try fileHandle.write(
180+
"""
181+
{
182+
"verbosity": 50,
183+
"filter": ["hello", "world"],
184+
"parallel": false
185+
}
186+
"""
187+
)
188+
}
189+
let args = try parseCommandLineArguments(from: ["PATH", "--experimental-configuration-path", temporaryFilePath])
190+
#expect(args.verbose == nil)
191+
#expect(args.quiet == nil)
192+
#expect(args.verbosity == 50)
193+
#expect(args.filter == ["hello", "world"])
194+
#expect(args.skip == nil)
195+
#expect(args.parallel == false)
196+
}
197+
170198
func decodeABIv0RecordStream(fromFileAtPath path: String) throws -> [ABIv0.Record] {
171199
try FileHandle(forReadingAtPath: path).readToEnd()
172200
.split(separator: 10) // "\n"

0 commit comments

Comments
 (0)