From f691c71ebe6db1902272b38ebc82fdc444a32177 Mon Sep 17 00:00:00 2001 From: NotTheDr01ds <32344964+NotTheDr01ds@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:40:07 -0400 Subject: [PATCH] Minimal std exports --- crates/nu-std/std/mod.nu | 13 ++--------- crates/nu-std/testing.nu | 4 ++++ .../tests/logger_tests/test_basic_commands.nu | 1 - .../tests/logger_tests/test_logger_env.nu | 2 +- crates/nu-std/tests/test_std.nu | 22 ------------------- crates/nu-std/tests/test_std_postload.nu | 11 ++++++++++ crates/nu-std/tests/test_std_preload.nu | 11 ++++++++++ tests/repl/test_stdlib.rs | 5 ++++- 8 files changed, 33 insertions(+), 36 deletions(-) delete mode 100644 crates/nu-std/tests/test_std.nu create mode 100644 crates/nu-std/tests/test_std_postload.nu create mode 100644 crates/nu-std/tests/test_std_preload.nu diff --git a/crates/nu-std/std/mod.nu b/crates/nu-std/std/mod.nu index d0b892d8e4..ed723a3a1c 100644 --- a/crates/nu-std/std/mod.nu +++ b/crates/nu-std/std/mod.nu @@ -1,18 +1,9 @@ -# std.nu, `used` to load all standard library components +# std.nu, `used` to load base standard library components -#export module assert -#export module bench -#export module dirs -#export module dt -#export module formats -#export module help export module input export module iter -#export module log -#export module math -#export module xml -# Make commands available in the top-level module +# Make certain commands available in the top-level namespace export use lib * export use formats * export use dt * \ No newline at end of file diff --git a/crates/nu-std/testing.nu b/crates/nu-std/testing.nu index 64212016df..003e1d1ebc 100644 --- a/crates/nu-std/testing.nu +++ b/crates/nu-std/testing.nu @@ -1,4 +1,8 @@ use std/log +export-env { + # Place NU_FORMAT... environment variables in module-scope + export use std/log * +} def "nu-complete threads" [] { seq 1 (sys cpu | length) diff --git a/crates/nu-std/tests/logger_tests/test_basic_commands.nu b/crates/nu-std/tests/logger_tests/test_basic_commands.nu index ce00109778..3e22e10bb2 100644 --- a/crates/nu-std/tests/logger_tests/test_basic_commands.nu +++ b/crates/nu-std/tests/logger_tests/test_basic_commands.nu @@ -1,4 +1,3 @@ -use std * use std/assert def run [ diff --git a/crates/nu-std/tests/logger_tests/test_logger_env.nu b/crates/nu-std/tests/logger_tests/test_logger_env.nu index 1a148efec0..2890dd8929 100644 --- a/crates/nu-std/tests/logger_tests/test_logger_env.nu +++ b/crates/nu-std/tests/logger_tests/test_logger_env.nu @@ -1,5 +1,5 @@ -use std * use std/assert +use std/log use std/log * #[test] diff --git a/crates/nu-std/tests/test_std.nu b/crates/nu-std/tests/test_std.nu deleted file mode 100644 index bfd6757d75..0000000000 --- a/crates/nu-std/tests/test_std.nu +++ /dev/null @@ -1,22 +0,0 @@ -use std/assert - -#[test] -def std_pre_import [] { - # These commands shouldn't exist without an import - assert length (scope commands | where name == "path add") 0 - assert length (scope commands | where name == "ellie") 0 - assert length (scope commands | where name == "repeat") 0 - assert length (scope commands | where name == "from jsonl") 0 - assert length (scope commands | where name == "datetime-diff") 0 -} - -def std_post_import [] { - # After importing std, these commands should be - # available at the top level namespace - use std * - assert length (scope commands | where name == "path add") 1 - assert length (scope commands | where name == "ellie") 1 - assert length (scope commands | where name == "repeat") 1 - assert length (scope commands | where name == "from jsonl") 1 - assert length (scope commands | where name == "datetime-diff") 1 -} \ No newline at end of file diff --git a/crates/nu-std/tests/test_std_postload.nu b/crates/nu-std/tests/test_std_postload.nu new file mode 100644 index 0000000000..5ba944e0d3 --- /dev/null +++ b/crates/nu-std/tests/test_std_postload.nu @@ -0,0 +1,11 @@ +use std/assert +export use std * + +#[test] +def std_post_import [] { + assert length (scope commands | where name == "path add") 1 + assert length (scope commands | where name == "ellie") 1 + assert length (scope commands | where name == "repeat") 1 + assert length (scope commands | where name == "from jsonl") 1 + assert length (scope commands | where name == "datetime-diff") 1 +} \ No newline at end of file diff --git a/crates/nu-std/tests/test_std_preload.nu b/crates/nu-std/tests/test_std_preload.nu new file mode 100644 index 0000000000..a1f88249b6 --- /dev/null +++ b/crates/nu-std/tests/test_std_preload.nu @@ -0,0 +1,11 @@ +use std/assert + +#[test] +def std_pre_import [] { + # These commands shouldn't exist without an import + assert length (scope commands | where name == "path add") 0 + assert length (scope commands | where name == "ellie") 0 + assert length (scope commands | where name == "repeat") 0 + assert length (scope commands | where name == "from jsonl") 0 + assert length (scope commands | where name == "datetime-diff") 0 +} \ No newline at end of file diff --git a/tests/repl/test_stdlib.rs b/tests/repl/test_stdlib.rs index 71188e4053..51772f09fe 100644 --- a/tests/repl/test_stdlib.rs +++ b/tests/repl/test_stdlib.rs @@ -7,5 +7,8 @@ fn not_loaded() -> TestResult { #[test] fn use_command() -> TestResult { - run_test_std("use ([ std, assert ] | path join); assert true; print 'it works'", "it works") + run_test_std( + "use ([ std, assert ] | path join); assert true; print 'it works'", + "it works", + ) }