11//! libtest-compatible argument parser
22//!
3- //! This does not drive parsing but provides [`TestOptsParseState `] to plug into the parsing,
3+ //! This does not drive parsing but provides [`TestOptsBuilder `] to plug into the parsing,
44//! allowing additional parsers to be integrated.
5+ //!
6+ //! ## Example
7+ //!
8+ //! ```no_run
9+ #![ doc = include_str ! ( "../examples/libtest-cli.rs" ) ]
10+ //! ```
511
612#![ cfg_attr( docsrs, feature( doc_auto_cfg) ) ]
713#![ forbid( unsafe_code) ]
@@ -12,7 +18,7 @@ use lexarg_error::ErrorContext;
1218
1319/// Parsed command-line options
1420///
15- /// To parse, see [`TestOptsParseState `]
21+ /// To parse, see [`TestOptsBuilder `]
1622#[ derive( Debug , Default ) ]
1723pub struct TestOpts {
1824 pub list : bool ,
@@ -23,7 +29,6 @@ pub struct TestOpts {
2329 pub run_ignored : RunIgnored ,
2430 pub run_tests : bool ,
2531 pub bench_benchmarks : bool ,
26- pub logfile : Option < std:: path:: PathBuf > ,
2732 pub nocapture : bool ,
2833 pub color : ColorConfig ,
2934 pub format : OutputFormat ,
@@ -40,7 +45,7 @@ pub struct TestOpts {
4045 pub allowed_unstable : Vec < String > ,
4146}
4247
43- /// Whether ignored test should be run or not
48+ /// Whether ignored test should be run or not (see [`TestOpts::run_ignored`])
4449#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
4550pub enum RunIgnored {
4651 Yes ,
@@ -55,7 +60,7 @@ impl Default for RunIgnored {
5560 }
5661}
5762
58- /// Whether should console output be colored or not
63+ /// Whether should console output be colored or not (see [`TestOpts::color`])
5964#[ derive( Copy , Clone , Debug ) ]
6065pub enum ColorConfig {
6166 AutoColor ,
@@ -69,7 +74,7 @@ impl Default for ColorConfig {
6974 }
7075}
7176
72- /// Format of the test results output
77+ /// Format of the test results output (see [`TestOpts::format`])
7378#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
7479pub enum OutputFormat {
7580 /// Verbose output
@@ -88,7 +93,7 @@ impl Default for OutputFormat {
8893 }
8994}
9095
91- /// Structure with parameters for calculating test execution time.
96+ /// Structure with parameters for calculating test execution time (see [`TestOpts::time_options`])
9297#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
9398pub struct TestTimeOptions {
9499 /// Denotes if the test critical execution time limit excess should be considered
@@ -119,7 +124,7 @@ impl Default for TestTimeOptions {
119124 }
120125}
121126
122- /// Structure denoting time limits for test execution.
127+ /// Structure denoting time limits for test execution (see [`TestTimeOptions`])
123128#[ derive( Copy , Clone , Debug , Default , PartialEq , Eq ) ]
124129pub struct TimeThreshold {
125130 pub warn : std:: time:: Duration ,
@@ -172,7 +177,9 @@ impl TimeThreshold {
172177 }
173178}
174179
175- /// Options for the test run defined by the caller (instead of CLI arguments).
180+ /// Options for the test run defined by the caller (instead of CLI arguments) (see
181+ /// [`TestOpts::options`])
182+ ///
176183/// In case we want to add other options as well, just add them in this struct.
177184#[ derive( Copy , Clone , Debug , Default ) ]
178185pub struct Options {
@@ -194,7 +201,6 @@ Options:
194201 --test Run tests and not benchmarks
195202 --bench Run benchmarks instead of tests
196203 --list List all tests and benchmarks
197- --logfile PATH Write logs to the specified file
198204 --nocapture don't capture stdout/stderr of each task, allow
199205 printing directly
200206 --test-threads n_threads
@@ -284,17 +290,17 @@ Test Attributes:
284290
285291/// Intermediate CLI parser state for [`TestOpts`]
286292///
287- /// See [`TestOptsParseState ::parse_next`]
293+ /// See [`TestOptsBuilder ::parse_next`]
288294#[ derive( Debug , Default ) ]
289- pub struct TestOptsParseState {
295+ pub struct TestOptsBuilder {
290296 opts : TestOpts ,
291297 quiet : bool ,
292298 format : Option < OutputFormat > ,
293299 include_ignored : bool ,
294300 ignored : bool ,
295301}
296302
297- impl TestOptsParseState {
303+ impl TestOptsBuilder {
298304 pub fn new ( ) -> Self {
299305 Default :: default ( )
300306 }
@@ -327,14 +333,6 @@ impl TestOptsParseState {
327333 Long ( "list" ) => {
328334 self . opts . list = true ;
329335 }
330- Long ( "logfile" ) => {
331- let path = parser
332- . next_flag_value ( )
333- . ok_or_missing ( Value ( std:: ffi:: OsStr :: new ( "PATH" ) ) )
334- . path ( )
335- . within ( arg) ?;
336- self . opts . logfile = Some ( path. to_owned ( ) ) ;
337- }
338336 Long ( "nocapture" ) => {
339337 self . opts . nocapture = true ;
340338 }
@@ -508,8 +506,7 @@ impl TestOptsParseState {
508506 }
509507 if let Some ( format) = self . format {
510508 self . opts . format = format;
511- }
512- if self . quiet {
509+ } else if self . quiet {
513510 self . opts . format = OutputFormat :: Terse ;
514511 }
515512
0 commit comments