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