set the type of default NU_LIB_DIRS and NU_PLUGIN_DIRS to list<string> (#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.
This commit is contained in:
Wind 2024-04-20 23:04:41 +08:00 committed by GitHub
parent 47867a58df
commit cf8fcef9bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View File

@ -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

View File

@ -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<string>");
}
#[test]
fn default_nu_plugin_dirs_type() {
let actual = nu!("$env.NU_PLUGIN_DIRS | describe");
assert_eq!(actual.out, "list<string>");
}