]> git.lizzy.rs Git - rust.git/blob - library/test/src/options.rs
Rollup merge of #103851 - viandoxdev:103816_bootstrap_fix_json_doc, r=jyn514
[rust.git] / library / test / src / options.rs
1 //! Enums denoting options for test execution.
2
3 /// Number of times to run a benchmarked function
4 #[derive(Clone, PartialEq, Eq)]
5 pub enum BenchMode {
6     Auto,
7     Single,
8 }
9
10 /// Whether test is expected to panic or not
11 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
12 pub enum ShouldPanic {
13     No,
14     Yes,
15     YesWithMessage(&'static str),
16 }
17
18 /// Whether should console output be colored or not
19 #[derive(Copy, Clone, Debug)]
20 pub enum ColorConfig {
21     AutoColor,
22     AlwaysColor,
23     NeverColor,
24 }
25
26 /// Format of the test results output
27 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
28 pub enum OutputFormat {
29     /// Verbose output
30     Pretty,
31     /// Quiet output
32     Terse,
33     /// JSON output
34     Json,
35     /// JUnit output
36     Junit,
37 }
38
39 /// Whether ignored test should be run or not
40 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
41 pub enum RunIgnored {
42     Yes,
43     No,
44     /// Run only ignored tests
45     Only,
46 }
47
48 #[derive(Clone, Copy)]
49 pub enum RunStrategy {
50     /// Runs the test in the current process, and sends the result back over the
51     /// supplied channel.
52     InProcess,
53
54     /// Spawns a subprocess to run the test, and sends the result back over the
55     /// supplied channel. Requires `argv[0]` to exist and point to the binary
56     /// that's currently running.
57     SpawnPrimary,
58 }
59
60 /// Options for the test run defined by the caller (instead of CLI arguments).
61 /// In case we want to add other options as well, just add them in this struct.
62 #[derive(Copy, Clone, Debug)]
63 pub struct Options {
64     pub display_output: bool,
65     pub panic_abort: bool,
66 }
67
68 impl Options {
69     pub fn new() -> Options {
70         Options { display_output: false, panic_abort: false }
71     }
72
73     pub fn display_output(mut self, display_output: bool) -> Options {
74         self.display_output = display_output;
75         self
76     }
77
78     pub fn panic_abort(mut self, panic_abort: bool) -> Options {
79         self.panic_abort = panic_abort;
80         self
81     }
82 }