From 6b2327f231bf6a36899dabd07d871830f5f62707 Mon Sep 17 00:00:00 2001 From: Michael Angerman Date: Fri, 26 Feb 2021 12:05:22 -0800 Subject: [PATCH] help generate_docs | flatten crashes nushell (#3099) * fix case where parent_name was {nu, term} and possibly others in the future by doing an extra test first to see if if the *parent_name key actually exists in cmap * update with help generate_docs testing --- crates/nu-command/tests/commands/help.rs | 31 ++++++++++++++++++++++++ crates/nu-command/tests/commands/mod.rs | 1 + crates/nu-engine/src/documentation.rs | 10 +++++--- 3 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 crates/nu-command/tests/commands/help.rs diff --git a/crates/nu-command/tests/commands/help.rs b/crates/nu-command/tests/commands/help.rs new file mode 100644 index 000000000..6d8623bde --- /dev/null +++ b/crates/nu-command/tests/commands/help.rs @@ -0,0 +1,31 @@ +use nu_test_support::{nu, pipeline}; + +#[test] +fn help_commands_count() { + let actual = nu!( + cwd: ".", pipeline( + r#" + help commands | count + "# + )); + + let output = actual.out; + let output_int: i32 = output.parse().unwrap(); + let is_positive = output_int.is_positive(); + assert!(is_positive); +} + +#[test] +fn help_generate_docs_count() { + let actual = nu!( + cwd: ".", pipeline( + r#" + help generate_docs | flatten | count + "# + )); + + let output = actual.out; + let output_int: i32 = output.parse().unwrap(); + let is_positive = output_int.is_positive(); + assert!(is_positive); +} diff --git a/crates/nu-command/tests/commands/mod.rs b/crates/nu-command/tests/commands/mod.rs index 5f9d9a838..beca72b5e 100644 --- a/crates/nu-command/tests/commands/mod.rs +++ b/crates/nu-command/tests/commands/mod.rs @@ -22,6 +22,7 @@ mod get; mod group_by; mod hash_; mod headers; +mod help; mod histogram; mod insert; mod into_int; diff --git a/crates/nu-engine/src/documentation.rs b/crates/nu-engine/src/documentation.rs index dc8e69c98..125692169 100644 --- a/crates/nu-engine/src/documentation.rs +++ b/crates/nu-engine/src/documentation.rs @@ -67,10 +67,12 @@ pub fn generate_docs(scope: &Scope) -> Value { if name.contains(' ') { let split_name = name.split_whitespace().collect_vec(); let parent_name = split_name.first().expect("Expected a parent command name"); - let sub_names = cmap - .get_mut(*parent_name) - .expect("Expected a entry for parent"); - sub_names.push(name.to_owned()); + if cmap.contains_key(*parent_name) { + let sub_names = cmap + .get_mut(*parent_name) + .expect("Expected a entry for parent"); + sub_names.push(name.to_owned()); + } } else { cmap.insert(name.to_owned(), Vec::new()); };