Skip to content

test(shell): cover nushell vars and powershell prefix - #90

Merged
kirillDevPro merged 1 commit into
masterfrom
test/shell-var-prefix
Sep 26, 2026
Merged

kirillDevPro merged 1 commit into
masterfrom
test/shell-var-prefix

Conversation

@kirillDevPro

Copy link
Copy Markdown
Collaborator

What & why

ShellBuilder rewrites each task argument with to_shell_variable and, when the command has arguments, quotes the program with try_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_prefix was 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_var empty ${} — stays ${}, including in the middle of a string.
  • parse_nushell_var $env. passthrough — $env.FOO and pre$env.FOO stay as written.
  • parse_nushell_var non-identifier $ — $1 and pre$1 stay 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_aware for PowerShell — echo stays echo, echo hi becomes &'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, and get_windows_system_shell (process and filesystem). supports_posix_chaining, sequential_commands_separator, sequential_and_commands_separator, activate_keyword, and clear_screen_command are still open. The separator and activate helpers have no callers outside this file. quote_powershell("") looks wrong next to quote_pwsh("") ('""' versus ''); that is #89 and was not encoded as a test. A $ followed by a non-digit symbol such as $-x was 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 diff shows 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 the env. 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 $-x assertion inside nushell_leaves_a_non_identifier_dollar_alone. Widening the name rule to digits left $-x green, so that assertion did not prove the fallback. The review kept the other tests.

How to verify

cargo test -p moon-util --lib shell_tests

cargo test -p moon-util --lib is green (138 tests). cargo fmt --all -- --check is green. cargo clippy -p moon-util --all-targets -- -D warnings is already red on this crate for warnings outside this diff; the new test file produced no clippy output. Two existing doctests in paths.rs still fail to compile (use util::paths), which this change does not touch.

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.
@kirillDevPro
kirillDevPro merged commit 7e2fae7 into master Sep 26, 2026
4 checks passed
@kirillDevPro
kirillDevPro deleted the test/shell-var-prefix branch September 26, 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