mirror of
https://github.com/nushell/nushell
synced 2024-11-14 00:47:09 +00:00
stdlib: use the loaded library in tests and update README
(#8811)
Should close #8809. # Description this PR uses the automatically loaded library from the tests by replacing `use std.nu ...` with `use std ...`. the `README` has been updated by - removing the very deprencated "concrete examples" - fixing the `use std` and the "run the tests" sections the `README` can be previewed [here](https://github.com/amtoine/nushell/blob/refactor/stdlib/use-std-in-tests-and-update-readme/crates/nu-std/README.md) 👍 # User-Facing Changes ``` $nothing ``` # Tests + Formatting - 🟢 `toolkit test stdlib` # After Submitting ``` $nothing ```
This commit is contained in:
parent
60e6ea5abd
commit
d128c0e02b
7 changed files with 23 additions and 61 deletions
|
@ -14,42 +14,9 @@ in order to "import" the standard library to either the interactive [*REPL*][REP
|
||||||
`nushell` or inside some `.nu` script, you might want to use the
|
`nushell` or inside some `.nu` script, you might want to use the
|
||||||
[`use`](https://nushell.sh/commands/docs/use.html) command!
|
[`use`](https://nushell.sh/commands/docs/use.html) command!
|
||||||
```bash
|
```bash
|
||||||
use /path/to/standard_library/std.nu
|
use std
|
||||||
```
|
```
|
||||||
|
|
||||||
> ### :mag: a concrete example
|
|
||||||
> - my name is @amtoine and i use the `ghq` tool to manage `git` projects
|
|
||||||
> > **Note**
|
|
||||||
> > `ghq` stores any repository inside `$env.GHQ_ROOT` under `<host>/<owner>/<repo>/`
|
|
||||||
> - the path to my local fork of `nushell` is then defined as
|
|
||||||
> ```bash
|
|
||||||
> let-env NUSHELL_REPO = ($env.GHQ_ROOT | path join "github.com" "amtoine" "nushell")
|
|
||||||
> ```
|
|
||||||
> - and the full path to the standard library is defined as
|
|
||||||
> ```bash
|
|
||||||
> let-env STD_LIB = ($env.NUSHELL_REPO | path join "crates" "nu-utils" "standard_library")
|
|
||||||
> ```
|
|
||||||
> > see the content of `$env.STD_LIB` :yum:
|
|
||||||
> > ```bash
|
|
||||||
> > >_ ls $env.STD_LIB | get name | str replace $env.STD_LIB "" | str trim -l -c "/"
|
|
||||||
> > ╭───┬───────────╮
|
|
||||||
> > │ 0 │ README.md │
|
|
||||||
> > │ 1 │ std.nu │
|
|
||||||
> > │ 2 │ tests.nu │
|
|
||||||
> > ╰───┴───────────╯
|
|
||||||
> > ```
|
|
||||||
> - finally we can `use` the standard library and have access to the commands it exposes :thumbsup:
|
|
||||||
> ```bash
|
|
||||||
> >_ use std.nu
|
|
||||||
> >_ help std
|
|
||||||
> Module: std
|
|
||||||
>
|
|
||||||
> Exported commands:
|
|
||||||
> assert (std assert), assert eq (std assert eq), assert ne (std assert ne), match (std match)
|
|
||||||
>
|
|
||||||
> This module does not export environment.
|
|
||||||
> ```
|
|
||||||
|
|
||||||
## :pencil2: contribute to the standard library
|
## :pencil2: contribute to the standard library
|
||||||
- all the commands of the standard_library are located in [`std.nu`](std.nu)
|
- all the commands of the standard_library are located in [`std.nu`](std.nu)
|
||||||
- the tests are located in files that have a name starting with "test_", e.g. [`test_std.nu`](test_std.nu)
|
- the tests are located in files that have a name starting with "test_", e.g. [`test_std.nu`](test_std.nu)
|
||||||
|
@ -64,13 +31,8 @@ use /path/to/standard_library/std.nu
|
||||||
### :test_tube: run the tests
|
### :test_tube: run the tests
|
||||||
the following call should return no errors
|
the following call should return no errors
|
||||||
```bash
|
```bash
|
||||||
NU_LOG_LEVEL=DEBUG nu /path/to/standard_library/tests.nu
|
NU_LOG_LEVEL=DEBUG cargo run -- crates/nu-std/tests.nu
|
||||||
```
|
```
|
||||||
|
|
||||||
> #### :mag: a concrete example
|
> **Warning**
|
||||||
> with `STD_LIB` defined as in the example above
|
> the `cargo run --` part of this command is important to ensure the version of `nushell` and the version of the library are the same.
|
||||||
> ```bash
|
|
||||||
> NU_LOG_LEVEL=DEBUG nu ($env.STD_LIB | path join "tests.nu")
|
|
||||||
> ```
|
|
||||||
|
|
||||||
[REPL]: https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std.nu *
|
use std *
|
||||||
|
|
||||||
export def test_assert [] {
|
export def test_assert [] {
|
||||||
assert true
|
assert true
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std.nu "assert length"
|
use std "assert length"
|
||||||
use std.nu "assert equal"
|
use std "assert equal"
|
||||||
|
|
||||||
def clean [path: path] {
|
def clean [path: path] {
|
||||||
cd $path
|
cd $path
|
||||||
|
@ -17,11 +17,11 @@ export def test_dirs_command [] {
|
||||||
mkdir $base_path $path_a $path_b
|
mkdir $base_path $path_a $path_b
|
||||||
|
|
||||||
cd $base_path
|
cd $base_path
|
||||||
use std.nu "dirs next"
|
use std "dirs next"
|
||||||
use std.nu "dirs prev"
|
use std "dirs prev"
|
||||||
use std.nu "dirs add"
|
use std "dirs add"
|
||||||
use std.nu "dirs drop"
|
use std "dirs drop"
|
||||||
use std.nu "dirs show"
|
use std "dirs show"
|
||||||
|
|
||||||
assert length $env.DIRS_LIST 1 "list is just pwd after initialization"
|
assert length $env.DIRS_LIST 1 "list is just pwd after initialization"
|
||||||
assert equal $base_path $env.DIRS_LIST.0 "list is just pwd after initialization"
|
assert equal $base_path $env.DIRS_LIST.0 "list is just pwd after initialization"
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use std.nu *
|
use std *
|
||||||
|
|
||||||
def run [system_level, message_level] {
|
def run [system_level, message_level] {
|
||||||
cd $env.FILE_PWD
|
cd $env.FILE_PWD
|
||||||
do {
|
do {
|
||||||
nu -c $'use std.nu; NU_LOG_LEVEL=($system_level) std log ($message_level) "test message"'
|
nu -c $'use std; NU_LOG_LEVEL=($system_level) std log ($message_level) "test message"'
|
||||||
} | complete | get -i stderr
|
} | complete | get -i stderr
|
||||||
}
|
}
|
||||||
def "assert no message" [system_level, message_level] {
|
def "assert no message" [system_level, message_level] {
|
||||||
|
@ -43,4 +43,4 @@ export def example [] {
|
||||||
log warning "Warning message"
|
log warning "Warning message"
|
||||||
log error "Error message"
|
log error "Error message"
|
||||||
log critical "Critical message"
|
log critical "Critical message"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std.nu
|
use std
|
||||||
|
|
||||||
export def test_path_add [] {
|
export def test_path_add [] {
|
||||||
use std.nu "assert equal"
|
use std "assert equal"
|
||||||
|
|
||||||
with-env [PATH []] {
|
with-env [PATH []] {
|
||||||
assert equal $env.PATH []
|
assert equal $env.PATH []
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std.nu "xaccess"
|
use std "xaccess"
|
||||||
use std.nu "xupdate"
|
use std "xupdate"
|
||||||
use std.nu "xinsert"
|
use std "xinsert"
|
||||||
use std.nu "assert equal"
|
use std "assert equal"
|
||||||
|
|
||||||
export def test_xml_xaccess [] {
|
export def test_xml_xaccess [] {
|
||||||
let sample_xml = ('<a><b><c a="b"></c></b><c></c><d><e>z</e><e>x</e></d></a>' | from xml)
|
let sample_xml = ('<a><b><c a="b"></c></b><c></c><d><e>z</e><e>x</e></d></a>' | from xml)
|
||||||
|
@ -27,4 +27,4 @@ export def test_xml_xinsert [] {
|
||||||
assert equal ($sample_xml | xinsert [a] {tag: b attributes:{} content: []}) ('<a><b><c a="b"></c></b><c></c><d><e>z</e><e>x</e></d><b></b></a>' | from xml)
|
assert equal ($sample_xml | xinsert [a] {tag: b attributes:{} content: []}) ('<a><b><c a="b"></c></b><c></c><d><e>z</e><e>x</e></d><b></b></a>' | from xml)
|
||||||
assert equal ($sample_xml | xinsert [a d *] {tag: null attributes: null content: 'n'} | to xml) '<a><b><c a="b"></c></b><c></c><d><e>zn</e><e>xn</e></d></a>'
|
assert equal ($sample_xml | xinsert [a d *] {tag: null attributes: null content: 'n'} | to xml) '<a><b><c a="b"></c></b><c></c><d><e>zn</e><e>xn</e></d></a>'
|
||||||
assert equal ($sample_xml | xinsert [a *] {tag: null attributes: null content: 'n'}) ('<a><b><c a="b"></c>n</b><c>n</c><d><e>z</e><e>x</e>n</d></a>' | from xml)
|
assert equal ($sample_xml | xinsert [a *] {tag: null attributes: null content: 'n'}) ('<a><b><c a="b"></c>n</b><c>n</c><d><e>z</e><e>x</e>n</d></a>' | from xml)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std.nu *
|
use std *
|
||||||
|
|
||||||
# show a test record in a pretty way
|
# show a test record in a pretty way
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in a new issue