Skip to content

Migrate ArgumentParserExampleTests to Swift Testing - #949

Open
bkhouri wants to merge 1 commit into
bkhouri/t/main/migrate_tests_to_swift_testingfrom
bkhouri/t/main/migrate_tests_to_swift_testing_batch2
Open

Migrate ArgumentParserExampleTests to Swift Testing#949
bkhouri wants to merge 1 commit into
bkhouri/t/main/migrate_tests_to_swift_testingfrom
bkhouri/t/main/migrate_tests_to_swift_testing_batch2

Conversation

@bkhouri

@bkhouri bkhouri commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Migrate the four ArgumentParserExampleTests suites from XCTest to
Swift Testing:

  • RollDiceExampleTests
  • CountLinesExampleTests
  • RepeatExampleTests
  • MathExampleTests

Add Swift Testing counterparts for the process-executing test helpers
in ArgumentParserTestHelpers, which were previously only available as
methods on extension XCTest:

  • requireExecuteCommand (String and [String] overloads) — uses
    #require for unrecoverable preconditions (missing executable,
    process failing to launch) and #expect for the exit-code and
    stdout/stderr comparisons.
  • expectSnapshot — reads/writes snapshots next to the caller's file
    using #function as the default snapshot name, preserving the
    existing Snapshots/testMath*CompletionScript().{bash,zsh,fish}
    files.

Preserved the exact testMath{Bash,Zsh,Fish}CompletionScript method
names so #function-based snapshot lookup continues to resolve the
existing baselines without renaming files.

Relates to #710

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

Stack created with GitHub Stacks CLIGive Feedback 💬

@bkhouri
bkhouri force-pushed the bkhouri/t/main/migrate_tests_to_swift_testing_batch2 branch from 12277ae to 760ba35 Compare August 25, 2026 03:26
@bkhouri
bkhouri marked this pull request as ready for review August 25, 2026 03:36
Comment thread Sources/ArgumentParserTestHelpers/TestHelpers+SwiftTesting.swift Outdated
Comment thread Sources/ArgumentParserTestHelpers/TestHelpers+SwiftTesting.swift Outdated

func testCountLines() throws {
@Test func countLines() throws {
guard #available(macOS 12, *) else { return }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Out of curiosity, why do test test only run on macOS? Should the test, and related binary, be updated to run on all platforms os is the intents to verify Swift Argument Parser with the @available(...) API?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all these Qs, I think the gating factor was what I could get working at the time of setting up these executable tests. So the question is more about whether we can get these executable tests to run on Linux/Windows, there isn't a principled reason not to.


func testCountLinesHelp() throws {
@Test func countLinesHelp() throws {
guard #available(macOS 12, *) else { return }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Out of curiosity, why do test test only run on macOS? Should the test, and related binary, be updated to run on all platforms os is the intents to verify Swift Argument Parser with the @available(...) API?

func testMathBashCompletionScript() throws {
let script = try AssertExecuteCommand(
@Test(
.requiresProcessExecution

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: This trait disabled the test on some platforms, for example Windows. Is this expected?

func testMathZshCompletionScript() throws {
let script = try AssertExecuteCommand(
@Test(
.requiresProcessExecution

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: This trait disabled the test on some platforms, for example Windows. Is this expected?

@bkhouri
bkhouri force-pushed the bkhouri/t/main/migrate_tests_to_swift_testing_batch2 branch 3 times, most recently from 54cf308 to 555b885 Compare August 26, 2026 18:18
@bkhouri
bkhouri force-pushed the bkhouri/t/main/migrate_tests_to_swift_testing_batch2 branch 3 times, most recently from ccc2547 to 0394d42 Compare August 27, 2026 15:43
Migrate the four `ArgumentParserExampleTests` suites from XCTest to
Swift Testing:

- `RollDiceExampleTests`
- `CountLinesExampleTests`
- `RepeatExampleTests`
- `MathExampleTests`

Add Swift Testing counterparts for the process-executing test helpers
in `ArgumentParserTestHelpers`, which were previously only available as
methods on `extension XCTest`:

- `requireExecuteCommand` (String and [String] overloads) — uses
  `#require` for unrecoverable preconditions (missing executable,
  process failing to launch) and `#expect` for the exit-code and
  stdout/stderr comparisons.
- `expectSnapshot` — reads/writes snapshots next to the caller's file
  using `#function` as the default snapshot name, preserving the
  existing `Snapshots/testMath*CompletionScript().{bash,zsh,fish}`
  files.

Preserved the exact `testMath{Bash,Zsh,Fish}CompletionScript` method
names so `#function`-based snapshot lookup continues to resolve the
existing baselines without renaming files.

Relates to #710
@bkhouri
bkhouri force-pushed the bkhouri/t/main/migrate_tests_to_swift_testing_batch2 branch from 0394d42 to cb646b9 Compare August 27, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants