@@ -140,18 +140,25 @@ struct LintExecutionResult {
140
140
fatal : usize ,
141
141
}
142
142
143
- fn lint_inner (
143
+ fn lint_inner < ' skip > (
144
144
root : & Dir ,
145
145
root_type : RootType ,
146
+ skip : impl IntoIterator < Item = & ' skip str > ,
146
147
mut output : impl std:: io:: Write ,
147
148
) -> Result < LintExecutionResult > {
148
149
let mut fatal = 0usize ;
149
150
let mut warnings = 0usize ;
150
151
let mut passed = 0usize ;
151
152
let mut skipped = 0usize ;
153
+ let skip: std:: collections:: HashSet < _ > = skip. into_iter ( ) . collect ( ) ;
152
154
for lint in LINTS {
153
155
let name = lint. name ;
154
156
157
+ if skip. contains ( name) {
158
+ skipped += 1 ;
159
+ continue ;
160
+ }
161
+
155
162
if let Some ( lint_root_type) = lint. root_type {
156
163
if lint_root_type != root_type {
157
164
skipped += 1 ;
@@ -194,13 +201,14 @@ fn lint_inner(
194
201
/// if it exists we need to check that it links to /run if not error
195
202
/// if it does not exist error.
196
203
#[ context( "Linting" ) ]
197
- pub ( crate ) fn lint (
204
+ pub ( crate ) fn lint < ' skip > (
198
205
root : & Dir ,
199
206
warning_disposition : WarningDisposition ,
200
207
root_type : RootType ,
208
+ skip : impl IntoIterator < Item = & ' skip str > ,
201
209
mut output : impl std:: io:: Write ,
202
210
) -> Result < ( ) > {
203
- let r = lint_inner ( root, root_type, & mut output) ?;
211
+ let r = lint_inner ( root, root_type, skip , & mut output) ?;
204
212
writeln ! ( output, "Checks passed: {}" , r. passed) ?;
205
213
if r. skipped > 0 {
206
214
writeln ! ( output, "Checks skipped: {}" , r. skipped) ?;
@@ -534,31 +542,43 @@ mod tests {
534
542
let mut out = Vec :: new ( ) ;
535
543
let warnings = WarningDisposition :: FatalWarnings ;
536
544
let root_type = RootType :: Running ;
537
- lint ( root, warnings, root_type, & mut out) . unwrap ( ) ;
545
+ lint ( root, warnings, root_type, [ ] , & mut out) . unwrap ( ) ;
538
546
root. create_dir_all ( "var/run/foo" ) ?;
539
547
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( ) ) ;
541
549
Ok ( ( ) )
542
550
}
543
551
544
552
#[ test]
545
553
fn test_lint_inner ( ) -> Result < ( ) > {
546
554
let root = & passing_fixture ( ) ?;
555
+
556
+ // Verify that all lints run except one which is skipped for non-running roots
547
557
let mut out = Vec :: new ( ) ;
548
558
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 ( ) ;
550
560
let allbut_one = LINTS . len ( ) . checked_sub ( 1 ) . unwrap ( ) ;
551
561
assert_eq ! ( r. passed, allbut_one) ;
552
562
assert_eq ! ( r. fatal, 0 ) ;
553
563
assert_eq ! ( r. skipped, 1 ) ;
554
564
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
556
576
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 ( ) ;
558
578
assert_eq ! ( r. passed, allbut_one. checked_sub( 1 ) . unwrap( ) ) ;
559
- assert_eq ! ( r. fatal, 1 ) ;
579
+ assert_eq ! ( r. fatal, 0 ) ;
560
580
assert_eq ! ( r. skipped, 1 ) ;
561
- assert_eq ! ( r. warnings, 0 ) ;
581
+ assert_eq ! ( r. warnings, 1 ) ;
562
582
Ok ( ( ) )
563
583
}
564
584
0 commit comments