@@ -1492,26 +1492,54 @@ fn test_stdin_is_socket() {
14921492 . stdout_is ( ";;" ) ;
14931493}
14941494
1495- #[ cfg( unix) ]
1496- #[ cfg_attr( wasi_runner, ignore = "WASI: the guest does not inherit LC_ALL" ) ]
1497- #[ test]
1498- fn test_classes_follow_single_byte_locale ( ) {
1499- // Compile a Latin-1 locale into the scenario's tmp dir.
1500- let ( at, _ucmd) = at_and_ucmd ! ( ) ;
1495+ // Returns (`LC_ALL`, optional `LOCPATH`): on Linux the locale is compiled
1496+ // with localedef into the scenario tmp dir, while FreeBSD and macOS use the
1497+ // installed system locale, as their localedef needs locale sources that are
1498+ // not installed there.
1499+ #[ cfg( all( unix, target_os = "linux" ) ) ]
1500+ fn locale_test_env (
1501+ at : & uutests:: util:: AtPath ,
1502+ charmap : & str ,
1503+ glibc_name : & str ,
1504+ _system_name : & str ,
1505+ ) -> ( String , Option < String > ) {
15011506 let compiled = std:: process:: Command :: new ( "localedef" )
1502- . args ( [ "-i" , "en_US" , "-f" , "ISO-8859-1" ] )
1503- . arg ( at. plus ( "en_US.ISO-8859-1" ) )
1507+ . args ( [ "-i" , "en_US" , "-f" , charmap ] )
1508+ . arg ( at. plus ( glibc_name ) )
15041509 . output ( )
15051510 . is_ok_and ( |output| output. status . success ( ) ) ;
15061511 assert ! (
15071512 compiled,
1508- "localedef failed to compile the Latin-1 test locale"
1513+ "localedef failed to compile the {glibc_name} test locale"
15091514 ) ;
1510- let locpath = at. as_string ( ) ;
1515+ ( glibc_name. to_string ( ) , Some ( at. as_string ( ) ) )
1516+ }
1517+
1518+ #[ cfg( all( unix, not( target_os = "linux" ) ) ) ]
1519+ fn locale_test_env (
1520+ _at : & uutests:: util:: AtPath ,
1521+ _charmap : & str ,
1522+ _glibc_name : & str ,
1523+ system_name : & str ,
1524+ ) -> ( String , Option < String > ) {
1525+ ( system_name. to_string ( ) , None )
1526+ }
1527+
1528+ #[ cfg( unix) ]
1529+ #[ cfg_attr( wasi_runner, ignore = "WASI: the guest does not inherit LC_ALL" ) ]
1530+ // macOS ships no single-byte locale, so this test has nothing to run against there.
1531+ #[ cfg( not( target_os = "macos" ) ) ]
1532+ #[ test]
1533+ fn test_classes_follow_single_byte_locale ( ) {
1534+ let ( at, _ucmd) = at_and_ucmd ! ( ) ;
1535+ let ( locale, locpath) =
1536+ locale_test_env ( & at, "ISO-8859-1" , "en_US.ISO-8859-1" , "en_US.ISO8859-1" ) ;
1537+ let mut cmd = new_ucmd ! ( ) ;
1538+ if let Some ( locpath) = locpath {
1539+ cmd. env ( "LOCPATH" , locpath) ;
1540+ }
15111541 // In Latin-1, 0x9b is a control character, so -d [:cntrl:] removes it.
1512- new_ucmd ! ( )
1513- . env ( "LOCPATH" , & locpath)
1514- . env ( "LC_ALL" , "en_US.ISO-8859-1" )
1542+ cmd. env ( "LC_ALL" , locale)
15151543 . args ( & [ "-d" , "[:cntrl:]" ] )
15161544 . pipe_in ( [ b'h' , b'e' , b'l' , b'l' , b'o' , 0x9b , b'3' , b'1' , b'm' ] )
15171545 . succeeds ( )
@@ -1522,22 +1550,14 @@ fn test_classes_follow_single_byte_locale() {
15221550#[ cfg_attr( wasi_runner, ignore = "WASI: the guest does not inherit LC_ALL" ) ]
15231551#[ test]
15241552fn test_classes_ignore_high_bytes_in_utf8_locale ( ) {
1525- // Compile a UTF-8 locale into the scenario's tmp dir.
15261553 let ( at, _ucmd) = at_and_ucmd ! ( ) ;
1527- let compiled = std:: process:: Command :: new ( "localedef" )
1528- . args ( [ "-i" , "en_US" , "-f" , "UTF-8" ] )
1529- . arg ( at. plus ( "en_US.UTF-8" ) )
1530- . output ( )
1531- . is_ok_and ( |output| output. status . success ( ) ) ;
1532- assert ! (
1533- compiled,
1534- "localedef failed to compile the UTF-8 test locale"
1535- ) ;
1536- let locpath = at. as_string ( ) ;
1554+ let ( locale, locpath) = locale_test_env ( & at, "UTF-8" , "en_US.UTF-8" , "en_US.UTF-8" ) ;
1555+ let mut cmd = new_ucmd ! ( ) ;
1556+ if let Some ( locpath) = locpath {
1557+ cmd. env ( "LOCPATH" , locpath) ;
1558+ }
15371559 // In UTF-8, high bytes are never class members, so -d [:alpha:] must not split é.
1538- new_ucmd ! ( )
1539- . env ( "LOCPATH" , & locpath)
1540- . env ( "LC_ALL" , "en_US.UTF-8" )
1560+ cmd. env ( "LC_ALL" , locale)
15411561 . args ( & [ "-d" , "[:alpha:]" ] )
15421562 . pipe_in ( [ b'a' , 0xc3 , 0xa9 , b'b' ] )
15431563 . succeeds ( )
0 commit comments