@@ -18,6 +18,9 @@ use pipe_trait::Pipe;
1818use pretty_assertions:: assert_eq;
1919use std:: process:: { Command , Stdio } ;
2020
21+ /// Predefined `LS_COLORS` value used in color tests to ensure deterministic output.
22+ const LS_COLORS : & str = "rs=0:di=01;34:ln=01;36:ex=01;32:fi=00" ;
23+
2124#[ cfg( unix) ]
2225use parallel_disk_usage:: {
2326 ls_colors:: LsColors ,
@@ -822,6 +825,7 @@ fn colorful_equals_colorless() {
822825 . with_current_dir ( & workspace)
823826 . with_arg ( "--color=always" )
824827 . with_arg ( "--total-width=100" )
828+ . with_env ( "LS_COLORS" , LS_COLORS )
825829 . pipe ( stdio)
826830 . output ( )
827831 . expect ( "spawn command with --color=always" ) ;
@@ -839,6 +843,7 @@ fn colorful_equals_colorless() {
839843 . with_current_dir ( & workspace)
840844 . with_arg ( "--color=never" )
841845 . with_arg ( "--total-width=100" )
846+ . with_env ( "LS_COLORS" , LS_COLORS )
842847 . pipe ( stdio)
843848 . output ( )
844849 . expect ( "spawn command with --color=never" )
@@ -857,6 +862,7 @@ fn color_always() {
857862 . with_arg ( "--color=always" )
858863 . with_arg ( "--total-width=100" )
859864 . with_arg ( "--min-ratio=0" )
865+ . with_env ( "LS_COLORS" , LS_COLORS )
860866 . pipe ( stdio)
861867 . output ( )
862868 . expect ( "spawn command with --color=always" )
@@ -874,6 +880,8 @@ fn color_always() {
874880 data_tree. par_sort_by ( |left, right| left. size ( ) . cmp ( & right. size ( ) ) . reverse ( ) ) ;
875881 * data_tree. name_mut ( ) = OsStringDisplay :: os_string_from ( "." ) ;
876882
883+ // SAFETY: tests that set LS_COLORS all use the same constant value, so there is no data race.
884+ unsafe { std:: env:: set_var ( "LS_COLORS" , LS_COLORS ) } ;
877885 let ls_colors = LsColors :: from_env ( ) ;
878886 let map = HashMap :: from ( [
879887 (
0 commit comments