@@ -132,16 +132,19 @@ pub(crate) fn lint_list(output: impl std::io::Write) -> Result<()> {
132132 Ok ( ( ) )
133133}
134134
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 (
140144 root : & Dir ,
141- warning_disposition : WarningDisposition ,
142145 root_type : RootType ,
143146 mut output : impl std:: io:: Write ,
144- ) -> Result < ( ) > {
147+ ) -> Result < LintExecutionResult > {
145148 let mut fatal = 0usize ;
146149 let mut warnings = 0usize ;
147150 let mut passed = 0usize ;
@@ -177,20 +180,40 @@ pub(crate) fn lint(
177180 passed += 1 ;
178181 }
179182 }
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) ?;
183206 }
184207 let fatal = if matches ! ( warning_disposition, WarningDisposition :: FatalWarnings ) {
185- fatal + warnings
208+ r . fatal + r . warnings
186209 } else {
187- fatal
210+ r . fatal
188211 } ;
189- if warnings > 0 {
190- writeln ! ( output, "Warnings: {warnings}" ) ?;
212+ if r . warnings > 0 {
213+ writeln ! ( output, "Warnings: {}" , r . warnings ) ?;
191214 }
192215 if fatal > 0 {
193- anyhow:: bail!( "Checks failed: {fatal}" )
216+ anyhow:: bail!( "Checks failed: {}" , fatal )
194217 }
195218 Ok ( ( ) )
196219}
@@ -517,6 +540,26 @@ mod tests {
517540 Ok ( ( ) )
518541 }
519542
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+
520563 #[ test]
521564 fn test_kernel_lint ( ) -> Result < ( ) > {
522565 let root = & fixture ( ) ?;
0 commit comments