|
| 1 | +use multi_launcher::actions::shell::build_shell_command; |
| 2 | +use serial_test::serial; |
| 3 | + |
| 4 | +fn set_use_wezterm(value: bool) { |
| 5 | + use multi_launcher::plugin::Plugin; |
| 6 | + let mut plugin = multi_launcher::plugins::shell::ShellPlugin; |
| 7 | + plugin.apply_settings(&serde_json::json!({ "open_in_wezterm": value })); |
| 8 | +} |
| 9 | + |
| 10 | +struct ResetUseWezterm; |
| 11 | + |
| 12 | +impl Drop for ResetUseWezterm { |
| 13 | + fn drop(&mut self) { |
| 14 | + set_use_wezterm(false); |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +#[test] |
| 19 | +#[serial] |
| 20 | +fn cmd_is_used_when_wezterm_disabled() { |
| 21 | + set_use_wezterm(false); |
| 22 | + let _reset = ResetUseWezterm; |
| 23 | + |
| 24 | + let (cmd_c, _desc_c) = build_shell_command("echo test", false); |
| 25 | + assert_eq!(cmd_c.get_program().to_string_lossy(), "cmd"); |
| 26 | + let args_c: Vec<_> = cmd_c |
| 27 | + .get_args() |
| 28 | + .map(|a| a.to_string_lossy().into_owned()) |
| 29 | + .collect(); |
| 30 | + assert_eq!(args_c, ["/C", "echo test"]); |
| 31 | + |
| 32 | + let (cmd_k, _desc_k) = build_shell_command("echo test", true); |
| 33 | + assert_eq!(cmd_k.get_program().to_string_lossy(), "cmd"); |
| 34 | + let args_k: Vec<_> = cmd_k |
| 35 | + .get_args() |
| 36 | + .map(|a| a.to_string_lossy().into_owned()) |
| 37 | + .collect(); |
| 38 | + assert_eq!(args_k, ["/K", "echo test"]); |
| 39 | +} |
| 40 | + |
| 41 | +#[test] |
| 42 | +#[serial] |
| 43 | +fn wezterm_is_used_when_enabled() { |
| 44 | + set_use_wezterm(true); |
| 45 | + let _reset = ResetUseWezterm; |
| 46 | + |
| 47 | + let (cmd, _desc) = build_shell_command("echo test", false); |
| 48 | + assert_eq!(cmd.get_program().to_string_lossy(), "wezterm"); |
| 49 | + let args: Vec<_> = cmd |
| 50 | + .get_args() |
| 51 | + .map(|a| a.to_string_lossy().into_owned()) |
| 52 | + .collect(); |
| 53 | + assert_eq!(&args[..3], ["start", "--", "cmd"]); |
| 54 | + assert_eq!(args[3], "/C"); |
| 55 | + assert_eq!(args[4], "echo test"); |
| 56 | +} |
0 commit comments