diff --git a/.github/workflows/lint.yml b/.github/workflows/pull_request.yml similarity index 84% rename from .github/workflows/lint.yml rename to .github/workflows/pull_request.yml index 438e24179..34995e966 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/pull_request.yml @@ -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 diff --git a/Sources/ArgumentParserTestHelpers/StringHelpers.swift b/Sources/ArgumentParserTestHelpers/StringHelpers.swift index 51324e64c..b1fd20c57 100644 --- a/Sources/ArgumentParserTestHelpers/StringHelpers.swift +++ b/Sources/ArgumentParserTestHelpers/StringHelpers.swift @@ -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") + } } diff --git a/Sources/ArgumentParserTestHelpers/TestHelpers.swift b/Sources/ArgumentParserTestHelpers/TestHelpers.swift index 7e43227b8..cdbd6d94d 100644 --- a/Sources/ArgumentParserTestHelpers/TestHelpers.swift +++ b/Sources/ArgumentParserTestHelpers/TestHelpers.swift @@ -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. diff --git a/Tests/ArgumentParserUnitTests/CompletionScriptTests.swift b/Tests/ArgumentParserUnitTests/CompletionScriptTests.swift index c15ce70ac..833623894 100644 --- a/Tests/ArgumentParserUnitTests/CompletionScriptTests.swift +++ b/Tests/ArgumentParserUnitTests/CompletionScriptTests.swift @@ -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") } @@ -189,6 +190,7 @@ extension CompletionScriptTests { file: file, line: line) } + #endif } func assertCustomCompletions( @@ -196,6 +198,7 @@ extension CompletionScriptTests { 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( @@ -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 { diff --git a/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift b/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift index 5bfc0bf1b..cb3250c4c 100644 --- a/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift +++ b/Tests/ArgumentParserUnitTests/HelpGenerationTests.swift @@ -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 } } @@ -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 @@ -229,7 +226,7 @@ extension HelpGenerationTests { --lucky Your lucky numbers. (default: 7, 14) --optional/--required Vegan diet. (default: --optional) --degree Your degree. - --directory Directory. (default: current directory) + --directory Directory. (default: /path/to/file) --manual Manual Option. (default: default-value) --unspecial Unspecialized Synthesized (values: 0, 1; default: 0) --special Specialized Synthesized (values: Apple, Banana;