@@ -40,6 +40,10 @@ const SKIP_FILE_WHITE_LIST: &[&str] = &[
40
40
"cfg_mod/wasm32.rs" ,
41
41
] ;
42
42
43
+ fn init_log ( ) {
44
+ let _ = env_logger:: builder ( ) . is_test ( true ) . try_init ( ) ;
45
+ }
46
+
43
47
struct TestSetting {
44
48
/// The size of the stack of the thread that run tests.
45
49
stack_size : usize ,
@@ -137,6 +141,7 @@ fn verify_config_used(path: &Path, config_name: &str) {
137
141
138
142
#[ test]
139
143
fn verify_config_test_names ( ) {
144
+ init_log ( ) ;
140
145
for path in & [
141
146
Path :: new ( "tests/source/configs" ) ,
142
147
Path :: new ( "tests/target/configs" ) ,
@@ -169,6 +174,7 @@ fn write_message(msg: &str) {
169
174
// exactly.
170
175
#[ test]
171
176
fn system_tests ( ) {
177
+ init_log ( ) ;
172
178
run_test_with ( & TestSetting :: default ( ) , || {
173
179
// Get all files in the tests/source directory.
174
180
let files = get_test_files ( Path :: new ( "tests/source" ) , true ) ;
@@ -189,6 +195,7 @@ fn system_tests() {
189
195
// The only difference is the coverage mode.
190
196
#[ test]
191
197
fn coverage_tests ( ) {
198
+ init_log ( ) ;
192
199
let files = get_test_files ( Path :: new ( "tests/coverage/source" ) , true ) ;
193
200
let ( _reports, count, fails) = check_files ( files, & None ) ;
194
201
@@ -198,20 +205,23 @@ fn coverage_tests() {
198
205
199
206
#[ test]
200
207
fn checkstyle_test ( ) {
208
+ init_log ( ) ;
201
209
let filename = "tests/writemode/source/fn-single-line.rs" ;
202
210
let expected_filename = "tests/writemode/target/checkstyle.xml" ;
203
211
assert_output ( Path :: new ( filename) , Path :: new ( expected_filename) ) ;
204
212
}
205
213
206
214
#[ test]
207
215
fn json_test ( ) {
216
+ init_log ( ) ;
208
217
let filename = "tests/writemode/source/json.rs" ;
209
218
let expected_filename = "tests/writemode/target/output.json" ;
210
219
assert_output ( Path :: new ( filename) , Path :: new ( expected_filename) ) ;
211
220
}
212
221
213
222
#[ test]
214
223
fn modified_test ( ) {
224
+ init_log ( ) ;
215
225
use std:: io:: BufRead ;
216
226
217
227
// Test "modified" output
@@ -297,6 +307,7 @@ fn assert_output(source: &Path, expected_filename: &Path) {
297
307
// rustfmt.
298
308
#[ test]
299
309
fn idempotence_tests ( ) {
310
+ init_log ( ) ;
300
311
run_test_with ( & TestSetting :: default ( ) , || {
301
312
// these tests require nightly
302
313
if !is_nightly_channel ! ( ) {
@@ -321,6 +332,7 @@ fn idempotence_tests() {
321
332
// no warnings are emitted.
322
333
#[ test]
323
334
fn self_tests ( ) {
335
+ init_log ( ) ;
324
336
// Issue-3443: these tests require nightly
325
337
if !is_nightly_channel ! ( ) {
326
338
return ;
@@ -359,6 +371,7 @@ fn self_tests() {
359
371
360
372
#[ test]
361
373
fn stdin_formatting_smoke_test ( ) {
374
+ init_log ( ) ;
362
375
let input = Input :: Text ( "fn main () {}" . to_owned ( ) ) ;
363
376
let mut config = Config :: default ( ) ;
364
377
config. set ( ) . emit_mode ( EmitMode :: Stdout ) ;
@@ -377,6 +390,7 @@ fn stdin_formatting_smoke_test() {
377
390
378
391
#[ test]
379
392
fn stdin_parser_panic_caught ( ) {
393
+ init_log ( ) ;
380
394
// See issue #3239.
381
395
for text in [ "{" , "}" ] . iter ( ) . cloned ( ) . map ( String :: from) {
382
396
let mut buf = vec ! [ ] ;
@@ -391,6 +405,7 @@ fn stdin_parser_panic_caught() {
391
405
/// when embedding Rustfmt (e.g. inside RLS).
392
406
#[ test]
393
407
fn stdin_works_with_modified_lines ( ) {
408
+ init_log ( ) ;
394
409
let input = "\n fn\n some( )\n {\n }\n fn main () {}\n " ;
395
410
let output = "1 6 2\n fn some() {}\n fn main() {}\n " ;
396
411
@@ -413,6 +428,7 @@ fn stdin_works_with_modified_lines() {
413
428
414
429
#[ test]
415
430
fn stdin_disable_all_formatting_test ( ) {
431
+ init_log ( ) ;
416
432
match option_env ! ( "CFG_RELEASE_CHANNEL" ) {
417
433
None | Some ( "nightly" ) => { }
418
434
// These tests require nightly.
@@ -441,6 +457,7 @@ fn stdin_disable_all_formatting_test() {
441
457
442
458
#[ test]
443
459
fn format_lines_errors_are_reported ( ) {
460
+ init_log ( ) ;
444
461
let long_identifier = String :: from_utf8 ( vec ! [ b'a' ; 239 ] ) . unwrap ( ) ;
445
462
let input = Input :: Text ( format ! ( "fn {}() {{}}" , long_identifier) ) ;
446
463
let mut config = Config :: default ( ) ;
@@ -452,6 +469,7 @@ fn format_lines_errors_are_reported() {
452
469
453
470
#[ test]
454
471
fn format_lines_errors_are_reported_with_tabs ( ) {
472
+ init_log ( ) ;
455
473
let long_identifier = String :: from_utf8 ( vec ! [ b'a' ; 97 ] ) . unwrap ( ) ;
456
474
let input = Input :: Text ( format ! ( "fn a() {{\n \t {}\n }}" , long_identifier) ) ;
457
475
let mut config = Config :: default ( ) ;
@@ -719,6 +737,7 @@ fn get_target(file_name: &Path, target: Option<&str>) -> PathBuf {
719
737
720
738
#[ test]
721
739
fn rustfmt_diff_make_diff_tests ( ) {
740
+ init_log ( ) ;
722
741
let diff = make_diff ( "a\n b\n c\n d" , "a\n e\n c\n d" , 3 ) ;
723
742
assert_eq ! (
724
743
diff,
@@ -738,6 +757,7 @@ fn rustfmt_diff_make_diff_tests() {
738
757
739
758
#[ test]
740
759
fn rustfmt_diff_no_diff_test ( ) {
760
+ init_log ( ) ;
741
761
let diff = make_diff ( "a\n b\n c\n d" , "a\n b\n c\n d" , 3 ) ;
742
762
assert_eq ! ( diff, vec![ ] ) ;
743
763
}
@@ -772,6 +792,7 @@ impl<'a> Iterator for CharsIgnoreNewlineRepr<'a> {
772
792
773
793
#[ test]
774
794
fn string_eq_ignore_newline_repr_test ( ) {
795
+ init_log ( ) ;
775
796
assert ! ( string_eq_ignore_newline_repr( "" , "" ) ) ;
776
797
assert ! ( !string_eq_ignore_newline_repr( "" , "abc" ) ) ;
777
798
assert ! ( !string_eq_ignore_newline_repr( "abc" , "" ) ) ;
@@ -833,6 +854,7 @@ fn rustfmt() -> PathBuf {
833
854
834
855
#[ test]
835
856
fn verify_check_works ( ) {
857
+ init_log ( ) ;
836
858
let temp_file = make_temp_file ( "temp_check.rs" ) ;
837
859
838
860
Command :: new ( rustfmt ( ) . to_str ( ) . unwrap ( ) )
0 commit comments