-
Notifications
You must be signed in to change notification settings - Fork 4
/
startest.gleam
51 lines (45 loc) 路 1.62 KB
/
startest.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
import gleam/option.{None}
import gleam/regex
import startest/cli
import startest/config.{type Config, Config}
import startest/reporters/default as default_reporter
import startest/test_case.{type Test, Test}
import startest/test_tree.{type TestTree, Suite}
/// Defines a new test suite with the given name.
///
/// A suite is a way of grouping related tests together.
///
/// `describe`s may also be nested in other `describe`s to form a hierarchy of tests.
pub fn describe(name: String, suite: List(TestTree)) -> TestTree {
Suite(name, suite)
}
/// Defines a test with the given name.
pub fn it(name: String, body: fn() -> Nil) -> TestTree {
Test(name, body, False)
|> test_tree.Test
}
/// Skips a test defined using `it`.
///
/// This can be used to skip running certain tests, but without deleting the code.
/// For instance, you might want to do this if a test is flaky and you want to stop
/// running it temporarily until it can be fixed.
pub fn xit(name: String, _body: fn() -> Nil) -> TestTree {
Test(name, fn() { Nil }, True)
|> test_tree.Test
}
/// Runs Startest with the provided list of tests.
pub fn run(config: Config) {
cli.run(config)
}
/// Returns the default Startest config.
pub fn default_config() -> Config {
let assert Ok(discover_describe_tests_pattern) = regex.from_string("_tests$")
let assert Ok(discover_standalone_tests_pattern) = regex.from_string("_test$")
Config(
reporters: [default_reporter.new()],
discover_describe_tests_pattern: discover_describe_tests_pattern,
discover_standalone_tests_pattern: discover_standalone_tests_pattern,
filters: [],
test_name_pattern: None,
)
}