]> git.lizzy.rs Git - rust.git/blob - src/libtest/options.rs
Clean some error codes diagnostics
[rust.git] / src / libtest / 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 }
43
44 /// Whether ignored test should be runned or not
45 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
46 pub enum RunIgnored {
47     Yes,
48     No,
49     /// Run only ignored tests
50     Only,
51 }
52
53 #[derive(Clone, Copy)]
54 pub enum RunStrategy {
55     /// Runs the test in the current process, and sends the result back over the
56     /// supplied channel.
57     InProcess,
58
59     /// Spawns a subprocess to run the test, and sends the result back over the
60     /// supplied channel. Requires `argv[0]` to exist and point to the binary
61     /// that's currently running.
62     SpawnPrimary,
63 }
64
65 /// Options for the test run defined by the caller (instead of CLI arguments).
66 /// In case we want to add other options as well, just add them in this struct.
67 #[derive(Copy, Clone, Debug)]
68 pub struct Options {
69     pub display_output: bool,
70     pub panic_abort: bool,
71 }
72
73 impl Options {
74     pub fn new() -> Options {
75         Options {
76             display_output: false,
77             panic_abort: false,
78         }
79     }
80
81     pub fn display_output(mut self, display_output: bool) -> Options {
82         self.display_output = display_output;
83         self
84     }
85
86     pub fn panic_abort(mut self, panic_abort: bool) -> Options {
87         self.panic_abort = panic_abort;
88         self
89     }
90 }