From f03f1949bf13fb541f709348502d108063dadb3f Mon Sep 17 00:00:00 2001 From: Leonhard Kipp Date: Fri, 2 Apr 2021 00:09:33 +0200 Subject: [PATCH] Logs and tests (#3247) * Add command name to err * Add var name to error message * Add test for def comment in test --- .../src/commands/classified/external.rs | 2 +- crates/nu-engine/src/evaluate/evaluator.rs | 2 +- crates/nu-parser/tests/main.rs | 25 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 crates/nu-parser/tests/main.rs diff --git a/crates/nu-command/src/commands/classified/external.rs b/crates/nu-command/src/commands/classified/external.rs index c6936901d3..1a648c9ea7 100644 --- a/crates/nu-command/src/commands/classified/external.rs +++ b/crates/nu-command/src/commands/classified/external.rs @@ -31,7 +31,7 @@ pub(crate) async fn run_external_command( if !context.host.lock().is_external_cmd(&command.name) { return Err(ShellError::labeled_error( "Command not found", - "command not found", + format!("command {} not found", &command.name), &command.name_tag, )); } diff --git a/crates/nu-engine/src/evaluate/evaluator.rs b/crates/nu-engine/src/evaluate/evaluator.rs index cce272284e..c7c323c7b7 100644 --- a/crates/nu-engine/src/evaluate/evaluator.rs +++ b/crates/nu-engine/src/evaluate/evaluator.rs @@ -264,7 +264,7 @@ fn evaluate_reference(name: &str, ctx: &EvaluationContext, tag: Tag) -> Result Ok(v), None => Err(ShellError::labeled_error( "Variable not in scope", - "unknown variable", + format!("unknown variable: {}", x), tag.span, )), }, diff --git a/crates/nu-parser/tests/main.rs b/crates/nu-parser/tests/main.rs new file mode 100644 index 0000000000..2db27e58df --- /dev/null +++ b/crates/nu-parser/tests/main.rs @@ -0,0 +1,25 @@ +use nu_test_support::fs::Stub::FileWithContent; +use nu_test_support::nu; +use nu_test_support::playground::Playground; + +#[test] +fn defs_contain_comment_in_help() { + Playground::setup("comment_test", |dirs, sandbox| { + sandbox.with_files(vec![FileWithContent( + "my_def.nu", + r#" + # I comment and test. I am a good boy. + def comment_philosphy [] { + echo It’s not a bug – it’s an undocumented feature. (Anonymous) + } + "#, + )]); + + let actual = nu!(cwd: dirs.test(), r#" + source my_def.nu + help comment_philosphy + "#); + + assert!(actual.out.contains("I comment and test. I am a good boy.")); + }); +}