Skip to content

Commit ec6987b

Browse files
unhappychoiceclaude
andcommitted
test(shell): cover Nushell across the shell module test suite
Two new tests target Nushell-specific invariants: the PWD env_change hook is the entry point (not chpwd / variable watch), and source_line returns the snippet itself (rather than the eval-on-startup line) so the rc layer can embed it inline. The exhaustive iterations (cd_hooks_call_on_cd_flag_not_bare_splash, source_line_covers_all_shells, as_str_returns_cli_names_for_every_shell, default_rc_path_for_known_shells_ends_in_expected_file) and the detect_maps_known_shells_from_shell_env case list are extended to include Nushell so regressions on either basename get caught. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 305465e commit ec6987b

1 file changed

Lines changed: 45 additions & 2 deletions

File tree

‎src/shell.rs‎

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ mod tests {
192192
assert!(s.contains("LocationChangedAction"));
193193
}
194194

195+
#[test]
196+
fn nushell_snippet_appends_pwd_env_change_hook() {
197+
let s = init_snippet(Shell::Nushell);
198+
assert!(s.contains("$env.config.hooks.env_change.PWD"));
199+
// First-prompt firing (`$before == null`) must be skipped so we don't double-splash
200+
// alongside the explicit startup `^splashboard` call below it.
201+
assert!(s.contains("$before != null"));
202+
}
203+
195204
#[test]
196205
fn all_snippets_guard_interactivity() {
197206
assert!(init_snippet(Shell::Bash).contains("$-"));
@@ -201,7 +210,13 @@ mod tests {
201210

202211
#[test]
203212
fn cd_hooks_call_on_cd_flag_not_bare_splash() {
204-
for shell in [Shell::Bash, Shell::Zsh, Shell::Fish, Shell::Powershell] {
213+
for shell in [
214+
Shell::Bash,
215+
Shell::Zsh,
216+
Shell::Fish,
217+
Shell::Powershell,
218+
Shell::Nushell,
219+
] {
205220
let s = init_snippet(shell);
206221
assert!(
207222
s.contains("splashboard --on-cd"),
@@ -225,6 +240,14 @@ mod tests {
225240
detect_shell(env_with(&[("SHELL", "/opt/homebrew/bin/fish")])),
226241
Some(Shell::Fish)
227242
);
243+
assert_eq!(
244+
detect_shell(env_with(&[("SHELL", "/usr/local/bin/nu")])),
245+
Some(Shell::Nushell)
246+
);
247+
assert_eq!(
248+
detect_shell(env_with(&[("SHELL", "/opt/homebrew/bin/nushell")])),
249+
Some(Shell::Nushell)
250+
);
228251
}
229252

230253
#[test]
@@ -268,6 +291,8 @@ mod tests {
268291
assert!(rc.ends_with(".bashrc"));
269292
let rc = default_rc_path(Shell::Fish).unwrap();
270293
assert!(rc.ends_with("config.fish"));
294+
let rc = default_rc_path(Shell::Nushell).unwrap();
295+
assert!(rc.ends_with("config.nu"));
271296
}
272297

273298
#[test]
@@ -276,6 +301,7 @@ mod tests {
276301
assert_eq!(Shell::Zsh.as_str(), "zsh");
277302
assert_eq!(Shell::Fish.as_str(), "fish");
278303
assert_eq!(Shell::Powershell.as_str(), "powershell");
304+
assert_eq!(Shell::Nushell.as_str(), "nushell");
279305
}
280306

281307
#[cfg(not(target_os = "windows"))]
@@ -302,9 +328,26 @@ mod tests {
302328

303329
#[test]
304330
fn source_line_covers_all_shells() {
305-
for shell in [Shell::Bash, Shell::Zsh, Shell::Fish, Shell::Powershell] {
331+
for shell in [
332+
Shell::Bash,
333+
Shell::Zsh,
334+
Shell::Fish,
335+
Shell::Powershell,
336+
Shell::Nushell,
337+
] {
306338
let line = source_line(shell);
307339
assert!(line.contains("splashboard"), "{:?}", shell);
308340
}
309341
}
342+
343+
/// Nushell can't use the same eval-on-startup indirection, so `source_line` returns
344+
/// the full snippet. The rc wiring layer then embeds it between the marker comments
345+
/// directly; re-running `splashboard install` replaces the block in place.
346+
#[test]
347+
fn nushell_source_line_embeds_full_snippet() {
348+
let line = source_line(Shell::Nushell);
349+
assert_eq!(line, init_snippet(Shell::Nushell));
350+
assert!(line.contains("env_change.PWD"));
351+
assert!(line.contains("^splashboard"));
352+
}
310353
}

0 commit comments

Comments
 (0)