mirror of
https://github.com/nushell/nushell.git
synced 2025-08-14 02:09:04 +02:00
Isolate tests from user config (#12437)
# Description This is an attempt to isolate the unit tests from whatever might be in the user's config. If the user's config is broken in some way or incompatible with this version (for example, especially if there are plugins that aren't built for this version), tests can spuriously fail. This makes tests more reliably pass the same way they would on CI even if the user has config, and should also make them run faster. I think this is _good enough_, but I still think we should have a specific config dir env variable for nushell specifically (rather than having to use `XDG_CONFIG_HOME`, which would mess with other things) and then we can just have `nu-test-support` set that to a temporary dir containing the shipped default config files. # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib`
This commit is contained in:
104
src/run.rs
104
src/run.rs
@ -146,57 +146,69 @@ pub(crate) fn run_file(
|
||||
) -> Result<(), miette::ErrReport> {
|
||||
trace!("run_file");
|
||||
let mut stack = nu_protocol::engine::Stack::new();
|
||||
let start_time = std::time::Instant::now();
|
||||
|
||||
#[cfg(feature = "plugin")]
|
||||
read_plugin_file(
|
||||
engine_state,
|
||||
&mut stack,
|
||||
parsed_nu_cli_args.plugin_file,
|
||||
NUSHELL_FOLDER,
|
||||
);
|
||||
perf(
|
||||
"read plugins",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
let start_time = std::time::Instant::now();
|
||||
// only want to load config and env if relative argument is provided.
|
||||
if parsed_nu_cli_args.env_file.is_some() {
|
||||
config_files::read_config_file(engine_state, &mut stack, parsed_nu_cli_args.env_file, true);
|
||||
} else {
|
||||
config_files::read_default_env_file(engine_state, &mut stack)
|
||||
}
|
||||
perf(
|
||||
"read env.nu",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
let start_time = std::time::Instant::now();
|
||||
if parsed_nu_cli_args.config_file.is_some() {
|
||||
config_files::read_config_file(
|
||||
// if the --no-config-file(-n) option is NOT passed, load the plugin file,
|
||||
// load the default env file or custom (depending on parsed_nu_cli_args.env_file),
|
||||
// and maybe a custom config file (depending on parsed_nu_cli_args.config_file)
|
||||
//
|
||||
// if the --no-config-file(-n) flag is passed, do not load plugin, env, or config files
|
||||
if parsed_nu_cli_args.no_config_file.is_none() {
|
||||
let start_time = std::time::Instant::now();
|
||||
#[cfg(feature = "plugin")]
|
||||
read_plugin_file(
|
||||
engine_state,
|
||||
&mut stack,
|
||||
parsed_nu_cli_args.config_file,
|
||||
false,
|
||||
parsed_nu_cli_args.plugin_file,
|
||||
NUSHELL_FOLDER,
|
||||
);
|
||||
perf(
|
||||
"read plugins",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
let start_time = std::time::Instant::now();
|
||||
// only want to load config and env if relative argument is provided.
|
||||
if parsed_nu_cli_args.env_file.is_some() {
|
||||
config_files::read_config_file(
|
||||
engine_state,
|
||||
&mut stack,
|
||||
parsed_nu_cli_args.env_file,
|
||||
true,
|
||||
);
|
||||
} else {
|
||||
config_files::read_default_env_file(engine_state, &mut stack)
|
||||
}
|
||||
perf(
|
||||
"read env.nu",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
let start_time = std::time::Instant::now();
|
||||
if parsed_nu_cli_args.config_file.is_some() {
|
||||
config_files::read_config_file(
|
||||
engine_state,
|
||||
&mut stack,
|
||||
parsed_nu_cli_args.config_file,
|
||||
false,
|
||||
);
|
||||
}
|
||||
perf(
|
||||
"read config.nu",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
}
|
||||
perf(
|
||||
"read config.nu",
|
||||
start_time,
|
||||
file!(),
|
||||
line!(),
|
||||
column!(),
|
||||
use_color,
|
||||
);
|
||||
|
||||
// Regenerate the $nu constant to contain the startup time and any other potential updates
|
||||
let nu_const = create_nu_constant(engine_state, input.span().unwrap_or_else(Span::unknown))?;
|
||||
|
Reference in New Issue
Block a user