1 /*
2  * This file is derived from src/options.rs in the Rust test library, used under
3  * the Apache License, Version 2.0. The following is the original copyright
4  * information from the Rust project:
5  *
6  * Copyrights in the Rust project are retained by their contributors. No
7  * copyright assignment is required to contribute to the Rust project.
8  *
9  * Some files include explicit copyright notices and/or license notices.
10  * For full authorship information, see the version control history or
11  * https://thanks.rust-lang.org
12  *
13  * Except as otherwise noted (below and/or in individual files), Rust is
14  * licensed under the Apache License, Version 2.0 <LICENSE-APACHE> or
15  * <http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
16  * <LICENSE-MIT> or <http://opensource.org/licenses/MIT>, at your option.
17  *
18  *
19  * Licensed under the Apache License, Version 2.0 (the "License");
20  * you may not use this file except in compliance with the License.
21  * You may obtain a copy of the License at
22  *
23  *      http://www.apache.org/licenses/LICENSE-2.0
24  *
25  * Unless required by applicable law or agreed to in writing, software
26  * distributed under the License is distributed on an "AS IS" BASIS,
27  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28  * See the License for the specific language governing permissions and
29  * limitations under the License.
30  */
31 
32 #![allow(dead_code)]
33 
34 //! Enums denoting options for test execution.
35 
36 /// Whether to execute tests concurrently or not
37 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
38 pub enum Concurrent {
39     Yes,
40     No,
41 }
42 
43 /// Number of times to run a benchmarked function
44 #[derive(Clone, PartialEq, Eq)]
45 pub enum BenchMode {
46     Auto,
47     Single,
48 }
49 
50 /// Whether test is expected to panic or not
51 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
52 pub enum ShouldPanic {
53     No,
54     Yes,
55     YesWithMessage(&'static str),
56 }
57 
58 /// Whether should console output be colored or not
59 #[derive(Copy, Clone, Debug)]
60 pub enum ColorConfig {
61     AutoColor,
62     AlwaysColor,
63     NeverColor,
64 }
65 
66 /// Format of the test results output
67 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
68 pub enum OutputFormat {
69     /// Verbose output
70     Pretty,
71     /// Quiet output
72     Terse,
73     /// JSON output
74     Json,
75 }
76 
77 /// Whether ignored test should be run or not
78 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
79 pub enum RunIgnored {
80     Yes,
81     No,
82     /// Run only ignored tests
83     Only,
84 }
85 
86 #[derive(Clone, Copy)]
87 pub enum RunStrategy {
88     /// Runs the test in the current process, and sends the result back over the
89     /// supplied channel.
90     InProcess,
91 
92     /// Spawns a subprocess to run the test, and sends the result back over the
93     /// supplied channel. Requires `argv[0]` to exist and point to the binary
94     /// that's currently running.
95     SpawnPrimary,
96 }
97 
98 /// Options for the test run defined by the caller (instead of CLI arguments).
99 /// In case we want to add other options as well, just add them in this struct.
100 #[derive(Copy, Clone, Debug)]
101 pub struct Options {
102     pub display_output: bool,
103     pub panic_abort: bool,
104 }
105 
106 impl Options {
new() -> Options107     pub fn new() -> Options {
108         Options { display_output: false, panic_abort: false }
109     }
110 
display_output(mut self, display_output: bool) -> Options111     pub fn display_output(mut self, display_output: bool) -> Options {
112         self.display_output = display_output;
113         self
114     }
115 
panic_abort(mut self, panic_abort: bool) -> Options116     pub fn panic_abort(mut self, panic_abort: bool) -> Options {
117         self.panic_abort = panic_abort;
118         self
119     }
120 }
121