@@ -34,7 +34,6 @@ pub struct TestOpts {
3434 pub shuffle_seed : Option < u64 > ,
3535 pub test_threads : Option < std:: num:: NonZeroUsize > ,
3636 pub skip : Vec < String > ,
37- pub time_options : Option < TestTimeOptions > ,
3837 /// Stop at first failing test.
3938 /// May run a few more tests due to threading, but will
4039 /// abort as soon as possible.
@@ -91,90 +90,6 @@ impl Default for OutputFormat {
9190 }
9291}
9392
94- /// Structure with parameters for calculating test execution time (see [`TestOpts::time_options`])
95- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
96- pub struct TestTimeOptions {
97- /// Denotes if the test critical execution time limit excess should be considered
98- /// a test failure.
99- pub error_on_excess : bool ,
100- pub unit_threshold : TimeThreshold ,
101- pub integration_threshold : TimeThreshold ,
102- pub doctest_threshold : TimeThreshold ,
103- }
104-
105- impl Default for TestTimeOptions {
106- fn default ( ) -> Self {
107- Self {
108- error_on_excess : false ,
109- unit_threshold : TimeThreshold {
110- warn : std:: time:: Duration :: from_millis ( 50 ) ,
111- critical : std:: time:: Duration :: from_millis ( 100 ) ,
112- } ,
113- integration_threshold : TimeThreshold {
114- warn : std:: time:: Duration :: from_millis ( 50 ) ,
115- critical : std:: time:: Duration :: from_millis ( 100 ) ,
116- } ,
117- doctest_threshold : TimeThreshold {
118- warn : std:: time:: Duration :: from_millis ( 50 ) ,
119- critical : std:: time:: Duration :: from_millis ( 100 ) ,
120- } ,
121- }
122- }
123- }
124-
125- /// Structure denoting time limits for test execution (see [`TestTimeOptions`])
126- #[ derive( Copy , Clone , Debug , Default , PartialEq , Eq ) ]
127- pub struct TimeThreshold {
128- pub warn : std:: time:: Duration ,
129- pub critical : std:: time:: Duration ,
130- }
131-
132- impl TimeThreshold {
133- /// Attempts to create a `TimeThreshold` instance with values obtained
134- /// from the environment variable, and returns `None` if the variable
135- /// is not set.
136- /// Environment variable format is expected to match `\d+,\d+`.
137- ///
138- /// # Panics
139- ///
140- /// Panics if variable with provided name is set but contains inappropriate
141- /// value.
142- fn from_env_var ( env_var_name : & str ) -> Result < Option < Self > , ErrorContext < ' static > > {
143- use std:: str:: FromStr ;
144-
145- let durations_str = match std:: env:: var ( env_var_name) {
146- Ok ( value) => value,
147- Err ( _) => {
148- return Ok ( None ) ;
149- }
150- } ;
151- let ( warn_str, critical_str) = durations_str. split_once ( ',' ) . ok_or_else ( || {
152- ErrorContext :: msg ( format_args ! (
153- "Duration variable {env_var_name} expected to have 2 numbers separated by comma, but got {durations_str}"
154- ) )
155- } ) ?;
156-
157- let parse_u64 = |v| {
158- u64:: from_str ( v) . map_err ( |_err| {
159- ErrorContext :: msg ( format_args ! (
160- "Duration value in variable {env_var_name} is expected to be a number, but got {v}"
161- ) )
162- } )
163- } ;
164-
165- let warn = parse_u64 ( warn_str) ?;
166- let critical = parse_u64 ( critical_str) ?;
167- if warn > critical {
168- panic ! ( "Test execution warn time should be less or equal to the critical time" ) ;
169- }
170-
171- Ok ( Some ( Self {
172- warn : std:: time:: Duration :: from_millis ( warn) ,
173- critical : std:: time:: Duration :: from_millis ( critical) ,
174- } ) )
175- }
176- }
177-
17893/// Options for the test run defined by the caller (instead of CLI arguments) (see
17994/// [`TestOpts::options`])
18095///
@@ -390,23 +305,6 @@ impl TestOptsBuilder {
390305 // Don't validate `feature` as other parsers might provide values
391306 self . opts . allowed_unstable . push ( feature. to_owned ( ) ) ;
392307 }
393- Long ( "report-time" ) => {
394- self . opts . time_options . get_or_insert_with ( Default :: default) ;
395- }
396- Long ( "ensure-time" ) => {
397- let time = self . opts . time_options . get_or_insert_with ( Default :: default) ;
398- time. error_on_excess = true ;
399- if let Some ( threshold) = TimeThreshold :: from_env_var ( "RUST_TEST_TIME_UNIT" ) ? {
400- time. unit_threshold = threshold;
401- }
402- if let Some ( threshold) = TimeThreshold :: from_env_var ( "RUST_TEST_TIME_INTEGRATION" ) ?
403- {
404- time. integration_threshold = threshold;
405- }
406- if let Some ( threshold) = TimeThreshold :: from_env_var ( "RUST_TEST_TIME_DOCTEST" ) ? {
407- time. doctest_threshold = threshold;
408- }
409- }
410308 Long ( "shuffle" ) => {
411309 self . opts . shuffle = true ;
412310 }
0 commit comments