@@ -132,26 +132,37 @@ pub(crate) fn lint_list(output: impl std::io::Write) -> Result<()> {
132
132
Ok ( ( ) )
133
133
}
134
134
135
- /// check for the existence of the /var/run directory
136
- /// if it exists we need to check that it links to /run if not error
137
- /// if it does not exist error.
138
- #[ context( "Linting" ) ]
139
- pub ( crate ) fn lint (
135
+ #[ derive( Debug ) ]
136
+ struct LintExecutionResult {
137
+ warnings : usize ,
138
+ passed : usize ,
139
+ skipped : usize ,
140
+ fatal : usize ,
141
+ }
142
+
143
+ fn lint_inner < ' skip > (
140
144
root : & Dir ,
141
- warning_disposition : WarningDisposition ,
142
145
root_type : RootType ,
146
+ skip : impl IntoIterator < Item = & ' skip str > ,
143
147
mut output : impl std:: io:: Write ,
144
- ) -> Result < ( ) > {
148
+ ) -> Result < LintExecutionResult > {
145
149
let mut fatal = 0usize ;
146
150
let mut warnings = 0usize ;
147
151
let mut passed = 0usize ;
148
152
let mut skipped = 0usize ;
153
+ let skip: std:: collections:: HashSet < _ > = skip. into_iter ( ) . collect ( ) ;
149
154
for lint in LINTS {
150
155
let name = lint. name ;
151
156
157
+ if skip. contains ( name) {
158
+ skipped += 1 ;
159
+ continue ;
160
+ }
161
+
152
162
if let Some ( lint_root_type) = lint. root_type {
153
163
if lint_root_type != root_type {
154
164
skipped += 1 ;
165
+ continue ;
155
166
}
156
167
}
157
168
@@ -177,20 +188,41 @@ pub(crate) fn lint(
177
188
passed += 1 ;
178
189
}
179
190
}
180
- writeln ! ( output, "Checks passed: {passed}" ) ?;
181
- if skipped > 0 {
182
- writeln ! ( output, "Checks skipped: {skipped}" ) ?;
191
+
192
+ Ok ( LintExecutionResult {
193
+ passed,
194
+ skipped,
195
+ warnings,
196
+ fatal,
197
+ } )
198
+ }
199
+
200
+ /// check for the existence of the /var/run directory
201
+ /// if it exists we need to check that it links to /run if not error
202
+ /// if it does not exist error.
203
+ #[ context( "Linting" ) ]
204
+ pub ( crate ) fn lint < ' skip > (
205
+ root : & Dir ,
206
+ warning_disposition : WarningDisposition ,
207
+ root_type : RootType ,
208
+ skip : impl IntoIterator < Item = & ' skip str > ,
209
+ mut output : impl std:: io:: Write ,
210
+ ) -> Result < ( ) > {
211
+ let r = lint_inner ( root, root_type, skip, & mut output) ?;
212
+ writeln ! ( output, "Checks passed: {}" , r. passed) ?;
213
+ if r. skipped > 0 {
214
+ writeln ! ( output, "Checks skipped: {}" , r. skipped) ?;
183
215
}
184
216
let fatal = if matches ! ( warning_disposition, WarningDisposition :: FatalWarnings ) {
185
- fatal + warnings
217
+ r . fatal + r . warnings
186
218
} else {
187
- fatal
219
+ r . fatal
188
220
} ;
189
- if warnings > 0 {
190
- writeln ! ( output, "Warnings: {warnings}" ) ?;
221
+ if r . warnings > 0 {
222
+ writeln ! ( output, "Warnings: {}" , r . warnings ) ?;
191
223
}
192
224
if fatal > 0 {
193
- anyhow:: bail!( "Checks failed: {fatal}" )
225
+ anyhow:: bail!( "Checks failed: {}" , fatal )
194
226
}
195
227
Ok ( ( ) )
196
228
}
@@ -509,11 +541,43 @@ mod tests {
509
541
let root = & passing_fixture ( ) ?;
510
542
let mut out = Vec :: new ( ) ;
511
543
let warnings = WarningDisposition :: FatalWarnings ;
512
- let root_type = RootType :: Running ;
513
- lint ( root, warnings, root_type, & mut out) . unwrap ( ) ;
544
+ let root_type = RootType :: Alternative ;
545
+ lint ( root, warnings, root_type, [ ] , & mut out) . unwrap ( ) ;
514
546
root. create_dir_all ( "var/run/foo" ) ?;
515
547
let mut out = Vec :: new ( ) ;
516
- assert ! ( lint( root, warnings, root_type, & mut out) . is_err( ) ) ;
548
+ assert ! ( lint( root, warnings, root_type, [ ] , & mut out) . is_err( ) ) ;
549
+ Ok ( ( ) )
550
+ }
551
+
552
+ #[ test]
553
+ fn test_lint_inner ( ) -> Result < ( ) > {
554
+ let root = & passing_fixture ( ) ?;
555
+
556
+ // Verify that all lints run
557
+ let mut out = Vec :: new ( ) ;
558
+ let root_type = RootType :: Alternative ;
559
+ let r = lint_inner ( root, root_type, [ ] , & mut out) . unwrap ( ) ;
560
+ assert_eq ! ( r. passed, LINTS . len( ) ) ;
561
+ assert_eq ! ( r. fatal, 0 ) ;
562
+ assert_eq ! ( r. skipped, 0 ) ;
563
+ assert_eq ! ( r. warnings, 0 ) ;
564
+
565
+ let r = lint_inner ( root, root_type, [ "var-log" ] , & mut out) . unwrap ( ) ;
566
+ // Trigger a failure in var-log
567
+ root. create_dir_all ( "var/log/dnf" ) ?;
568
+ root. write ( "var/log/dnf/dnf.log" , b"dummy dnf log" ) ?;
569
+ assert_eq ! ( r. passed, LINTS . len( ) . checked_sub( 1 ) . unwrap( ) ) ;
570
+ assert_eq ! ( r. fatal, 0 ) ;
571
+ assert_eq ! ( r. skipped, 1 ) ;
572
+ assert_eq ! ( r. warnings, 0 ) ;
573
+
574
+ // But verify that not skipping it results in a warning
575
+ let mut out = Vec :: new ( ) ;
576
+ let r = lint_inner ( root, root_type, [ ] , & mut out) . unwrap ( ) ;
577
+ assert_eq ! ( r. passed, LINTS . len( ) . checked_sub( 1 ) . unwrap( ) ) ;
578
+ assert_eq ! ( r. fatal, 0 ) ;
579
+ assert_eq ! ( r. skipped, 0 ) ;
580
+ assert_eq ! ( r. warnings, 1 ) ;
517
581
Ok ( ( ) )
518
582
}
519
583
0 commit comments