Skip to content

test(shell): cover kind fallback and shell arguments - #87

Merged
kirillDevPro merged 1 commit into
masterfrom
test/shell-kind-dispatch
Sep 25, 2026
Merged

kirillDevPro merged 1 commit into
masterfrom
test/shell-kind-dispatch

Conversation

@kirillDevPro

Copy link
Copy Markdown
Collaborator

What & why

ShellBuilder asks ShellKind which program to run, how to spell a variable, and which flags to pass. The tests already in shell.rs and shell_builder.rs only reach Nushell, Fish, and sh quoting. Cmd and PowerShell rewrite $FOO differently, and they do not take -i. An unknown program name on Windows falls back to PowerShell rather than POSIX.

Covered in crates/moon-util/src/shell.rs:

  • ShellKind::new — cmd.exe / pwsh / bash select that shell on either platform, and an unknown name is PowerShell only when is_windows is set.
  • to_shell_variable for Cmd — $FOO and ${FOO} become %FOO%, ${FOO:-bar} and plain text stay as written.
  • to_shell_variable for PowerShell and Pwsh — $FOO and ${BAR} become $env:FOO / $env:BAR, and a :- default stays as written.
  • args_for_shell for Cmd — /S /C plus a quoted payload, with or without the interactive flag.
  • args_for_shell for PowerShell and Pwsh — -C and the command, never -i.
  • args_for_shell for POSIX — -i only when interactive is requested.

Still untested here: get_system_shell, get_default_system_shell, get_default_system_shell_preferring_bash, get_windows_bash, and get_windows_system_shell (process and filesystem). to_nushell_variable is reached by the existing builder test; empty ${}, a $env. passthrough, and a $ that is not an identifier are not. supports_posix_chaining, PowerShell prepend_command_prefix / try_quote_prefix_aware (Nushell prefix quoting is already tested), sequential_commands_separator, sequential_and_commands_separator, and activate_keyword are still open. The last three have no callers outside this file.

Mutations

Each test was green, then one production edit turned that test red on its assertion, then the edit was reverted and the test was green again. git diff on shell.rs is only mod shell_tests.

  • unknown_program_falls_back_to_powershell_only_on_windows — the Windows fallback arm returns Posix. Red: ShellKind::new("fancy", true) was Posix, expected PowerShell.
  • cmd_rewrites_variables_but_leaves_default_substitutions — drop the : guard so every ${...} is wrapped. Red: left was %FOO:-bar%, expected ${FOO:-bar}.
  • powershell_rewrites_variables_onto_the_env_drive — the $ arm returns the input unchanged. Red: left was $FOO, expected $env:FOO.
  • cmd_args_quote_the_command_and_ignore_interactive — pass the command to /C without quotes. Red: left was ["/S", "/C", "echo hi"], expected the quoted payload.
  • powershell_args_use_capital_c_without_an_interactive_flag — pass -c instead of -C. Red: left was ["-c", "echo hi"], expected -C.
  • posix_args_add_interactive_only_when_requested — always pass -i. Red: left was ["-i", "-c", "echo hi"], expected ["-c", "echo hi"].

Nothing was dropped. A clean-context review kept all six.

How to verify

cargo test -p moon-util --lib shell_tests

cargo test -p moon-util --lib is green (133 tests). Two existing doctests in paths.rs still fail to compile (use util::paths), which this change does not touch.

ShellBuilder asks ShellKind which program to run, how to spell a
variable, and which flags to pass. The existing tests only reach
Nushell, Fish, and sh quoting. Cmd and PowerShell rewrite variables
differently and do not take -i, and an unknown program name on
Windows falls back to PowerShell rather than POSIX.
@kirillDevPro
kirillDevPro merged commit 887dec1 into master Sep 25, 2026
4 checks passed
@kirillDevPro
kirillDevPro deleted the test/shell-kind-dispatch branch September 25, 2026 06:31
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.

1 participant