diff --git a/src/main.rs b/src/main.rs index 2c7b94b6289..bef8d07caf0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,8 +24,8 @@ use nu_cli::gather_parent_env_vars; use nu_lsp::LanguageServer; use nu_path::canonicalize_with; use nu_protocol::{ - engine::EngineState, report_shell_error, ByteStream, PipelineData, ShellError, Span, Spanned, - Value, + engine::EngineState, report_shell_error, ByteStream, Config, IntoValue, PipelineData, + ShellError, Span, Spanned, Value, }; use nu_std::load_standard_library; use nu_utils::perf; @@ -257,6 +257,13 @@ fn main() -> Result<()> { perf!("acquire_terminal", start_time, use_color); } + start_time = std::time::Instant::now(); + engine_state.add_env_var( + "config".into(), + Config::default().into_value(Span::unknown()), + ); + perf!("$env.config setup", start_time, use_color); + start_time = std::time::Instant::now(); if let Some(include_path) = &parsed_nu_cli_args.include_path { let span = include_path.span; diff --git a/tests/repl/test_config_path.rs b/tests/repl/test_config_path.rs index 63488ecb6a1..29c090db170 100644 --- a/tests/repl/test_config_path.rs +++ b/tests/repl/test_config_path.rs @@ -298,3 +298,81 @@ fn test_xdg_config_symlink() { ); }); } + +#[test] +fn no_config_does_not_load_env_files() { + let nu = nu_test_support::fs::executable_path().display().to_string(); + let cmd = format!( + r#" + {nu} -n -c "view files | where filename =~ 'env\\.nu$' | length" + "# + ); + let actual = nu!(cmd); + + assert_eq!(actual.out, "0"); +} + +#[test] +fn no_config_does_not_load_config_files() { + let nu = nu_test_support::fs::executable_path().display().to_string(); + let cmd = format!( + r#" + {nu} -n -c "view files | where filename =~ 'config\\.nu$' | length" + "# + ); + let actual = nu!(cmd); + + assert_eq!(actual.out, "0"); +} + +#[test] +fn commandstring_does_not_load_config_files() { + let nu = nu_test_support::fs::executable_path().display().to_string(); + let cmd = format!( + r#" + {nu} -c "view files | where filename =~ 'config\\.nu$' | length" + "# + ); + let actual = nu!(cmd); + + assert_eq!(actual.out, "0"); +} + +#[test] +fn commandstring_does_not_load_user_env() { + let nu = nu_test_support::fs::executable_path().display().to_string(); + let cmd = format!( + r#" + {nu} -c "view files | where filename =~ '[^_]env\\.nu$' | length" + "# + ); + let actual = nu!(cmd); + + assert_eq!(actual.out, "0"); +} + +#[test] +fn commandstring_loads_default_env() { + let nu = nu_test_support::fs::executable_path().display().to_string(); + let cmd = format!( + r#" + {nu} -c "view files | where filename =~ 'default_env\\.nu$' | length" + "# + ); + let actual = nu!(cmd); + + assert_eq!(actual.out, "1"); +} + +#[test] +fn commandstring_populates_config_record() { + let nu = nu_test_support::fs::executable_path().display().to_string(); + let cmd = format!( + r#" + {nu} --no-std-lib -n -c "$env.config.show_banner" + "# + ); + let actual = nu!(cmd); + + assert_eq!(actual.out, "true"); +}