Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from nushell:main #527

Merged
merged 4 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ bench = false
# To use a development version of a dependency please use a global override here
# changing versions in each sub-crate of the workspace is tedious
[patch.crates-io]
# reedline = { git = "https://github.com/nushell/reedline", branch = "main" }
reedline = { git = "https://github.com/nushell/reedline", branch = "main" }
# nu-ansi-term = {git = "https://github.com/nushell/nu-ansi-term.git", branch = "main"}

# Run all benchmarks with `cargo bench`
Expand Down
2 changes: 2 additions & 0 deletions crates/nu-command/src/filters/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ fn insert(
let replacement: Value = call.req(engine_state, stack, 1)?;

match input {
// Propagate errors in the pipeline
PipelineData::Value(Value::Error { error, .. }, ..) => Err(*error),
PipelineData::Value(mut value, metadata) => {
if let Value::Closure { val, .. } = replacement {
match (cell_path.members.first(), &mut value) {
Expand Down
2 changes: 2 additions & 0 deletions crates/nu-command/src/filters/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ repeating this process with row 1, and so on."#
PipelineData::Value(Value::Record { val: inp, .. }, ..),
Value::Record { val: to_merge, .. },
) => Ok(Value::record(do_merge(inp, &to_merge), head).into_pipeline_data()),
// Propagate errors in the pipeline
(PipelineData::Value(Value::Error { error, .. }, ..), _) => Err(*error.clone()),
(PipelineData::Value(val, ..), ..) => {
// Only point the "value originates here" arrow at the merge value
// if it was generated from a block. Otherwise, point at the pipeline value. -Leon 2022-10-27
Expand Down
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions tests/plugins/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ fn get_current_dir() {
"cd tests; example env --cwd"
);
assert!(result.status.success());
#[cfg(not(windows))]
assert_eq!(cwd, result.out);
#[cfg(windows)]
{
// cwd == r"e:\Study\Nushell", while result.out == r"E:\Study\Nushell"
assert_eq!(
cwd.chars().next().unwrap().to_ascii_uppercase(),
result.out.chars().next().unwrap().to_ascii_uppercase()
);
assert_eq!(cwd[1..], result.out[1..]);
}
}

#[test]
Expand Down
78 changes: 78 additions & 0 deletions tests/repl/test_config_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Loading