mirror of
https://github.com/nushell/nushell.git
synced 2025-01-11 00:38:23 +01:00
Add test cases for $nu.config-path change (#6385)
* Add test cases for $nu.config-path change Part of #6366 Signed-off-by: nibon7 <nibon7@163.com> * do not start a new process to test default config path Signed-off-by: nibon7 <nibon7@163.com> Signed-off-by: nibon7 <nibon7@163.com>
This commit is contained in:
parent
7ef4e5f940
commit
839b264261
@ -1,4 +1,5 @@
|
||||
mod test_conditionals;
|
||||
mod test_config_path;
|
||||
mod test_converters;
|
||||
mod test_custom_commands;
|
||||
mod test_engine;
|
||||
|
38
src/tests/test_config_path.rs
Normal file
38
src/tests/test_config_path.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use nu_test_support::nu;
|
||||
|
||||
#[test]
|
||||
fn test_default_config_path() {
|
||||
let config_dir = nu_path::config_dir().expect("Could not get config directory");
|
||||
let cwd = std::env::current_dir().expect("Could not get current working directory");
|
||||
|
||||
let config_path = config_dir.join("nushell").join("config.nu");
|
||||
let actual = nu!(cwd: &cwd, "$nu.config-path");
|
||||
assert_eq!(actual.out, config_path.to_string_lossy().to_string());
|
||||
|
||||
let env_path = config_dir.join("nushell").join("env.nu");
|
||||
let actual = nu!(cwd: &cwd, "$nu.env-path");
|
||||
assert_eq!(actual.out, env_path.to_string_lossy().to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_alternate_config_path() {
|
||||
let config_file = "crates/nu-utils/src/sample_config/default_config.nu";
|
||||
let env_file = "crates/nu-utils/src/sample_config/default_env.nu";
|
||||
|
||||
let cwd = std::env::current_dir().expect("Could not get current working directory");
|
||||
|
||||
let config_path =
|
||||
nu_path::canonicalize_with(config_file, &cwd).expect("Could not get config path");
|
||||
let actual = nu!(
|
||||
cwd: &cwd,
|
||||
format!("nu --config {:?} -c '$nu.config-path'", config_path)
|
||||
);
|
||||
assert_eq!(actual.out, config_path.to_string_lossy().to_string());
|
||||
|
||||
let env_path = nu_path::canonicalize_with(env_file, &cwd).expect("Could not get env path");
|
||||
let actual = nu!(
|
||||
cwd: &cwd,
|
||||
format!("nu --env-config {:?} -c '$nu.env-path'", env_path)
|
||||
);
|
||||
assert_eq!(actual.out, env_path.to_string_lossy().to_string());
|
||||
}
|
Loading…
Reference in New Issue
Block a user