@@ -151,18 +151,23 @@ impl Runner for LintRunner {
151
151
} else {
152
152
config_file
153
153
} ;
154
- match fs:: write ( Self :: DEFAULT_OXLINTRC , configuration) {
155
- Ok ( ( ) ) => {
156
- return CliRunResult :: ConfigFileInitResult {
157
- message : "Configuration file created" . to_string ( ) ,
158
- }
159
- }
160
- Err ( _) => {
161
- return CliRunResult :: ConfigFileInitResult {
162
- message : "Failed to create configuration file" . to_string ( ) ,
163
- }
164
- }
154
+
155
+ if fs:: write ( Self :: DEFAULT_OXLINTRC , configuration) . is_ok ( ) {
156
+ stdout
157
+ . write_all ( "Configuration file created\n " . as_bytes ( ) )
158
+ . or_else ( Self :: check_for_writer_error)
159
+ . unwrap ( ) ;
160
+ stdout. flush ( ) . unwrap ( ) ;
161
+ return CliRunResult :: ConfigFileInitSucceeded ;
165
162
}
163
+
164
+ // failed case
165
+ stdout
166
+ . write_all ( "Failed to create configuration file\n " . as_bytes ( ) )
167
+ . or_else ( Self :: check_for_writer_error)
168
+ . unwrap ( ) ;
169
+ stdout. flush ( ) . unwrap ( ) ;
170
+ return CliRunResult :: ConfigFileInitFailed ;
166
171
}
167
172
}
168
173
@@ -224,6 +229,7 @@ impl Runner for LintRunner {
224
229
start_time : now. elapsed ( ) ,
225
230
} ) {
226
231
stdout. write_all ( end. as_bytes ( ) ) . or_else ( Self :: check_for_writer_error) . unwrap ( ) ;
232
+ stdout. flush ( ) . unwrap ( ) ;
227
233
} ;
228
234
229
235
CliRunResult :: LintResult ( ExitCode :: from ( u8:: from ( diagnostic_failed) ) )
@@ -328,10 +334,7 @@ mod test {
328
334
use std:: fs;
329
335
330
336
use super :: LintRunner ;
331
- use crate :: {
332
- cli:: { lint_command, CliRunResult , Runner } ,
333
- tester:: Tester ,
334
- } ;
337
+ use crate :: tester:: Tester ;
335
338
336
339
// lints the full directory of fixtures,
337
340
// so do not snapshot it, test only
@@ -644,14 +647,13 @@ mod test {
644
647
645
648
#[ test]
646
649
fn test_init_config ( ) {
650
+ assert ! ( !fs:: exists( LintRunner :: DEFAULT_OXLINTRC ) . unwrap( ) ) ;
651
+
647
652
let args = & [ "--init" ] ;
648
- let options = lint_command ( ) . run_inner ( args) . unwrap ( ) ;
649
- let mut output = Vec :: new ( ) ;
650
- let ret = LintRunner :: new ( options) . run ( & mut output) ;
651
- let CliRunResult :: ConfigFileInitResult { message } = ret else {
652
- panic ! ( "Expected configuration file to be created, got {ret:?}" )
653
- } ;
654
- assert_eq ! ( message, "Configuration file created" ) ;
653
+ Tester :: new ( ) . test ( args) ;
654
+
655
+ assert ! ( fs:: exists( LintRunner :: DEFAULT_OXLINTRC ) . unwrap( ) ) ;
656
+
655
657
fs:: remove_file ( LintRunner :: DEFAULT_OXLINTRC ) . unwrap ( ) ;
656
658
}
657
659
0 commit comments