Commit Graph

16 Commits

Author SHA1 Message Date
Antoine Stevan
cb1eefd24a
FIX: expand all the base_paths in std::test_dirs (#8552)
Related to #8525.

# Description

this should close #8528.

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
```
$nothing
```

# After Submitting
```
$nothing
```
2023-03-22 09:50:01 +01:00
Máté FARKAS
77d33766f1
std lib: extend test runner capabilities (#8499)
I am implementing a nu plugin, and want to unit test that it works well.

# Basic usage (unchanged)


![image](https://user-images.githubusercontent.com/282320/225895139-f1ea0088-22e1-4778-b27e-c1868af48753.png)

# Select the folder to run tests within (subfolders included)


![image](https://user-images.githubusercontent.com/282320/225894283-4c6ac739-afde-44ef-bf7e-362d5118e83f.png)

# Select module to run tests within


![image](https://user-images.githubusercontent.com/282320/225894438-f39690db-955d-4d66-818f-17a179b00c66.png)

# Select test command to run


![image](https://user-images.githubusercontent.com/282320/225894534-edb15b9c-d3ef-4368-9108-2d220ef75dcf.png)

# Complex usage


![image](https://user-images.githubusercontent.com/282320/225894827-03f2e937-3984-4b33-b206-c155c723feac.png)

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-03-20 18:48:48 +01:00
Máté FARKAS
7d963776a0
stdlib: Implement common assert commands (#8515)
Implement common assert commands with tests.
Fixes #8419.

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-03-20 08:57:28 -05:00
Antoine Stevan
d1309a36b2
standard library: fix the readme (#8526)
# Description
as we now want to put all the library in `std.nu` alone, this PR removes
the mentions to "creating a separate submodule from `std.nu`" from the
`README` of the standard library and adds a few clarifications about the
structure of the library.

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
```
$nothing
```

# After Submitting
```
$nothing
```
2023-03-20 17:05:49 +13:00
Antoine Stevan
f9cf1d943c
standard library: use the standard assert and fix test output (#8509)
# Description
## in the `test_dirs` test module
- use the `std assert` function in the `test_dirs` module instead of
`myassert`
- refactor the "test cleaning" in the `clean` command
- allows to clean the tests and then throw a real error in the `catch`
block in case there is an error
- the test still "try"s to `clean` the test directory after the `catch`,
like in a "finally" block
- parse the `catch` error and `error make` a proper one instead of
`debug`ging it => because the `catch` will be triggered as soon as one
error occurs, there will always only be a single error in the tests, so
this does not change the behaviour of failing `dirs` tests!

> **Note**
> i'm not particularly happy with the parsing stage in the `catch`
block.
> however that's the simplest i found to both keep the `try` / `catch`
construct that allows to clean the test directory and have a proper
error at the same time!

## in the global `tests` module
- use `print` instead of `echo` to make sure the log statements show up
during the tests

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
```bash
nu crates/nu-utils/standard_library/tests.nu
```
passes but now with
- proper log statements
- proper error when a `dirs` error occurs => try with `sd 'assert \(1'
"assert (10" crates/nu-utils/standard_library/test_dirs.nu` 😉

# After Submitting
```
$nothing
```
2023-03-18 09:23:41 -05:00
Máté FARKAS
10a42de64f
standard library: add log commands (#8448)
# Description

```nushell
log critical "this is a critical message"
log error "this is an error message"
log warning "this is a warning message"
log info "this is an info message"
log debug "this is a debug message"
```


![image](https://user-images.githubusercontent.com/282320/225071852-1ddf0e87-d12b-452d-9598-5122df7123ab.png)

# Tests + Formatting

Tests are written. To run automatically, #8443 needs to be merged before
or after this PR.

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-03-18 08:19:54 -05:00
Máté FARKAS
3f224db990
Make assert eq, assert ne consistent with ==, != operators (#8473)
fixes #8418

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-03-18 08:59:27 +13:00
Antoine Stevan
14bf0b000e
standard library: fix the tests for the new closure parsing of 0.77.2 (#8504)
# Description
as closures now need to have explicit parameters, this PR adds the empty
`||` to the two closure of the `std match` test.

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
```
nu crates/nu-utils/standard_library/tests.nu
```
does not give the following anymore
```
Error: nu::parser::closure_missing_pipe

  × Missing || inside closure
    ╭─[/home/amtoine/.local/share/git/store/github.com/amtoine/nushell/crates/nu-utils/standard_library/test_std.nu:29:1]
 29 │     let branches = {
 30 │         1: { -1 }
    ·            ───┬──
    ·               ╰── Parsing as a closure, but || is missing
 31 │         2: { -2 }
    ╰────
  help: Try add || to the beginning of closure

Error: nu:🐚:only_supports_this_input_type

  × Input type not supported.
    ╭─[/home/amtoine/.local/share/git/store/github.com/amtoine/nushell/crates/nu-utils/standard_library/tests.nu:7:1]
  7 │             nu -c $'use ($test_file) *; $nu.scope.commands | to nuon'
  8 │             | from nuon
    ·               ────┬────
    ·                   ╰── input type: nothing
  9 │             | where module_name == $module_name
    ·               ──┬──
    ·                 ╰── only list, binary, raw data or range input data is supported
 10 │             | where ($it.name | str starts-with "test_")
    ╰────
```

# After Submitting
```
$nothing
```
2023-03-18 08:52:08 +13:00
Antoine Stevan
bb8949f2b2
REFACTOR: put all the standard library in std.nu (#8489)
> **Warning**
> this PR is the result of a demand from the core team, to have the
simplest structure for the standard library, at least for now 👍

# Description
this PR mainly
- moved the `dirs.nu` module to the end of `std.nu`
- fixed the imports in `test_dirs.nu`

# User-Facing Changes
```
$nothing
```

# Tests + Formatting
with the new runner from #8443, we get as expected 👌 
```
>_ nu crates/nu-utils/standard_library/tests.nu
INFO  Run tests in test_dirs
DEBUG Run test test_dirs/test_dirs_command
INFO  Run tests in test_std
DEBUG Run test test_std/test_assert
DEBUG Run test test_std/test_match
DEBUG Run test test_std/test_path_add
```

# After Submitting
```
$nothing
```
2023-03-17 12:30:35 -05:00
Máté FARKAS
d74a260883
stdlib: add test discovery, extract test files (#8443)
# Description

Was original asked here:
https://github.com/nushell/nushell/pull/8405#issuecomment-1465062652
Make it easier to extend standard library with submodules.
(For a new submodule called `xx.nu` the tests can be written in
`test_xx.nu`).
Test discovery is implemented.

# User-Facing Changes

There are no user-facing changes.

# Tests + Formatting

Tests are updated.
There is no `nufmt` now.

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-03-16 13:23:29 -05:00
Antoine Stevan
d3be5ec750
DOC: make the README of the standard library clearer (#8465)
Should close #8444.

# Description
as asked by @presidento, i've used a generic command to run the tests.

i've also transformed the "a concrete example" sections into quote
blocks to make them stand out less.
not sure about that one, please tell me what you think 😋 

i think a small example is always helpfull, maybe some work has to be
done to make it better 💪

# User-Facing Changes
hopefully a slightly clearer README for the standard library

# Tests + Formatting
```
$nothing
```

# After Submitting
```
$nothing
```
2023-03-15 20:13:09 -07:00
Máté FARKAS
12652f897a
std.nu: Rewrite assert method (#8405)
It is a common pattern to add message to assert.
Also the error message was not so helpful. (See the difference in the
documentation)

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-03-15 18:19:38 +01:00
Bob Hyman
2e01bf9cba
add dirs command to std lib (#8368)
# Description

Prototype replacement for `enter`, `n`, `p`, `exit` built-ins
implemented as scripts in standard library.
MVP-level capabilities (rough hack), for feedback please. Not intended
to merge and ship as is.

_(Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.)_

# User-Facing Changes
New command in standard library

```nushell
〉use ~/src/rust/nushell/crates/nu-utils/standard_library/dirs.nu
---------------------------------------------- /home/bobhy ----------------------------------------------
〉help dirs
module dirs.nu -- maintain list of remembered directories + navigate them

todo:
* expand relative to absolute paths (or relative to some prefix?)
* what if user does `cd` by hand?

Module: dirs

Exported commands:
  add (dirs add), drop, next (dirs next), prev (dirs prev), show (dirs show)

This module exports environment.
---------------------------------------------- /home/bobhy ----------------------------------------------
〉dirs add ~/src/rust/nushell /etc ~/.cargo
-------------------------------------- /home/bobhy/src/rust/nushell --------------------------------------
〉dirs next 2
------------------------------------------- /home/bobhy/.cargo -------------------------------------------
〉dirs show
╭───┬─────────┬────────────────────╮
│ # │ current │        path        │
├───┼─────────┼────────────────────┤
│ 0 │         │ /home/bobhy        │
│ 1 │         │ ~/src/rust/nushell │
│ 2 │         │ /etc               │
│ 3 │ ==>     │ ~/.cargo           │
╰───┴─────────┴────────────────────╯
------------------------------------------- /home/bobhy/.cargo -------------------------------------------
〉dirs drop
---------------------------------------------- /home/bobhy ----------------------------------------------
〉dirs show
╭───┬─────────┬────────────────────╮
│ # │ current │        path        │
├───┼─────────┼────────────────────┤
│ 0 │ ==>     │ /home/bobhy        │
│ 1 │         │ ~/src/rust/nushell │
│ 2 │         │ /etc               │
╰───┴─────────┴────────────────────╯
---------------------------------------------- /home/bobhy ----------------------------------------------
〉
```
# Tests + Formatting

Haven't even looked at stdlib `tests.nu` yet.

Other todos:
* address module todos.
* integrate into std lib, rather than as standalone module. Somehow
arrange for `use .../standard_library/std.nu` to load this module
without having to put all the source in `std.nu`?
*  Maybe command should be `std dirs ...`?   
* what else do `enter` and `exit` do that this should do? Then deprecate
those commands.

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-11 16:31:09 -06:00
Antoine Stevan
6af59cb0ea
FEATURE: add a path add to the standard library (#8303)
# Description
this PR adds the `path add` command to
`crates/nu-utils/standard_library/std.nu`
- this comes from frequent questions over on the discord server, about
how to add directories to the `PATH`
- this is greatly inspired from the [original
`path-add`](https://discord.com/channels/601130461678272522/615253963645911060/1081206660816699402)
from @melMass
- allows to prepend and append a variable number of directories to the
`PATH`
- i've added a description with an example
- i've added tests in `crates/nu-utils/standard_library/tests.nu` that
hopefully covers all the features

# User-Facing Changes
`path add` can now be used from `std.nu`

# Tests + Formatting
the tests pass with
```bash
nu crates/nu-utils/standard_library/tests.nu
```

# After Submitting
```bash
$nothing
```
2023-03-07 17:06:14 -06:00
Antoine Stevan
b864a455f2
DOC: add a README to the standard library (#8304)
# Description
this PR a `README` to the standard library in
`crates/nu-utils/standard_library/` 👍

> **Note**
> you can have a look at what the `README` looks like
[here](https://github.com/amtoine/nushell/blob/doc/add-a-readme-to-the-standard-library/crates/nu-utils/standard_library/README.md#--welcome-to-the-standard-library-of-nushell--)

# User-Facing Changes
the user can now access some documentation about the standard library. 

# Tests + Formatting
```
$nothing
```

# After Submitting
```
$nothing
```
2023-03-04 08:30:36 -06:00
Antoine Stevan
2ccbefe01e
REFACTOR: move the standard library to a less-confusing place (#8265)
# Description
we've discussed a bit about the location of the standard library in the
#standard-library channel of the discord server => **the previous
location, `crates/nu-utils/src/sample_config/`, was a bit confusing**
- is `std.nu` a config file, just as `default_config.nu` or
`default_env.nu`?
- what is this `tests.nu` file inside the `sample_config/`?

in this PR, i propose moving the standard library to
`crates/nu-utils/standard_library/` for a few reasons:
- `std.nu` is not a config file, so it should not be next to config
files in a `sample_config/` directory
- `tests.nu` is confusing if mixed with other unrelated files
- `crates/nu-utils/` appears to be a good place for the standard library
as it is meant to be a tool for `nushell`
- i thought it would be strange to have `std.nu` inside
`crates/nu-utils/src/` as this directory is generally filled with `rust`
files, right?

these are the reasons why i choose to propose
`crates/nu-utils/standard_library/` 😋

# User-Facing Changes
the standard library is now used with
```bash
use crates/nu-utils/standard_library/std.nu
```
and the tests are run with
```bash
nu crates/nu-utils/standard_library/tests.nu
```

# Tests + Formatting
```bash
$nothing
```

# After Submitting
```bash
$nothing
```
2023-03-01 16:40:50 -06:00