diff --git a/crates/nu-std/src/lib.rs b/crates/nu-std/src/lib.rs index cc2fff688e..340727d2ee 100644 --- a/crates/nu-std/src/lib.rs +++ b/crates/nu-std/src/lib.rs @@ -18,23 +18,20 @@ pub fn load_standard_library( let mut std_files = vec![ ("mod.nu", include_str!("../std/mod.nu")), - ("core", include_str!("../std/core/mod.nu")), - ("assert", include_str!("../std/assert/mod.nu")), - ("bench", include_str!("../std/bench/mod.nu")), - ("dirs", include_str!("../std/dirs/mod.nu")), - ( - "deprecated_dirs", - include_str!("../std/deprecated_dirs/mod.nu"), - ), - ("dt", include_str!("../std/dt/mod.nu")), - ("formats", include_str!("../std/formats/mod.nu")), - ("help", include_str!("../std/help/mod.nu")), - ("input", include_str!("../std/input/mod.nu")), - ("iter", include_str!("../std/iter/mod.nu")), - ("log", include_str!("../std/log/mod.nu")), - ("math", include_str!("../std/math/mod.nu")), - ("util", include_str!("../std/util/mod.nu")), - ("xml", include_str!("../std/xml/mod.nu")), + ("core", include_str!("../std/core.nu")), + ("assert", include_str!("../std/assert.nu")), + ("bench", include_str!("../std/bench.nu")), + ("dirs", include_str!("../std/dirs.nu")), + ("deprecated_dirs", include_str!("../std/deprecated_dirs.nu")), + ("dt", include_str!("../std/dt.nu")), + ("formats", include_str!("../std/formats.nu")), + ("help", include_str!("../std/help.nu")), + ("input", include_str!("../std/input.nu")), + ("iter", include_str!("../std/iter.nu")), + ("log", include_str!("../std/log.nu")), + ("math", include_str!("../std/math.nu")), + ("lib", include_str!("../std/lib.nu")), + ("xml", include_str!("../std/xml.nu")), ]; let mut working_set = StateWorkingSet::new(engine_state); diff --git a/crates/nu-std/std/assert/mod.nu b/crates/nu-std/std/assert.nu similarity index 100% rename from crates/nu-std/std/assert/mod.nu rename to crates/nu-std/std/assert.nu diff --git a/crates/nu-std/std/bench/mod.nu b/crates/nu-std/std/bench.nu similarity index 100% rename from crates/nu-std/std/bench/mod.nu rename to crates/nu-std/std/bench.nu diff --git a/crates/nu-std/std/core/mod.nu b/crates/nu-std/std/core.nu similarity index 100% rename from crates/nu-std/std/core/mod.nu rename to crates/nu-std/std/core.nu diff --git a/crates/nu-std/std/deprecated_dirs/mod.nu b/crates/nu-std/std/deprecated_dirs.nu similarity index 100% rename from crates/nu-std/std/deprecated_dirs/mod.nu rename to crates/nu-std/std/deprecated_dirs.nu diff --git a/crates/nu-std/std/dirs/mod.nu b/crates/nu-std/std/dirs.nu similarity index 100% rename from crates/nu-std/std/dirs/mod.nu rename to crates/nu-std/std/dirs.nu diff --git a/crates/nu-std/std/dt/mod.nu b/crates/nu-std/std/dt.nu similarity index 100% rename from crates/nu-std/std/dt/mod.nu rename to crates/nu-std/std/dt.nu diff --git a/crates/nu-std/std/formats/mod.nu b/crates/nu-std/std/formats.nu similarity index 100% rename from crates/nu-std/std/formats/mod.nu rename to crates/nu-std/std/formats.nu diff --git a/crates/nu-std/std/help/mod.nu b/crates/nu-std/std/help.nu similarity index 100% rename from crates/nu-std/std/help/mod.nu rename to crates/nu-std/std/help.nu diff --git a/crates/nu-std/std/input/mod.nu b/crates/nu-std/std/input.nu similarity index 100% rename from crates/nu-std/std/input/mod.nu rename to crates/nu-std/std/input.nu diff --git a/crates/nu-std/std/iter/mod.nu b/crates/nu-std/std/iter.nu similarity index 100% rename from crates/nu-std/std/iter/mod.nu rename to crates/nu-std/std/iter.nu diff --git a/crates/nu-std/std/util/mod.nu b/crates/nu-std/std/lib.nu similarity index 100% rename from crates/nu-std/std/util/mod.nu rename to crates/nu-std/std/lib.nu diff --git a/crates/nu-std/std/log/mod.nu b/crates/nu-std/std/log.nu similarity index 100% rename from crates/nu-std/std/log/mod.nu rename to crates/nu-std/std/log.nu diff --git a/crates/nu-std/std/math/mod.nu b/crates/nu-std/std/math.nu similarity index 100% rename from crates/nu-std/std/math/mod.nu rename to crates/nu-std/std/math.nu diff --git a/crates/nu-std/std/mod.nu b/crates/nu-std/std/mod.nu index 89b028dc6e..d0b892d8e4 100644 --- a/crates/nu-std/std/mod.nu +++ b/crates/nu-std/std/mod.nu @@ -1,161 +1,18 @@ # std.nu, `used` to load all standard library components -export module core -export module bench -export module assert -export module dirs -export module dt -export module formats -export module help +#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 util -export module xml -export-env { - use dirs [] - use log [] -} +#export module log +#export module math +#export module xml -def deprecation_warning [ - cmd_name: string -] { -print -e $" -(ansi red)Warning:(ansi reset) '($cmd_name)' is being moved from the 'std' library to -'std/util'. To remove this warning, import it using: - -use std/util ($cmd_name) - -" -} - -# Add the given paths to the PATH. -# -# # Example -# - adding some dummy paths to an empty PATH -# ```nushell -# >_ with-env { PATH: [] } { -# std path add "foo" -# std path add "bar" "baz" -# std path add "fooo" --append -# -# assert equal $env.PATH ["bar" "baz" "foo" "fooo"] -# -# print (std path add "returned" --ret) -# } -# ╭───┬──────────╮ -# │ 0 │ returned │ -# │ 1 │ bar │ -# │ 2 │ baz │ -# │ 3 │ foo │ -# │ 4 │ fooo │ -# ╰───┴──────────╯ -# ``` -# - adding paths based on the operating system -# ```nushell -# >_ std path add {linux: "foo", windows: "bar", darwin: "baz"} -# ``` -export def --env "path add" [ - --ret (-r) # return $env.PATH, useful in pipelines to avoid scoping. - --append (-a) # append to $env.PATH instead of prepending to. - ...paths # the paths to add to $env.PATH. -] { - deprecation_warning "path add" - - let span = (metadata $paths).span - let paths = $paths | flatten - - if ($paths | is-empty) or ($paths | length) == 0 { - error make {msg: "Empty input", label: { - text: "Provide at least one string or a record", - span: $span - }} - } - - let path_name = if "PATH" in $env { "PATH" } else { "Path" } - - let paths = $paths | each {|p| - let p = match ($p | describe | str replace --regex '<.*' '') { - "string" => $p, - "record" => { $p | get --ignore-errors $nu.os-info.name }, - } - - $p | path expand --no-symlink - } - - if null in $paths or ($paths | is-empty) { - error make {msg: "Empty input", label: { - text: $"Received a record, that does not contain a ($nu.os-info.name) key", - span: $span - }} - } - - load-env {$path_name: ( - $env - | get $path_name - | split row (char esep) - | if $append { append $paths } else { prepend $paths } - )} - - if $ret { - $env | get $path_name - } -} - -# the cute and friendly mascot of Nushell :) -export def ellie [] { - deprecation_warning ellie - let ellie = [ - " __ ,", - " .--()°'.'", - "'|, . ,'", - " !_-(_\\", - ] - - $ellie | str join "\n" | $"(ansi green)($in)(ansi reset)" -} - -# repeat anything a bunch of times, yielding a list of *n* times the input -# -# # Examples -# repeat a string -# > "foo" | std repeat 3 | str join -# "foofoofoo" -export def repeat [ - n: int # the number of repetitions, must be positive -]: any -> list { - deprecation_warning repeat - let item = $in - - if $n < 0 { - let span = metadata $n | get span - error make { - msg: $"(ansi red_bold)invalid_argument(ansi reset)" - label: { - text: $"n should be a positive integer, found ($n)" - span: $span - } - } - } - - if $n == 0 { - return [] - } - - 1..$n | each { $item } -} - -# return a null device file. -# -# # Examples -# run a command and ignore it's stderr output -# > cat xxx.txt e> (null-device) -export def null-device []: nothing -> path { - deprecation_warning "null-device" - if ($nu.os-info.name | str downcase) == "windows" { - '\\.\NUL' - } else { - "/dev/null" - } -} +# Make commands available in the top-level module +export use lib * +export use formats * +export use dt * \ No newline at end of file diff --git a/crates/nu-std/std/xml/mod.nu b/crates/nu-std/std/xml.nu similarity index 100% rename from crates/nu-std/std/xml/mod.nu rename to crates/nu-std/std/xml.nu diff --git a/crates/nu-std/testing.nu b/crates/nu-std/testing.nu index e2ec10ac98..64212016df 100644 --- a/crates/nu-std/testing.nu +++ b/crates/nu-std/testing.nu @@ -1,4 +1,4 @@ -use std log +use std/log def "nu-complete threads" [] { seq 1 (sys cpu | length) @@ -287,8 +287,6 @@ export def run-tests [ --list, # list the selected tests without running them. --threads: int@"nu-complete threads", # Amount of threads to use for parallel execution. Default: All threads are utilized ] { - use std log - let available_threads = (sys cpu | length) # Can't use pattern matching here due to https://github.com/nushell/nushell/issues/9198 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 cd1d4f3e08..ce00109778 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,5 @@ use std * +use std/assert def run [ system_level, @@ -6,9 +7,9 @@ def run [ --short ] { if $short { - ^$nu.current-exe --no-config-file --commands $'use std; NU_LOG_LEVEL=($system_level) std log ($message_level) --short "test message"' + ^$nu.current-exe --no-config-file --commands $'use std; use std/log; NU_LOG_LEVEL=($system_level) log ($message_level) --short "test message"' } else { - ^$nu.current-exe --no-config-file --commands $'use std; NU_LOG_LEVEL=($system_level) std log ($message_level) "test message"' + ^$nu.current-exe --no-config-file --commands $'use std; use std/log; NU_LOG_LEVEL=($system_level) log ($message_level) "test message"' } | complete | get --ignore-errors stderr } diff --git a/crates/nu-std/tests/logger_tests/test_log_custom.nu b/crates/nu-std/tests/logger_tests/test_log_custom.nu index da11150032..3965752734 100644 --- a/crates/nu-std/tests/logger_tests/test_log_custom.nu +++ b/crates/nu-std/tests/logger_tests/test_log_custom.nu @@ -1,5 +1,4 @@ -use std * -use std log * +use std/assert use commons.nu * def run-command [ @@ -12,12 +11,12 @@ def run-command [ ] { if ($level_prefix | is-empty) { if ($ansi | is-empty) { - ^$nu.current-exe --no-config-file --commands $'use std; NU_LOG_LEVEL=($system_level) std log custom "($message)" "($format)" ($log_level)' + ^$nu.current-exe --no-config-file --commands $'use std/log; NU_LOG_LEVEL=($system_level) log custom "($message)" "($format)" ($log_level)' } else { - ^$nu.current-exe --no-config-file --commands $'use std; NU_LOG_LEVEL=($system_level) std log custom "($message)" "($format)" ($log_level) --ansi "($ansi)"' + ^$nu.current-exe --no-config-file --commands $'use std/log; NU_LOG_LEVEL=($system_level) log custom "($message)" "($format)" ($log_level) --ansi "($ansi)"' } } else { - ^$nu.current-exe --no-config-file --commands $'use std; NU_LOG_LEVEL=($system_level) std log custom "($message)" "($format)" ($log_level) --level-prefix "($level_prefix)" --ansi "($ansi)"' + ^$nu.current-exe --no-config-file --commands $'use std/log; NU_LOG_LEVEL=($system_level) log custom "($message)" "($format)" ($log_level) --level-prefix "($level_prefix)" --ansi "($ansi)"' } | complete | get --ignore-errors stderr } @@ -31,6 +30,7 @@ def errors_during_deduction [] { #[test] def valid_calls [] { + use std/log * assert equal (run-command "DEBUG" "msg" "%MSG%" 25 --level-prefix "abc" --ansi (ansi default) | str trim --right) "msg" assert equal (run-command "DEBUG" "msg" "%LEVEL% %MSG%" 20 | str trim --right) $"((log-prefix).INFO) msg" assert equal (run-command "DEBUG" "msg" "%LEVEL% %MSG%" --level-prefix "abc" 20 | str trim --right) "abc msg" @@ -39,6 +39,7 @@ def valid_calls [] { #[test] def log-level_handling [] { + use std/log * assert equal (run-command "DEBUG" "msg" "%LEVEL% %MSG%" 20 | str trim --right) $"((log-prefix).INFO) msg" assert equal (run-command "WARNING" "msg" "%LEVEL% %MSG%" 20 | str trim --right) "" } diff --git a/crates/nu-std/tests/logger_tests/test_log_format_flag.nu b/crates/nu-std/tests/logger_tests/test_log_format_flag.nu index 5306daabbe..112f42dbea 100644 --- a/crates/nu-std/tests/logger_tests/test_log_format_flag.nu +++ b/crates/nu-std/tests/logger_tests/test_log_format_flag.nu @@ -1,5 +1,6 @@ use std * -use std log * +use std/log * +use std/assert use commons.nu * def run-command [ @@ -10,9 +11,9 @@ def run-command [ --short ] { if $short { - ^$nu.current-exe --no-config-file --commands $'use std; NU_LOG_LEVEL=($system_level) std log ($message_level) --format "($format)" --short "($message)"' + ^$nu.current-exe --no-config-file --commands $'use std; use std/log; NU_LOG_LEVEL=($system_level) log ($message_level) --format "($format)" --short "($message)"' } else { - ^$nu.current-exe --no-config-file --commands $'use std; NU_LOG_LEVEL=($system_level) std log ($message_level) --format "($format)" "($message)"' + ^$nu.current-exe --no-config-file --commands $'use std; use std/log; NU_LOG_LEVEL=($system_level) log ($message_level) --format "($format)" "($message)"' } | complete | get --ignore-errors stderr } 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 9aaa75c8f6..1a148efec0 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,6 @@ use std * -use std log * +use std/assert +use std/log * #[test] def env_log-ansi [] { diff --git a/crates/nu-std/tests/test_asserts.nu b/crates/nu-std/tests/test_asserts.nu index 2447dfda1e..bc748891ba 100644 --- a/crates/nu-std/tests/test_asserts.nu +++ b/crates/nu-std/tests/test_asserts.nu @@ -1,4 +1,5 @@ use std * +use std/assert #[test] def assert_basic [] { diff --git a/crates/nu-std/tests/test_core.nu b/crates/nu-std/tests/test_core.nu index 8fb36ae9f5..eca7cddd61 100644 --- a/crates/nu-std/tests/test_core.nu +++ b/crates/nu-std/tests/test_core.nu @@ -1,7 +1,7 @@ -use std assert +use std/assert #[test] def banner [] { - use std core + use std/core assert ((core banner | lines | length) == 15) } diff --git a/crates/nu-std/tests/test_dirs.nu b/crates/nu-std/tests/test_dirs.nu index 716ea59936..c3ceb772e1 100644 --- a/crates/nu-std/tests/test_dirs.nu +++ b/crates/nu-std/tests/test_dirs.nu @@ -1,5 +1,5 @@ -use std assert -use std log +use std/assert +use std/log # A couple of nuances to understand when testing module that exports environment: # Each 'use' for that module in the test script will execute the def --env block. @@ -47,7 +47,7 @@ def dirs_command [] { # must execute these uses for the UOT commands *after* the test and *not* just put them at top of test module. # the def --env gets messed up - use std dirs + use std/dirs # Stack: [BASE] assert equal [$c.base_path] $env.DIRS_LIST "list is just pwd after initialization" @@ -95,7 +95,7 @@ def dirs_next [] { cd $c.base_path assert equal $env.PWD $c.base_path "test setup" - use std dirs + use std/dirs cur_dir_check $c.base_path "use module test setup" dirs add $c.path_a $c.path_b @@ -116,7 +116,7 @@ def dirs_cd [] { # must set PWD *before* doing `use` that will run the def --env block in dirs module. cd $c.base_path - use std dirs + use std/dirs cur_dir_check $c.base_path "use module test setup" @@ -138,7 +138,7 @@ def dirs_cd [] { def dirs_goto_bug10696 [] { let $c = $in cd $c.base_path - use std dirs + use std/dirs dirs add $c.path_a cd $c.path_b @@ -152,7 +152,7 @@ def dirs_goto_bug10696 [] { def dirs_goto [] { let $c = $in cd $c.base_path - use std dirs + use std/dirs # check that goto can move *from* any position in the ring *to* any other position (correctly) diff --git a/crates/nu-std/tests/test_dt.nu b/crates/nu-std/tests/test_dt.nu index 72f608248c..28f3201839 100644 --- a/crates/nu-std/tests/test_dt.nu +++ b/crates/nu-std/tests/test_dt.nu @@ -1,5 +1,5 @@ -use std assert -use std dt * +use std/assert +use std/dt * #[test] def equal_times [] { diff --git a/crates/nu-std/tests/test_formats.nu b/crates/nu-std/tests/test_formats.nu index 59e7ddd94c..5fc1de2d01 100644 --- a/crates/nu-std/tests/test_formats.nu +++ b/crates/nu-std/tests/test_formats.nu @@ -1,4 +1,4 @@ -use std assert +use std/assert def test_data_multiline [] { let lines = [ @@ -19,7 +19,7 @@ def test_data_multiline [] { #[test] def from_ndjson_multiple_objects [] { - use std formats * + use std/formats * let result = test_data_multiline | from ndjson let expect = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] assert equal $result $expect "could not convert from NDJSON" @@ -27,7 +27,7 @@ def from_ndjson_multiple_objects [] { #[test] def from_ndjson_single_object [] { - use std formats * + use std/formats * let result = '{"a": 1}' | from ndjson let expect = [{a:1}] assert equal $result $expect "could not convert from NDJSON" @@ -35,13 +35,13 @@ def from_ndjson_single_object [] { #[test] def from_ndjson_invalid_object [] { - use std formats * + use std/formats * assert error { '{"a":1' | from ndjson } } #[test] def from_jsonl_multiple_objects [] { - use std formats * + use std/formats * let result = test_data_multiline | from jsonl let expect = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] assert equal $result $expect "could not convert from JSONL" @@ -49,7 +49,7 @@ def from_jsonl_multiple_objects [] { #[test] def from_jsonl_single_object [] { - use std formats * + use std/formats * let result = '{"a": 1}' | from jsonl let expect = [{a:1}] assert equal $result $expect "could not convert from JSONL" @@ -57,13 +57,13 @@ def from_jsonl_single_object [] { #[test] def from_jsonl_invalid_object [] { - use std formats * + use std/formats * assert error { '{"a":1' | from jsonl } } #[test] def to_ndjson_multiple_objects [] { - use std formats * + use std/formats * let result = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] | to ndjson | str trim let expect = test_data_multiline assert equal $result $expect "could not convert to NDJSON" @@ -71,7 +71,7 @@ def to_ndjson_multiple_objects [] { #[test] def to_ndjson_single_object [] { - use std formats * + use std/formats * let result = [{a:1}] | to ndjson | str trim let expect = "{\"a\":1}" assert equal $result $expect "could not convert to NDJSON" @@ -79,7 +79,7 @@ def to_ndjson_single_object [] { #[test] def to_jsonl_multiple_objects [] { - use std formats * + use std/formats * let result = [{a:1},{a:2},{a:3},{a:4},{a:5},{a:6}] | to jsonl | str trim let expect = test_data_multiline assert equal $result $expect "could not convert to JSONL" @@ -87,7 +87,7 @@ def to_jsonl_multiple_objects [] { #[test] def to_jsonl_single_object [] { - use std formats * + use std/formats * let result = [{a:1}] | to jsonl | str trim let expect = "{\"a\":1}" assert equal $result $expect "could not convert to JSONL" diff --git a/crates/nu-std/tests/test_help.nu b/crates/nu-std/tests/test_help.nu index b82e5072ef..07ea7c6e4c 100644 --- a/crates/nu-std/tests/test_help.nu +++ b/crates/nu-std/tests/test_help.nu @@ -1,5 +1,5 @@ -use std assert -use std help +use std/assert +use std/help #[test] def show_help_on_commands [] { diff --git a/crates/nu-std/tests/test_iter.nu b/crates/nu-std/tests/test_iter.nu index 7404d082de..2b768c3d9d 100644 --- a/crates/nu-std/tests/test_iter.nu +++ b/crates/nu-std/tests/test_iter.nu @@ -1,4 +1,5 @@ use std * +use std/assert #[test] def iter_find [] { diff --git a/crates/nu-std/tests/test_util.nu b/crates/nu-std/tests/test_lib.nu similarity index 74% rename from crates/nu-std/tests/test_util.nu rename to crates/nu-std/tests/test_lib.nu index ad7c435e47..1f1720de01 100644 --- a/crates/nu-std/tests/test_util.nu +++ b/crates/nu-std/tests/test_lib.nu @@ -1,8 +1,8 @@ -use std util +use std/lib #[test] def path_add [] { - use std assert + use std/assert let path_name = if "PATH" in $env { "PATH" } else { "Path" } @@ -11,19 +11,19 @@ def path_add [] { assert equal (get_path) [] - util path add "/foo/" + lib path add "/foo/" assert equal (get_path) (["/foo/"] | path expand) - util path add "/bar/" "/baz/" + lib path add "/bar/" "/baz/" assert equal (get_path) (["/bar/", "/baz/", "/foo/"] | path expand) load-env {$path_name: []} - util path add "foo" - util path add "bar" "baz" --append + lib path add "foo" + lib path add "bar" "baz" --append assert equal (get_path) (["foo", "bar", "baz"] | path expand) - assert equal (util path add "fooooo" --ret) (["fooooo", "foo", "bar", "baz"] | path expand) + assert equal (lib path add "fooooo" --ret) (["fooooo", "foo", "bar", "baz"] | path expand) assert equal (get_path) (["fooooo", "foo", "bar", "baz"] | path expand) load-env {$path_name: []} @@ -35,18 +35,18 @@ def path_add [] { android: "quux", } - util path add $target_paths + lib path add $target_paths assert equal (get_path) ([($target_paths | get $nu.os-info.name)] | path expand) load-env {$path_name: [$"(["/foo", "/bar"] | path expand | str join (char esep))"]} - util path add "~/foo" + lib path add "~/foo" assert equal (get_path) (["~/foo", "/foo", "/bar"] | path expand) } } #[test] def path_add_expand [] { - use std assert + use std/assert # random paths to avoid collision, especially if left dangling on failure let real_dir = $nu.temp-path | path join $"real-dir-(random chars)" @@ -63,7 +63,7 @@ def path_add_expand [] { with-env {$path_name: []} { def get_path [] { $env | get $path_name } - util path add $link_dir + lib path add $link_dir assert equal (get_path) ([$link_dir]) } @@ -72,12 +72,12 @@ def path_add_expand [] { #[test] def repeat_things [] { - use std assert - assert error { "foo" | util repeat -1 } + use std/assert + assert error { "foo" | lib repeat -1 } for x in ["foo", [1 2], {a: 1}] { - assert equal ($x | util repeat 0) [] - assert equal ($x | util repeat 1) [$x] - assert equal ($x | util repeat 2) [$x $x] + assert equal ($x | lib repeat 0) [] + assert equal ($x | lib repeat 1) [$x] + assert equal ($x | lib repeat 2) [$x $x] } } diff --git a/crates/nu-std/tests/test_setup_teardown.nu b/crates/nu-std/tests/test_setup_teardown.nu index 60168ab6f3..d19ba915fb 100644 --- a/crates/nu-std/tests/test_setup_teardown.nu +++ b/crates/nu-std/tests/test_setup_teardown.nu @@ -1,5 +1,5 @@ -use std log -use std assert +use std/log +use std/assert #[before-each] def before-each [] { diff --git a/crates/nu-std/tests/test_std.nu b/crates/nu-std/tests/test_std.nu new file mode 100644 index 0000000000..bfd6757d75 --- /dev/null +++ b/crates/nu-std/tests/test_std.nu @@ -0,0 +1,22 @@ +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_xml.nu b/crates/nu-std/tests/test_xml.nu index a74b6808e0..16cbb712bc 100644 --- a/crates/nu-std/tests/test_xml.nu +++ b/crates/nu-std/tests/test_xml.nu @@ -1,7 +1,5 @@ -use std xml xaccess -use std xml xupdate -use std xml xinsert -use std assert +use std/xml * +use std/assert #[before-each] def before-each [] { diff --git a/tests/repl/test_stdlib.rs b/tests/repl/test_stdlib.rs index f3e4af7f1a..b15a10dd22 100644 --- a/tests/repl/test_stdlib.rs +++ b/tests/repl/test_stdlib.rs @@ -7,5 +7,5 @@ fn not_loaded() -> TestResult { #[test] fn use_command() -> TestResult { - run_test_std("use std assert; assert true; print 'it works'", "it works") + run_test_std("use std/assert; assert true; print 'it works'", "it works") } diff --git a/tests/shell/environment/env.rs b/tests/shell/environment/env.rs index e07259a500..0d285409fb 100644 --- a/tests/shell/environment/env.rs +++ b/tests/shell/environment/env.rs @@ -224,10 +224,10 @@ fn std_log_env_vars_are_not_overridden() { ("NU_LOG_DATE_FORMAT".to_string(), "%Y".to_string()), ], r#" - use std + use std/log print -e $env.NU_LOG_FORMAT print -e $env.NU_LOG_DATE_FORMAT - std log error "err" + log error "err" "# ); assert_eq!(actual.err, "%MSG%\n%Y\nerr\n");