test(shell): cover kind fallback and shell arguments - #87
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
ShellBuilderasksShellKindwhich program to run, how to spell a variable, and which flags to pass. The tests already inshell.rsandshell_builder.rsonly reach Nushell, Fish, andshquoting. Cmd and PowerShell rewrite$FOOdifferently, 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/bashselect that shell on either platform, and an unknown name is PowerShell only whenis_windowsis set.to_shell_variableforCmd—$FOOand${FOO}become%FOO%,${FOO:-bar}and plain text stay as written.to_shell_variableforPowerShellandPwsh—$FOOand${BAR}become$env:FOO/$env:BAR, and a:-default stays as written.args_for_shellforCmd—/S /Cplus a quoted payload, with or without the interactive flag.args_for_shellforPowerShellandPwsh—-Cand the command, never-i.args_for_shellfor POSIX —-ionly when interactive is requested.Still untested here:
get_system_shell,get_default_system_shell,get_default_system_shell_preferring_bash,get_windows_bash, andget_windows_system_shell(process and filesystem).to_nushell_variableis reached by the existing builder test; empty${}, a$env.passthrough, and a$that is not an identifier are not.supports_posix_chaining, PowerShellprepend_command_prefix/try_quote_prefix_aware(Nushell prefix quoting is already tested),sequential_commands_separator,sequential_and_commands_separator, andactivate_keywordare 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 diffonshell.rsis onlymod shell_tests.unknown_program_falls_back_to_powershell_only_on_windows— the Windows fallback arm returnsPosix. Red:ShellKind::new("fancy", true)wasPosix, expectedPowerShell.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/Cwithout quotes. Red: left was["/S", "/C", "echo hi"], expected the quoted payload.powershell_args_use_capital_c_without_an_interactive_flag— pass-cinstead 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_testscargo test -p moon-util --libis green (133 tests). Two existing doctests inpaths.rsstill fail to compile (use util::paths), which this change does not touch.