test(shell): cover nushell vars and powershell prefix - #90
Merged
Merged
Conversation
ShellBuilder rewrites task arguments through to_shell_variable and
quotes the program with try_quote_prefix_aware. The Nushell builder
test never passes an empty ${}, an existing $env. path, or a $1.
prepend_command_prefix is only checked for a Nushell path that does
not already start with ^, so a second prefix would still pass.
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
ShellBuilderrewrites each task argument withto_shell_variableand, when the command has arguments, quotes the program withtry_quote_prefix_aware. The Nushell builder test covers$world,${hello}, and--$something. It does not cover an empty${}, a path that is already$env.FOO, or a$1.prepend_command_prefixwas only checked for a Nushell path that did not already start with^, so stacking a second prefix would still pass. PowerShell's prefix-aware quoting was not reached at all.Covered in
crates/moon-util/src/shell.rs:parse_nushell_varempty${}— stays${}, including in the middle of a string.parse_nushell_var$env.passthrough —$env.FOOandpre$env.FOOstay as written.parse_nushell_varnon-identifier$—$1andpre$1stay as written.prepend_command_prefix— PowerShell and Pwsh add one&, Nushell adds one^, an existing prefix is left alone, and POSIX adds nothing.try_quote_prefix_awarefor PowerShell —echostaysecho,echo hibecomes&'echo hi', and a command that already starts with&is not prefixed again.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).supports_posix_chaining,sequential_commands_separator,sequential_and_commands_separator,activate_keyword, andclear_screen_commandare still open. The separator and activate helpers have no callers outside this file.quote_powershell("")looks wrong next toquote_pwsh("")('""'versus''); that is #89 and was not encoded as a test. A$followed by a non-digit symbol such as$-xwas dropped after review.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 diffshows no production change.nushell_keeps_an_empty_brace_expansion— the empty-brace arm emits$env.. Red: left was$env., expected${}.nushell_keeps_an_existing_env_drive— delete theenv.passthrough. Red: left was$env.env.FOO, expected$env.FOO.nushell_leaves_a_non_identifier_dollar_alone— treat a digit as a name (is_alphanumeric). Red: left was$env.1, expected$1.command_prefix_is_applied_once— drop the already-prefixed guard. Red: left was&&Get-ChildItem, expected&Get-ChildItem.powershell_prefix_aware_quote_prefixes_only_a_quoted_command— the owned-quote arm no longer prepends&. Red: left was'echo hi', expected&'echo hi'.Dropped after one clean-context review: the
$-xassertion insidenushell_leaves_a_non_identifier_dollar_alone. Widening the name rule to digits left$-xgreen, so that assertion did not prove the fallback. The review kept the other tests.How to verify
cargo test -p moon-util --lib shell_testscargo test -p moon-util --libis green (138 tests).cargo fmt --all -- --checkis green.cargo clippy -p moon-util --all-targets -- -D warningsis already red on this crate for warnings outside this diff; the new test file produced no clippy output. Two existing doctests inpaths.rsstill fail to compile (use util::paths), which this change does not touch.