From cf8fcef9bfb979a5433a86981bc4c63b434a8aa8 Mon Sep 17 00:00:00 2001 From: Wind Date: Sat, 20 Apr 2024 23:04:41 +0800 Subject: [PATCH] set the type of default NU_LIB_DIRS and NU_PLUGIN_DIRS to list (#12573) # Description Fix: #12489 I believe the issue it's because the default value of `NU_LIB_DIRS` and `NU_PLUGIN_DIRS` is a string, but it should be a list. So if users don't set up these values in `env.nu`, we will get a problem. --- src/main.rs | 8 ++++++-- src/tests/test_env.rs | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index af2bb3b922..689f846722 100644 --- a/src/main.rs +++ b/src/main.rs @@ -132,14 +132,18 @@ fn main() -> Result<()> { default_nu_lib_dirs_path.push("scripts"); engine_state.add_env_var( "NU_LIB_DIRS".to_string(), - Value::test_string(default_nu_lib_dirs_path.to_string_lossy()), + Value::test_list(vec![Value::test_string( + default_nu_lib_dirs_path.to_string_lossy(), + )]), ); let mut default_nu_plugin_dirs_path = nushell_config_path; default_nu_plugin_dirs_path.push("plugins"); engine_state.add_env_var( "NU_PLUGIN_DIRS".to_string(), - Value::test_string(default_nu_plugin_dirs_path.to_string_lossy()), + Value::test_list(vec![Value::test_string( + default_nu_plugin_dirs_path.to_string_lossy(), + )]), ); // End: Default NU_LIB_DIRS, NU_PLUGIN_DIRS diff --git a/src/tests/test_env.rs b/src/tests/test_env.rs index 2241839f85..159b3d0a20 100644 --- a/src/tests/test_env.rs +++ b/src/tests/test_env.rs @@ -1,4 +1,5 @@ use crate::tests::{fail_test, run_test, TestResult}; +use nu_test_support::nu; #[test] fn shorthand_env_1() -> TestResult { @@ -14,3 +15,15 @@ fn shorthand_env_2() -> TestResult { fn shorthand_env_3() -> TestResult { run_test(r#"FOO=BAZ BAR=MOO $env.FOO"#, "BAZ") } + +#[test] +fn default_nu_lib_dirs_type() { + let actual = nu!("$env.NU_LIB_DIRS | describe"); + assert_eq!(actual.out, "list"); +} + +#[test] +fn default_nu_plugin_dirs_type() { + let actual = nu!("$env.NU_PLUGIN_DIRS | describe"); + assert_eq!(actual.out, "list"); +}