File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,7 @@ impl RingBuffer {
115
115
}
116
116
}
117
117
118
+ #[ derive( Clone ) ]
118
119
pub struct LoggerFileOptions {
119
120
pub file_path : String ,
120
121
pub append_mode : bool ,
@@ -208,3 +209,32 @@ impl Logger {
208
209
}
209
210
}
210
211
}
212
+
213
+ #[ cfg( test) ]
214
+ mod tests {
215
+ use super :: * ;
216
+ use std:: fs;
217
+
218
+ fn setup ( ) {
219
+ fs:: File :: options ( )
220
+ . read ( true )
221
+ . write ( true )
222
+ . create ( true )
223
+ . open ( "log.txt" )
224
+ . unwrap ( ) ;
225
+ }
226
+
227
+ #[ test]
228
+ fn simple_to_file ( ) {
229
+ setup ( ) ;
230
+ let o = LoggerFileOptions {
231
+ file_path : "log.txt" . to_owned ( ) ,
232
+ append_mode : false ,
233
+ } ;
234
+ let logger = Logger :: new ( 1024 , Some ( o. clone ( ) ) ) ;
235
+ logger. log_f ( || "to file" . to_owned ( ) ) ;
236
+ logger. shutdown ( ) ;
237
+ let bytes = fs:: read ( o. file_path ) . unwrap ( ) ;
238
+ assert_eq ! ( String :: from_utf8( bytes) . unwrap( ) , "to file\n " . to_owned( ) ) ;
239
+ }
240
+ }
You can’t perform that action at this time.
0 commit comments