Skip to content

Commit 04fb935

Browse files
committed
feat: warn when a test file fails to parse
1 parent b8d11fe commit 04fb935

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/unitest/internal/discover.gleam

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import glance
22
import gleam/bit_array
3+
import gleam/io
34
import gleam/list
45
import gleam/result
56
import gleam/string
@@ -61,8 +62,18 @@ fn discover_tests_in_file(path: String, base_path: String) -> List(Test) {
6162

6263
case simplifile.read(path) {
6364
Error(_) -> []
64-
Ok(contents) ->
65-
parse_module(contents)
65+
Ok(contents) -> {
66+
let parsed = parse_module(contents)
67+
case parsed {
68+
Ok(_) -> Nil
69+
Error(_) -> {
70+
io.println_error(
71+
"Warning: could not parse " <> path <> ", skipping its tests",
72+
)
73+
}
74+
}
75+
76+
parsed
6677
|> result.unwrap([])
6778
|> list.map(fn(pt) {
6879
let start_line = byte_offset_to_line(contents, pt.byte_span.start)
@@ -75,6 +86,7 @@ fn discover_tests_in_file(path: String, base_path: String) -> List(Test) {
7586
line_span: LineSpan(start_line, end_line),
7687
)
7788
})
89+
}
7890
}
7991
}
8092

0 commit comments

Comments
 (0)