File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
src/tools/tidy/src/alphabetical Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -31,16 +31,19 @@ fn bad(lines: &str, expected_msg: &str) {
3131
3232#[ track_caller]
3333fn bless_test ( before : & str , after : & str ) {
34- let tempfile = tempfile:: Builder :: new ( ) . tempfile ( ) . unwrap ( ) ;
35- std:: fs:: write ( tempfile. path ( ) , before) . unwrap ( ) ;
34+ // NB: convert to a temporary *path* (closing the file), so that `check_lines` can then
35+ // atomically replace the file with a blessed version (on windows that requires the file
36+ // to not be open)
37+ let temp_path = tempfile:: Builder :: new ( ) . tempfile ( ) . unwrap ( ) . into_temp_path ( ) ;
38+ std:: fs:: write ( & temp_path, before) . unwrap ( ) ;
3639
37- let tidy_ctx = TidyCtx :: new ( Path :: new ( "/aaaa " ) , false , TidyFlags :: new ( & [ "--bless" . to_owned ( ) ] ) ) ;
40+ let tidy_ctx = TidyCtx :: new ( Path :: new ( "/" ) , false , TidyFlags :: new ( & [ "--bless" . to_owned ( ) ] ) ) ;
3841
3942 let mut check = tidy_ctx. start_check ( "alphabetical-test" ) ;
40- check_lines ( tempfile . path ( ) , before, & tidy_ctx, & mut check) ;
43+ check_lines ( & temp_path , before, & tidy_ctx, & mut check) ;
4144
4245 assert ! ( !check. is_bad( ) ) ;
43- let new = std:: fs:: read_to_string ( tempfile . path ( ) ) . unwrap ( ) ;
46+ let new = std:: fs:: read_to_string ( temp_path ) . unwrap ( ) ;
4447 assert_eq ! ( new, after) ;
4548
4649 good ( & new) ;
You can’t perform that action at this time.
0 commit comments