Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ jobs:
curl -sL https://raw.githubusercontent.com/apple/swift-mmio/refs/heads/main/.swift-format -o .swift-format-mmio
diff .swift-format .swift-format-mmio
tests:
name: Test
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
with:
windows_exclude_swift_versions: "[{\"swift_version\": \"5.9\"}]"
soundness:
name: Soundness
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
Expand Down
6 changes: 6 additions & 0 deletions Sources/ArgumentParserTestHelpers/StringHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ extension String {
.map { $0.trimmed() }
.joined(separator: "\n")
}

public func normalizingLineEndings() -> String {
self
.replacingOccurrences(of: "\r\n", with: "\n")
.replacingOccurrences(of: "\r", with: "\n")
}
}
4 changes: 4 additions & 0 deletions Sources/ArgumentParserTestHelpers/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ public func AssertEqualStrings(
file: StaticString = #filePath,
line: UInt = #line
) {
// Normalize line endings to '\n'.
let actual = actual.normalizingLineEndings()
let expected = expected.normalizingLineEndings()

// If the input strings are not equal, create a simple diff for debugging...
guard actual != expected else {
// Otherwise they are equal, early exit.
Expand Down
4 changes: 4 additions & 0 deletions Tests/ArgumentParserUnitTests/CompletionScriptTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ extension CompletionScriptTests {
file: StaticString = #filePath,
line: UInt = #line
) throws {
#if !os(Windows) && !os(WASI)
do {
setenv("SAP_SHELL", shell, 1)
defer { unsetenv("SAP_SHELL") }
Expand All @@ -189,13 +190,15 @@ extension CompletionScriptTests {
file: file,
line: line)
}
#endif
}

func assertCustomCompletions(
shell: String,
file: StaticString = #filePath,
line: UInt = #line
) throws {
#if !os(Windows) && !os(WASI)
try assertCustomCompletion(
"-o", shell: shell, prefix: "e", file: file, line: line)
try assertCustomCompletion(
Expand All @@ -211,6 +214,7 @@ extension CompletionScriptTests {
try assertCustomCompletion("--bad", shell: shell, file: file, line: line))
XCTAssertThrowsError(
try assertCustomCompletion("four", shell: shell, file: file, line: line))
#endif
}

func testBashCustomCompletions() throws {
Expand Down
9 changes: 3 additions & 6 deletions Tests/ArgumentParserUnitTests/HelpGenerationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ extension Foundation.URL: ArgumentParser.ExpressibleByArgument {
}

public var defaultValueDescription: String {
self.path == FileManager.default.currentDirectoryPath && self.isFileURL
? "current directory"
: String(describing: self)
self.path
}
}

Expand Down Expand Up @@ -189,8 +187,7 @@ extension HelpGenerationTests {
var degree: Degree = .bachelor

@Option(help: "Directory.")
var directory: URL = URL(
fileURLWithPath: FileManager.default.currentDirectoryPath)
var directory: URL = URL(fileURLWithPath: "/path/to/file")

enum Manual: Int, ExpressibleByArgument {
case foo
Expand Down Expand Up @@ -229,7 +226,7 @@ extension HelpGenerationTests {
--lucky <numbers> Your lucky numbers. (default: 7, 14)
--optional/--required Vegan diet. (default: --optional)
--degree <degree> Your degree.
--directory <directory> Directory. (default: current directory)
--directory <directory> Directory. (default: /path/to/file)
--manual <manual> Manual Option. (default: default-value)
--unspecial <unspecial> Unspecialized Synthesized (values: 0, 1; default: 0)
--special <special> Specialized Synthesized (values: Apple, Banana;
Expand Down