From c11a17e6c56aa16aae6782dbacd079f6330c17f4 Mon Sep 17 00:00:00 2001 From: Ian Manske Date: Sat, 16 Nov 2024 14:27:41 -0800 Subject: [PATCH] Fix tests and `run_external` message bug --- crates/nu-command/src/system/exec.rs | 1 + crates/nu-command/src/system/run_external.rs | 21 +++++++++++++------- tests/hooks/mod.rs | 12 +++++------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/crates/nu-command/src/system/exec.rs b/crates/nu-command/src/system/exec.rs index 7bf9daecc9..8a2b24a113 100644 --- a/crates/nu-command/src/system/exec.rs +++ b/crates/nu-command/src/system/exec.rs @@ -45,6 +45,7 @@ On Windows based systems, Nushell will wait for the command to finish and then e call.head, engine_state, stack, + &cwd, )); }; executable diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index 32543716f1..25367d9576 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -1,6 +1,6 @@ use nu_cmd_base::hook::eval_hook; use nu_engine::{command_prelude::*, env_to_strings, get_eval_expression}; -use nu_path::{dots::expand_ndots, expand_tilde}; +use nu_path::{dots::expand_ndots, expand_tilde, AbsolutePath}; use nu_protocol::{did_you_mean, process::ChildProcess, ByteStream, NuGlob, OutDest, Signals}; use nu_system::ForegroundChild; use nu_utils::IgnoreCaseExt; @@ -78,7 +78,13 @@ impl Command for External { // effect if it's an absolute path already let paths = nu_engine::env::path_str(engine_state, stack, call.head)?; let Some(executable) = which(expanded_name, &paths, cwd.as_ref()) else { - return Err(command_not_found(&name_str, call.head, engine_state, stack)); + return Err(command_not_found( + &name_str, + call.head, + engine_state, + stack, + &cwd, + )); }; executable }; @@ -371,6 +377,7 @@ pub fn command_not_found( span: Span, engine_state: &EngineState, stack: &mut Stack, + cwd: &AbsolutePath, ) -> ShellError { // Run the `command_not_found` hook if there is one. if let Some(hook) = &stack.get_config(engine_state).hooks.command_not_found { @@ -481,12 +488,12 @@ pub fn command_not_found( } // If we find a file, it's likely that the user forgot to set permissions - if Path::new(name).is_file() { + if cwd.join(name).is_file() { return ShellError::ExternalCommand { - label: format!("Command `{name}` not found"), - help: format!("`{name}` refers to a file that is not executable. Did you forget to set execute permissions?"), - span, - }; + label: format!("Command `{name}` not found"), + help: format!("`{name}` refers to a file that is not executable. Did you forget to set execute permissions?"), + span, + }; } // We found nothing useful. Give up and return a generic error message. diff --git a/tests/hooks/mod.rs b/tests/hooks/mod.rs index 4fc7490106..fe18194b45 100644 --- a/tests/hooks/mod.rs +++ b/tests/hooks/mod.rs @@ -68,7 +68,7 @@ fn pre_prompt_hook(code: &str) -> String { format!( "$env.config = {{ hooks: {{ - pre_prompt: {code} + pre_prompt: [{code}] }} }}" ) @@ -78,9 +78,9 @@ fn pre_prompt_hook_code(code: &str) -> String { format!( "$env.config = {{ hooks: {{ - pre_prompt: {{ + pre_prompt: [{{ code: {code} - }} + }}] }} }}" ) @@ -90,7 +90,7 @@ fn pre_execution_hook(code: &str) -> String { format!( "$env.config = {{ hooks: {{ - pre_execution: {code} + pre_execution: [{code}] }} }}" ) @@ -100,9 +100,9 @@ fn pre_execution_hook_code(code: &str) -> String { format!( "$env.config = {{ hooks: {{ - pre_execution: {{ + pre_execution: [{{ code: {code} - }} + }}] }} }}" )