@@ -140,18 +140,25 @@ struct LintExecutionResult {
140140 fatal : usize ,
141141}
142142
143- fn lint_inner (
143+ fn lint_inner < ' skip > (
144144 root : & Dir ,
145145 root_type : RootType ,
146+ skip : impl IntoIterator < Item = & ' skip str > ,
146147 mut output : impl std:: io:: Write ,
147148) -> Result < LintExecutionResult > {
148149 let mut fatal = 0usize ;
149150 let mut warnings = 0usize ;
150151 let mut passed = 0usize ;
151152 let mut skipped = 0usize ;
153+ let skip: std:: collections:: HashSet < _ > = skip. into_iter ( ) . collect ( ) ;
152154 for lint in LINTS {
153155 let name = lint. name ;
154156
157+ if skip. contains ( name) {
158+ skipped += 1 ;
159+ continue ;
160+ }
161+
155162 if let Some ( lint_root_type) = lint. root_type {
156163 if lint_root_type != root_type {
157164 skipped += 1 ;
@@ -194,13 +201,14 @@ fn lint_inner(
194201/// if it exists we need to check that it links to /run if not error
195202/// if it does not exist error.
196203#[ context( "Linting" ) ]
197- pub ( crate ) fn lint (
204+ pub ( crate ) fn lint < ' skip > (
198205 root : & Dir ,
199206 warning_disposition : WarningDisposition ,
200207 root_type : RootType ,
208+ skip : impl IntoIterator < Item = & ' skip str > ,
201209 mut output : impl std:: io:: Write ,
202210) -> Result < ( ) > {
203- let r = lint_inner ( root, root_type, & mut output) ?;
211+ let r = lint_inner ( root, root_type, skip , & mut output) ?;
204212 writeln ! ( output, "Checks passed: {}" , r. passed) ?;
205213 if r. skipped > 0 {
206214 writeln ! ( output, "Checks skipped: {}" , r. skipped) ?;
@@ -534,31 +542,43 @@ mod tests {
534542 let mut out = Vec :: new ( ) ;
535543 let warnings = WarningDisposition :: FatalWarnings ;
536544 let root_type = RootType :: Running ;
537- lint ( root, warnings, root_type, & mut out) . unwrap ( ) ;
545+ lint ( root, warnings, root_type, [ ] , & mut out) . unwrap ( ) ;
538546 root. create_dir_all ( "var/run/foo" ) ?;
539547 let mut out = Vec :: new ( ) ;
540- assert ! ( lint( root, warnings, root_type, & mut out) . is_err( ) ) ;
548+ assert ! ( lint( root, warnings, root_type, [ ] , & mut out) . is_err( ) ) ;
541549 Ok ( ( ) )
542550 }
543551
544552 #[ test]
545553 fn test_lint_inner ( ) -> Result < ( ) > {
546554 let root = & passing_fixture ( ) ?;
555+
556+ // Verify that all lints run except one which is skipped for non-running roots
547557 let mut out = Vec :: new ( ) ;
548558 let root_type = RootType :: Running ;
549- let r = lint_inner ( root, root_type, & mut out) . unwrap ( ) ;
559+ let r = lint_inner ( root, root_type, [ ] , & mut out) . unwrap ( ) ;
550560 let allbut_one = LINTS . len ( ) . checked_sub ( 1 ) . unwrap ( ) ;
551561 assert_eq ! ( r. passed, allbut_one) ;
552562 assert_eq ! ( r. fatal, 0 ) ;
553563 assert_eq ! ( r. skipped, 1 ) ;
554564 assert_eq ! ( r. warnings, 0 ) ;
555- root. create_dir_all ( "var/run/foo" ) ?;
565+
566+ let r = lint_inner ( root, root_type, [ "var-log" ] , & mut out) . unwrap ( ) ;
567+ // Trigger a failure in var-log
568+ root. create_dir_all ( "var/log/dnf" ) ?;
569+ root. write ( "var/log/dnf/dnf.log" , b"dummy dnf log" ) ?;
570+ assert_eq ! ( r. passed, allbut_one. checked_sub( 1 ) . unwrap( ) ) ;
571+ assert_eq ! ( r. fatal, 0 ) ;
572+ assert_eq ! ( r. skipped, 2 ) ;
573+ assert_eq ! ( r. warnings, 0 ) ;
574+
575+ // But verify that not skipping it results in an error
556576 let mut out = Vec :: new ( ) ;
557- let r = lint_inner ( root, root_type, & mut out) . unwrap ( ) ;
577+ let r = lint_inner ( root, root_type, [ ] , & mut out) . unwrap ( ) ;
558578 assert_eq ! ( r. passed, allbut_one. checked_sub( 1 ) . unwrap( ) ) ;
559- assert_eq ! ( r. fatal, 1 ) ;
579+ assert_eq ! ( r. fatal, 0 ) ;
560580 assert_eq ! ( r. skipped, 1 ) ;
561- assert_eq ! ( r. warnings, 0 ) ;
581+ assert_eq ! ( r. warnings, 1 ) ;
562582 Ok ( ( ) )
563583 }
564584
0 commit comments