Skip to content

Commit 507ef22

Browse files
authored
Replace usages of use std (nushell#1814)
1 parent 8464123 commit 507ef22

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

book/dataframes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ $df_0 | polars schema
9494
To output more statistically correct timings, let's load and use the `std bench` command.
9595

9696
```nu
97-
use std bench
97+
use std/bench
9898
```
9999

100100
We are going to group the data by year, and sum the column `geo_count`.

book/testing.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ Nushell provides a set of "assertion" commands in the standard library.
66
One could use built-in equality / order tests such as `==` or `<=` or more complex commands and throw errors manually when an expected condition fails, but using what the standard library has to offer is arguably easier!
77

88
In the following, it will be assumed that the `std assert` module has been imported inside the current scope
9+
910
```nu
10-
use std assert
11+
use std/assert
1112
```
1213

1314
The foundation for every assertion is the `std assert` command. If the condition is not true, it makes an error.
1415

1516
```nu
1617
assert (1 == 2)
1718
```
19+
1820
```
1921
Error:
2022
× Assertion failed.
@@ -31,6 +33,7 @@ Optionally, a message can be set to show the intention of the assert command, wh
3133
let a = 0
3234
assert ($a == 19) $"The lockout code is wrong, received: ($a)"
3335
```
36+
3437
```
3538
Error:
3639
× The lockout code is wrong, received: 13
@@ -51,6 +54,7 @@ let a = "foo"
5154
let b = "bar"
5255
assert ($b | str contains $a)
5356
```
57+
5458
```
5559
Error: × Assertion failed.
5660
╭─[entry #5:3:8]
@@ -68,6 +72,7 @@ let a = "a needle"
6872
let b = "haystack"
6973
assert str contains $b $a
7074
```
75+
7176
```
7277
Error: × Assertion failed.
7378
╭─[entry #7:3:21]
@@ -96,6 +101,7 @@ Then you'll have your detailed custom error message:
96101
let $a = 13
97102
assert even $a
98103
```
104+
99105
```
100106
Error:
101107
× Assertion failed.
@@ -110,28 +116,29 @@ Error:
110116

111117
Now that we are able to write tests by calling commands from `std assert`, it would be great to be able to run them and see our tests fail when there is an issue and pass when everything is correct :)
112118

113-
114119
### Nupm Package
115120

116121
In this first case, we will assume that the code you are trying to test is part of a [Nupm] package.
117122

118123
In that case, it is as easy as following the following steps
124+
119125
- create a `tests/` directory next to the `nupm.nuon` package file of your package
120126
- make the `tests/` directory a valid module by adding a `mod.nu` file into it
121127
- write commands inside `tests/`
122128
- call `nupm test`
123129

124130
The convention is that any command fully exported from the `tests` module will be run as a test, e.g.
131+
125132
- `export def some-test` in `tests/mod.nu` will run
126133
- `def just-an-internal-cmd` in `tests/mod.nu` will NOT run
127134
- `export def another-test` in `tests/spam.nu` will run if and only if there is something like `export use spam.nu *` in `tests/mod.nu`
128135

129-
130136
### Standalone Tests
131137

132138
If your Nushell script or module is not part of a [Nupm] package, the simplest way is to write tests in standalone scripts and then call them, either from a `Makefile` or in a CI:
133139

134140
Let's say we have a simple `math.nu` module which contains a simple Fibonacci command:
141+
135142
```nu
136143
# `fib n` is the n-th Fibonacci number
137144
export def fib [n: int] [ nothing -> int ] {
@@ -144,10 +151,12 @@ export def fib [n: int] [ nothing -> int ] {
144151
(fib ($n - 1)) + (fib ($n - 2))
145152
}
146153
```
154+
147155
then a test script called `tests.nu` could look like
156+
148157
```nu
149158
use math.nu fib
150-
use std assert
159+
use std/assert
151160
152161
for t in [
153162
[input, expected];
@@ -163,6 +172,7 @@ for t in [
163172
assert equal (fib $t.input) $t.expected
164173
}
165174
```
175+
166176
and be invoked as `nu tests.nu`
167177

168178
### Basic Test Framework
@@ -172,7 +182,7 @@ them dynamically without requiring a [Nupm] package. The following uses `scope c
172182
second instance of Nushell to run the generated list of tests.
173183

174184
```nu
175-
use std assert
185+
use std/assert
176186
177187
source fib.nu
178188

cookbook/jq_v_nushell.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ help commands | where command_type == "custom"
637637

638638
```nu
639639
# toolbox.nu
640-
use std assert
640+
use std/assert
641641
642642
# A command for cherry-picking values from a record key recursively
643643
export def cherry-pick [

cookbook/pattern_matching.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Also note that we have to capture the `$in` variable on the first statement of t
9494
With this implementation we can check that the command works as expected:
9595

9696
```nu
97-
use std assert
97+
use std/assert
9898
assert equal ("foo" | str append "/") "foo/"
9999
assert equal (["foo", "bar", "baz"] | str append "/") ["foo/", "bar/", "baz/"]
100100
```

snippets/book/std_log.nu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std log
1+
use std/log
22

33
def main [] {
44
log debug "Debug message"

0 commit comments

Comments
 (0)