Skip to content

Commit d19774c

Browse files
committed
refactor: move manifesting of lazy parse errors into the source, being discover.nu
1 parent 4211bea commit d19774c

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

nutest/discover.nu

+10-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,17 @@ export def test-suites [
2828
]: list<string> -> table<name: string, path: string, tests:table<name: string, type: string>> {
2929

3030
let suite_files = $in
31-
$suite_files
31+
let result = $suite_files
3232
| par-each { discover-suite $in }
3333
| filter-tests $matcher
34+
35+
# The following manifests the data to avoid laziness causing errors to be thrown in the wrong context
36+
# Some parser errors might be a `list<error>`, collecting will cause it to be thrown here
37+
$result | collect
38+
# Others are only apparent collecting the tests table
39+
$result | each { |suite| $suite.tests | collect }
40+
41+
$result
3442
}
3543

3644
def discover-suite [test_file: string]: nothing -> record<name: string, path: string, tests: table<name: string, type: string>> {
@@ -81,7 +89,7 @@ def parse-test [test: record<name: string, description: string>]: nothing -> rec
8189

8290
def filter-tests [
8391
matcher: string
84-
]: table<name: string, path: string, tests:table<name: string, type: string>> -> table<name: string, path: string, tests:table<name: string, type: string>> {
92+
]: table<name: string, path: string, tests:table<name: string, type: string>> -> table<name: string, path: string, tests: table<name: string, type: string>> {
8593

8694
let tests = $in
8795
$tests

nutest/mod.nu

-12
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ export def run-tests [
5555
| discover suite-files --matcher $suite
5656
| discover test-suites --matcher $test
5757

58-
$test_suites | manifest-errors
59-
6058
store create
6159

6260
do $display.run-start
@@ -78,16 +76,6 @@ export def run-tests [
7876
}
7977
}
8078

81-
# Manifest the data to avoid laziness causing errors to be thrown in the wrong context
82-
def manifest-errors []: any -> nothing {
83-
# This type should be: table<name: string, path: string, tests: table<name: string, type: string>>
84-
let suites = $in
85-
# Some parser errors might be a `list<error>`, collecting will cause it to be thrown here
86-
$suites | collect
87-
# Otherwise we do have a table that might have error instead of tests, so we and we need to try to collect
88-
$suites | each { |suite| $suite.tests | collect }
89-
}
90-
9179
def check-path []: string -> string {
9280
let path = $in
9381
if (not ($path | path exists)) {

0 commit comments

Comments
 (0)