diff --git a/crates/nu-cmd-lang/src/core_commands/overlay/hide.rs b/crates/nu-cmd-lang/src/core_commands/overlay/hide.rs index 666fedead8..b747ccd504 100644 --- a/crates/nu-cmd-lang/src/core_commands/overlay/hide.rs +++ b/crates/nu-cmd-lang/src/core_commands/overlay/hide.rs @@ -96,6 +96,7 @@ impl Command for OverlayHide { for (name, val) in env_vars_to_keep { stack.add_env_var(name, val); } + stack.update_config(engine_state)?; Ok(PipelineData::empty()) } diff --git a/crates/nu-cmd-lang/src/core_commands/overlay/use_.rs b/crates/nu-cmd-lang/src/core_commands/overlay/use_.rs index bf29087a61..5ddf4c5f81 100644 --- a/crates/nu-cmd-lang/src/core_commands/overlay/use_.rs +++ b/crates/nu-cmd-lang/src/core_commands/overlay/use_.rs @@ -178,6 +178,7 @@ impl Command for OverlayUse { } } else { caller_stack.add_overlay(overlay_name); + caller_stack.update_config(engine_state)?; } Ok(PipelineData::empty()) diff --git a/tests/overlays/mod.rs b/tests/overlays/mod.rs index cd101bda6d..55d9f5a347 100644 --- a/tests/overlays/mod.rs +++ b/tests/overlays/mod.rs @@ -918,6 +918,74 @@ fn overlay_use_export_env() { assert_eq!(actual_repl.out, "foo"); } +#[test] +fn overlay_use_export_env_config_affected() { + let inp = &[ + "mut out = []", + "$env.config.filesize.unit = 'metric'", + "$out ++= [(20MB | into string)]", + "module spam { export-env { $env.config.filesize.unit = 'binary' } }", + "overlay use spam", + "$out ++= [(20MiB | into string)]", + r#"$out | to json --raw"#, + ]; + + let actual = nu!(&inp.join("; ")); + let actual_repl = nu!(nu_repl_code(inp)); + + assert_eq!(actual.out, r#"["20.0 MB","20.0 MiB"]"#); + assert_eq!(actual_repl.out, r#"["20.0 MB","20.0 MiB"]"#); +} + +#[test] +fn overlay_hide_config_affected() { + let inp = &[ + "mut out = []", + "$env.config.filesize.unit = 'metric'", + "$out ++= [(20MB | into string)]", + "module spam { export-env { $env.config.filesize.unit = 'binary' } }", + "overlay use spam", + "$out ++= [(20MiB | into string)]", + "overlay hide", + "$out ++= [(20MB | into string)]", + r#"$out | to json --raw"#, + ]; + + // Can't hide overlay within the same source file + // let actual = nu!(&inp.join("; ")); + let actual_repl = nu!(nu_repl_code(inp)); + + // assert_eq!(actual.out, r#"["20.0 MB","20.0 MiB","20.0 MB"]"#); + assert_eq!(actual_repl.out, r#"["20.0 MB","20.0 MiB","20.0 MB"]"#); +} + +#[test] +fn overlay_use_after_hide_config_affected() { + let inp = &[ + "mut out = []", + "$env.config.filesize.unit = 'metric'", + "$out ++= [(20MB | into string)]", + "module spam { export-env { $env.config.filesize.unit = 'binary' } }", + "overlay use spam", + "$out ++= [(20MiB | into string)]", + "overlay hide", + "$out ++= [(20MB | into string)]", + "overlay use spam", + "$out ++= [(20MiB | into string)]", + r#"$out | to json --raw"#, + ]; + + // Can't hide overlay within the same source file + // let actual = nu!(&inp.join("; ")); + let actual_repl = nu!(nu_repl_code(inp)); + + // assert_eq!(actual.out, r#"["20.0 MB","20.0 MiB","20.0 MB"]"#); + assert_eq!( + actual_repl.out, + r#"["20.0 MB","20.0 MiB","20.0 MB","20.0 MiB"]"# + ); +} + #[test] fn overlay_use_export_env_hide() { let inp = &[