Skip to content

Commit e772d1b

Browse files
committed
Updated to conform better with style guide, nupm testing, as well as suggestions from @fdncred
1 parent b5b1ba3 commit e772d1b

File tree

1 file changed

+30
-36
lines changed

1 file changed

+30
-36
lines changed

book/testing.md

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -177,47 +177,41 @@ use std assert
177177
source fib.nu
178178
179179
def main [] {
180-
print "Running tests..."
181-
182-
let test_commands = (
183-
scope commands
184-
# Exclude all in-built commands
185-
| where ($it.type == "custom")
186-
# Include all commands starting with "test_"
187-
| where ($it.name | str starts-with "test_")
188-
# Exclude commands marked as "ignored" in the description
189-
| where not ($it.description | str starts-with "ignore")
190-
# Get the name of the test command
191-
| get name
192-
# Prefix each test command with a command to print the test name
193-
| each { |test| [$"print 'Running test: ($test)'", $test] } | flatten
194-
# Concatenate into a command list
195-
| str join "; "
196-
)
197-
198-
nu --commands $"source ($env.CURRENT_FILE); ($tests)"
199-
print "Tests completed successfully"
180+
print "Running tests..."
181+
182+
let test_commands = (
183+
scope commands
184+
| where ($it.type == "custom")
185+
and ($it.name | str starts-with "test ")
186+
and not ($it.description | str starts-with "ignore")
187+
| get name
188+
| each { |test| [$"print 'Running test: ($test)'", $test] } | flatten
189+
| str join "; "
190+
)
191+
192+
nu --commands $"source ($env.CURRENT_FILE); ($test_commands)"
193+
print "Tests completed successfully"
200194
}
201195
202-
def test_fib [] {
203-
for t in [
204-
[input, expected];
205-
[0, 0],
206-
[1, 1],
207-
[2, 1],
208-
[3, 2],
209-
[4, 3],
210-
[5, 5],
211-
[6, 8],
212-
[7, 13]
213-
] {
214-
assert equal (fib $t.input) $t.expected
215-
}
196+
def "test fib" [] {
197+
for t in [
198+
[input, expected];
199+
[0, 0],
200+
[1, 1],
201+
[2, 1],
202+
[3, 2],
203+
[4, 3],
204+
[5, 5],
205+
[6, 8],
206+
[7, 13]
207+
] {
208+
assert equal (fib $t.input) $t.expected
209+
}
216210
}
217211
218212
# ignore
219-
def test_fib_ignored_test [] {
220-
print "This test will not be executed"
213+
def "test show-ignored-test" [] {
214+
print "This test will not be executed"
221215
}
222216
```
223217

0 commit comments

Comments
 (0)