@@ -132,16 +132,19 @@ 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 (
140
144
root : & Dir ,
141
- warning_disposition : WarningDisposition ,
142
145
root_type : RootType ,
143
146
mut output : impl std:: io:: Write ,
144
- ) -> Result < ( ) > {
147
+ ) -> Result < LintExecutionResult > {
145
148
let mut fatal = 0usize ;
146
149
let mut warnings = 0usize ;
147
150
let mut passed = 0usize ;
@@ -177,20 +180,40 @@ pub(crate) fn lint(
177
180
passed += 1 ;
178
181
}
179
182
}
180
- writeln ! ( output, "Checks passed: {passed}" ) ?;
181
- if skipped > 0 {
182
- writeln ! ( output, "Checks skipped: {skipped}" ) ?;
183
+
184
+ Ok ( LintExecutionResult {
185
+ passed,
186
+ skipped,
187
+ warnings,
188
+ fatal,
189
+ } )
190
+ }
191
+
192
+ /// check for the existence of the /var/run directory
193
+ /// if it exists we need to check that it links to /run if not error
194
+ /// if it does not exist error.
195
+ #[ context( "Linting" ) ]
196
+ pub ( crate ) fn lint (
197
+ root : & Dir ,
198
+ warning_disposition : WarningDisposition ,
199
+ root_type : RootType ,
200
+ mut output : impl std:: io:: Write ,
201
+ ) -> Result < ( ) > {
202
+ let r = lint_inner ( root, root_type, & mut output) ?;
203
+ writeln ! ( output, "Checks passed: {}" , r. passed) ?;
204
+ if r. skipped > 0 {
205
+ writeln ! ( output, "Checks skipped: {}" , r. skipped) ?;
183
206
}
184
207
let fatal = if matches ! ( warning_disposition, WarningDisposition :: FatalWarnings ) {
185
- fatal + warnings
208
+ r . fatal + r . warnings
186
209
} else {
187
- fatal
210
+ r . fatal
188
211
} ;
189
- if warnings > 0 {
190
- writeln ! ( output, "Warnings: {warnings}" ) ?;
212
+ if r . warnings > 0 {
213
+ writeln ! ( output, "Warnings: {}" , r . warnings ) ?;
191
214
}
192
215
if fatal > 0 {
193
- anyhow:: bail!( "Checks failed: {fatal}" )
216
+ anyhow:: bail!( "Checks failed: {}" , fatal )
194
217
}
195
218
Ok ( ( ) )
196
219
}
@@ -517,6 +540,26 @@ mod tests {
517
540
Ok ( ( ) )
518
541
}
519
542
543
+ #[ test]
544
+ fn test_lint_inner ( ) -> Result < ( ) > {
545
+ let root = & passing_fixture ( ) ?;
546
+ let mut out = Vec :: new ( ) ;
547
+ let root_type = RootType :: Running ;
548
+ let r = lint_inner ( root, root_type, & mut out) . unwrap ( ) ;
549
+ assert_eq ! ( r. passed, LINTS . len( ) ) ;
550
+ assert_eq ! ( r. fatal, 0 ) ;
551
+ assert_eq ! ( r. skipped, 1 ) ;
552
+ assert_eq ! ( r. warnings, 0 ) ;
553
+ root. create_dir_all ( "var/run/foo" ) ?;
554
+ let mut out = Vec :: new ( ) ;
555
+ let r = lint_inner ( root, root_type, & mut out) . unwrap ( ) ;
556
+ assert_eq ! ( r. passed, LINTS . len( ) . checked_sub( 1 ) . unwrap( ) ) ;
557
+ assert_eq ! ( r. fatal, 1 ) ;
558
+ assert_eq ! ( r. skipped, 1 ) ;
559
+ assert_eq ! ( r. warnings, 0 ) ;
560
+ Ok ( ( ) )
561
+ }
562
+
520
563
#[ test]
521
564
fn test_kernel_lint ( ) -> Result < ( ) > {
522
565
let root = & fixture ( ) ?;
0 commit comments