@@ -52,19 +52,23 @@ fn verify_against_date_command_local(path: &'static str, dt: NaiveDateTime) {
5252 }
5353}
5454
55+ /// path to Unix `date` command. Should work on most Linux and Unixes. Not the
56+ /// path for MacOS (/bin/date) which uses a different version of `date` with
57+ /// different arguments (so it won't run which is okay).
58+ /// for testing only
59+ #[ allow( dead_code) ]
60+ #[ cfg( not( target_os = "aix" ) ) ]
61+ const DATE_PATH : & ' static str = "/usr/bin/date" ;
62+ #[ allow( dead_code) ]
63+ #[ cfg( target_os = "aix" ) ]
64+ const DATE_PATH : & ' static str = "/opt/freeware/bin/date" ;
65+
5566#[ test]
5667#[ cfg( unix) ]
5768fn try_verify_against_date_command ( ) {
58- #[ cfg( not( target_os = "aix" ) ) ]
59- let date_path = "/usr/bin/date" ;
60- #[ cfg( target_os = "aix" ) ]
61- let date_path = "/opt/freeware/bin/date" ;
62-
63- if !path:: Path :: new ( date_path) . exists ( ) {
64- // date command not found, skipping
65- // avoid running this on macOS, which has path /bin/date
66- // as the required CLI arguments are not present in the
67- // macOS build.
69+
70+ if !path:: Path :: new ( DATE_PATH ) . exists ( ) {
71+ eprintln ! ( "date command {:?} not found, skipping" , DATE_PATH ) ;
6872 return ;
6973 }
7074
@@ -75,7 +79,7 @@ fn try_verify_against_date_command() {
7579 || ( 2020 ..=2022 ) . contains ( & date. year ( ) )
7680 || ( 2073 ..=2077 ) . contains ( & date. year ( ) )
7781 {
78- verify_against_date_command_local ( date_path , date) ;
82+ verify_against_date_command_local ( DATE_PATH , date) ;
7983 }
8084
8185 date += chrono:: Duration :: hours ( 1 ) ;
@@ -125,15 +129,13 @@ fn verify_against_date_command_format_local(path: &'static str, dt: NaiveDateTim
125129#[ test]
126130#[ cfg( target_os = "linux" ) ]
127131fn try_verify_against_date_command_format ( ) {
128- let date_path = "/usr/bin/date" ;
129-
130- if !path:: Path :: new ( date_path) . exists ( ) {
131- // date command not found, skipping
132+ if !path:: Path :: new ( DATE_PATH ) . exists ( ) {
133+ eprintln ! ( "date command {:?} not found, skipping" , DATE_PATH ) ;
132134 return ;
133135 }
134136 let mut date = NaiveDate :: from_ymd_opt ( 1970 , 1 , 1 ) . unwrap ( ) . and_hms_opt ( 12 , 11 , 13 ) . unwrap ( ) ;
135137 while date. year ( ) < 2008 {
136- verify_against_date_command_format_local ( date_path , date) ;
138+ verify_against_date_command_format_local ( DATE_PATH , date) ;
137139 date += chrono:: Duration :: days ( 55 ) ;
138140 }
139141}
0 commit comments