Commit Graph

59 Commits

Author SHA1 Message Date
Máté FARKAS
c3678764b4
stdlib test runner: implement setup and teardown commands to unit tests (#8776)
# Description

As in other testing frameworks, the `setup` runs before every test case,
and the `teardown` after that. A context can be created in `setup`,
which will be in the `$in` variable in the test cases, and in the
`teardown`. The `teardown` is called regardless of the test is passed,
skipped, or failed.

For example:

```nushell
use std.nu *

export def setup [] {
    log debug "Setup is running"
    {msg: "This is the context"}
}

export def teardown [] {
    log debug $"Teardown is running. Context: ($in)"
}

export def test_assert_pass [] {
    log debug $"Assert is running. Context: ($in)"
}

export def test_assert_skip [] {
    log debug $"Assert is running. Context: ($in)"
    assert skip
}

export def test_assert_fail_skipped_by_default [] {
    log debug $"Assert is running. Context: ($in)"
    assert false
}
```


![image](https://user-images.githubusercontent.com/282320/230466359-9908cc72-edbd-4150-9aff-d15fe42c0cc7.png)

# After Submitting

I'll update the documentation.

---------

Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>
2023-04-10 22:42:11 +02:00
Antoine Stevan
6d51e34d0a
stdlib: make helper modules available in std (#8841)
> **Note**
> waiting for the following to land
> - https://github.com/nushell/nushell/pull/8824 to avoid conflicts,
i'll add this to `CONTRIBUTING.md` once it's ready 👍

should close #8839 

# Description
this PR moves the `log` submodule of `std` to the top of the call stack,
making it available in the rest of the library as `log`.
i've added some comments around the `submodules` list in
`load_standard_library` to make it clear how it should work.
 
# User-Facing Changes
`log` and `assert` are now available in the rest of `std`.

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
-  `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting
```
$nothing
```
2023-04-10 13:32:33 -05:00
Antoine Stevan
d0a83fec69
stdlib: add completion to help commands (#8799)
> **Note**
> waiting for
> - https://github.com/nushell/nushell/pull/8770
> - #8815

# Description
this PR adds a very basic completion support to the `help`
implementations of the `std`.

# User-Facing Changes
completion on all the `std help ...` commands, based on the names in
`$nu.scope.`

# Tests + Formatting
-  `toolkit fmt`
-  `toolkit clippy`
-  `toolkit test`
-  `toolkit test stdlib`

# After Submitting
```
$nothing
```
2023-04-10 10:59:57 +12:00
JT
9e3d6c3bfd
Only add the std lib files once (#8830)
# Description

We were seeing duplicate entries for the std lib files, and this PR
addresses that. Each file should now only be added once.

Note: they are still parsed twice because it's hard to recover the
module from the output of `parse` but a bit of clever hacking in a
future PR might be able to do that.

# User-Facing Changes

_(List of all changes that impact the user experience here. This helps
us keep track of breaking changes.)_

# Tests + Formatting

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
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```

# 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-04-10 08:55:47 +12:00
Antoine Stevan
4a955d7e76
stdlib: refactor into a multi-module library (#8815) 2023-04-09 20:00:20 +03:00
Antoine Stevan
d128c0e02b
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
```
2023-04-08 07:35:16 -05:00
Michael Angerman
60e6ea5abd
remove nu_cli crate dependency from nu_std (#8807)
now nu_std only depends on nu_parser, nu_protocol and miette
and removes the nu_cli dependency

this enables developers moving forward to come along and implement their
own CLI's without having to pull in a redundant nu-cli which will not be
needed for them.

I did this by moving report_error into nu_protocol
which nu_std already has a dependency on anyway....



- `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
- `cargo run -- crates/nu-std/tests.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
2023-04-08 13:53:43 +02:00
Michael Angerman
5ec6edb9c5
add LICENSE to nu-std (#8803)
# Description

_(Thank you for improving Nushell. Please, check our [contributing
guide](../CONTRIBUTING.md) and talk to the core team before making major
changes.)_

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

# User-Facing Changes

_(List of all changes that impact the user experience here. This helps
us keep track of breaking changes.)_

# Tests + Formatting

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
- `cargo run -- crates/nu-std/tests.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```

# 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-04-07 13:39:21 -07:00
Antoine Stevan
5d8bedfbe4
stdlib: make the library a standalone crate (#8770)
# Description
as we now have a prelude thanks to #8627, i'd like to work on the
structure of the library 😋

and i think the first step is to make it a true standalone crate 😏

this PR
- moves all the library from `crates/nu-utils/standard_library/` to
`crates/nu-std/`
- moves the `rust` loading code from `src/run.rs` to
`crates/nu-std/src/lib.rs`
2023-04-07 22:12:27 +02:00