@@ -73,12 +73,13 @@ where
7373}
7474
7575#[ cfg( test) ]
76+ #[ allow( clippy:: unwrap_used) ]
7677mod tests {
7778 use super :: * ;
7879 use tracing:: subscriber:: with_default;
7980 use tracing_subscriber:: fmt:: Subscriber ;
8081
81- /// Captures all output from a tracing subscriber using our Formatter.
82+ /// Captures all output from a tracing subscriber using our ` Formatter` .
8283 fn capture_log < F : FnOnce ( ) > ( f : F ) -> String {
8384 let buf = std:: sync:: Arc :: new ( std:: sync:: Mutex :: new ( Vec :: new ( ) ) ) ;
8485 let buf_clone = buf. clone ( ) ;
@@ -100,12 +101,11 @@ mod tests {
100101 String :: from_utf8 ( lock. clone ( ) ) . expect ( "invalid UTF-8 in log output" )
101102 }
102103
103- /// A wrapper so Arc<Mutex<Vec<u8>>> implements std::io::Write.
104104 struct WriterGuard ( std:: sync:: Arc < std:: sync:: Mutex < Vec < u8 > > > ) ;
105105
106106 impl std:: io:: Write for WriterGuard {
107107 fn write ( & mut self , buf : & [ u8 ] ) -> std:: io:: Result < usize > {
108- self . 0 . lock ( ) . unwrap ( ) . extend_from_slice ( buf) ;
108+ self . 0 . lock ( ) . expect ( "write lock poisoned" ) . extend_from_slice ( buf) ;
109109 Ok ( buf. len ( ) )
110110 }
111111 fn flush ( & mut self ) -> std:: io:: Result < ( ) > {
@@ -137,7 +137,8 @@ mod tests {
137137 tracing:: error!( "something broke" ) ;
138138 } ) ;
139139
140- let parsed: serde_json:: Value = serde_json:: from_str ( output. trim ( ) ) . unwrap ( ) ;
140+ let parsed: serde_json:: Value =
141+ serde_json:: from_str ( output. trim ( ) ) . expect ( "output should be valid JSON" ) ;
141142 assert_eq ! ( parsed[ "level" ] , "ERROR" ) ;
142143 assert ! (
143144 parsed[ "message" ]
@@ -153,7 +154,8 @@ mod tests {
153154 tracing:: debug!( "debug details" ) ;
154155 } ) ;
155156
156- let parsed: serde_json:: Value = serde_json:: from_str ( output. trim ( ) ) . unwrap ( ) ;
157+ let parsed: serde_json:: Value =
158+ serde_json:: from_str ( output. trim ( ) ) . expect ( "output should be valid JSON" ) ;
157159 assert_eq ! ( parsed[ "level" ] , "DEBUG" ) ;
158160 assert ! (
159161 parsed[ "message" ]
@@ -169,7 +171,6 @@ mod tests {
169171 tracing:: info!( "message with \" quotes\" and a\n newline" ) ;
170172 } ) ;
171173
172- // The output should be valid JSON despite special characters
173174 let parsed: serde_json:: Value =
174175 serde_json:: from_str ( output. trim ( ) ) . expect ( "special chars should be escaped" ) ;
175176 let msg = parsed[ "message" ] . as_str ( ) . unwrap ( ) ;
0 commit comments