-
Notifications
You must be signed in to change notification settings - Fork 4
/
cli.gleam
76 lines (67 loc) 路 1.96 KB
/
cli.gleam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//// The Startest command line interface (CLI).
import argv
import bigben/clock
import gleam/option.{None, Some}
import gleam/result
import gleam/string
import gleam_community/ansi
import glint
import startest/config.{type Config}
import startest/context.{Context}
import startest/internal/gleam_toml
import startest/internal/runner
import startest/logger.{Logger}
/// Runs the Startest CLI.
pub fn run(config: Config) {
glint.new()
|> glint.with_name("gleam test --")
|> glint.pretty_help(glint.default_pretty_help())
|> glint.add(at: [], do: {
let package_name =
gleam_toml.read_name()
|> result.unwrap("my_project")
use <- glint.command_help(
string.concat([
"Runs the tests.",
"\n\n",
"Accepts zero or more filepath patterns as `ARGS` to filter down which tests are run. For example:",
"\n\n",
" - `",
ansi.cyan("gleam test -- example"),
"` will run the tests in all files that have \"example\" in their name",
"\n",
" - `",
ansi.cyan("gleam test -- test/" <> package_name <> "_test.gleam"),
"` will run just the tests in that specific file",
]),
)
use test_name_filter <- glint.flag(
glint.string_flag("test-name-filter")
|> glint.flag_default("")
|> glint.flag_help(
"Filter down tests just to those whose names match the filter",
),
)
glint.command(fn(_named_args, args, flags) {
let filters = args
let assert Ok(filter) = test_name_filter(flags)
let config =
config
|> config.with_filters(filters)
|> config.with_test_name_pattern(case filter {
"" -> None
filter -> Some(filter)
})
let clock = clock.new()
let ctx =
Context(
config,
clock: clock,
logger: Logger,
started_at: clock.now(clock),
)
runner.run_tests(ctx)
})
})
|> glint.run(argv.load().arguments)
}