diff --git a/crates/nu-utils/standard_library/test_dirs.nu b/crates/nu-utils/standard_library/test_dirs.nu index 60f29c9873..88faa2567a 100644 --- a/crates/nu-utils/standard_library/test_dirs.nu +++ b/crates/nu-utils/standard_library/test_dirs.nu @@ -1,19 +1,9 @@ -use std.nu +use std.nu assert -def "myassert" [ - predicate: bool - msg?:string = "..." - --verbose = false (-v) # enable to see successful tests -] { - if not $predicate { - let span = (metadata $predicate).span - error make {msg: $"Assertion failed checking ($msg)", - label: {text: "Condition not true" start: $span.start end: $span.end}} - } else { - if $verbose { - echo $"check succeeded: ($msg)" - } - } +def clean [path: path] { + cd $path + cd .. + rm -r $path } export def test_dirs_command [] { @@ -31,37 +21,52 @@ export def test_dirs_command [] { use std.nu "dirs drop" use std.nu "dirs show" - myassert (1 == ($env.DIRS_LIST | length)) "list is just pwd after initialization" - myassert ($base_path == $env.DIRS_LIST.0) "list is just pwd after initialization" + assert (1 == ($env.DIRS_LIST | length)) "list is just pwd after initialization" + assert ($base_path == $env.DIRS_LIST.0) "list is just pwd after initialization" dirs next - myassert ($base_path == $env.DIRS_LIST.0) "next wraps at end of list" + assert ($base_path == $env.DIRS_LIST.0) "next wraps at end of list" dirs prev - myassert ($base_path == $env.DIRS_LIST.0) "prev wraps at top of list" + assert ($base_path == $env.DIRS_LIST.0) "prev wraps at top of list" dirs add $path_b $path_a - myassert ($path_b == $env.PWD) "add changes PWD to first added dir" - myassert (3 == ($env.DIRS_LIST | length)) "add in fact adds to list" - myassert ($path_a == $env.DIRS_LIST.2) "add in fact adds to list" + assert ($path_b == $env.PWD) "add changes PWD to first added dir" + assert (3 == ($env.DIRS_LIST | length)) "add in fact adds to list" + assert ($path_a == $env.DIRS_LIST.2) "add in fact adds to list" dirs next 2 - myassert ($base_path == $env.PWD) "next wraps at end of list" + assert ($base_path == $env.PWD) "next wraps at end of list" dirs prev 1 - myassert ($path_a == $env.PWD) "prev wraps at start of list" + assert ($path_a == $env.PWD) "prev wraps at start of list" dirs drop - myassert (2 == ($env.DIRS_LIST | length)) "drop removes from list" - myassert ($base_path == $env.PWD) "drop changes PWD to next in list (after dropped element)" + assert (2 == ($env.DIRS_LIST | length)) "drop removes from list" + assert ($base_path == $env.PWD) "drop changes PWD to next in list (after dropped element)" - myassert ((dirs show) == [[active path]; [true $base_path] [false $path_b]]) "show table contains expected information" + assert ((dirs show) == [[active path]; [true $base_path] [false $path_b]]) "show table contains expected information" } catch { |error| - $error | debug - true + clean $base_path + + let error = ( + $error + | get debug + | str replace "{" "(" + | str replace "}" ")" + | parse 'GenericError("{msg}", "{text}", Some(Span ( start: {start}, end: {end} )), {rest})' + | reject rest + | get 0 + ) + error make { + msg: $error.msg + label: { + text: $error.text + start: ($error.start | into int) + end: ($error.end | into int) + } + } } - cd $base_path - cd .. - rm -r $base_path + try { clean $base_path } }