1# 2# Regression tests for date(1) 3# 4# Submitted by Edwin Groothuis <edwin@FreeBSD.org> 5# 6# $FreeBSD$ 7# 8 9# 10# These two date/times have been chosen carefully -- they 11# create both the single digit and double/multidigit version of 12# the values. 13# 14# To create a new one, make sure you are using the UTC timezone! 15# 16 17TEST1=3222243 # 1970-02-07 07:04:03 18TEST2=1005600000 # 2001-11-12 21:11:12 19 20check() 21{ 22 local format_string exp_output_1 exp_output_2 23 24 format_string=${1} 25 exp_output_1=${2} 26 exp_output_2=${3} 27 28 atf_check -o "inline:${exp_output_1}\n" \ 29 date -r ${TEST1} +%${format_string} 30 atf_check -o "inline:${exp_output_2}\n" \ 31 date -r ${TEST2} +%${format_string} 32} 33 34format_string_test() 35{ 36 local desc exp_output_1 exp_output_2 flag 37 38 desc=${1} 39 flag=${2} 40 exp_output_1=${3} 41 exp_output_2=${4} 42 43 atf_test_case ${desc}_test 44 eval " 45${desc}_test_body() { 46 check ${flag} '${exp_output_1}' '${exp_output_2}'; 47}" 48 atf_add_test_case ${desc}_test 49} 50 51atf_init_test_cases() 52{ 53 format_string_test A A Saturday Monday 54 format_string_test a a Sat Mon 55 format_string_test B B February November 56 format_string_test b b Feb Nov 57 format_string_test C C 19 20 58 format_string_test c c "Sat Feb 7 07:04:03 1970" "Mon Nov 12 21:20:00 2001" 59 format_string_test D D 02/07/70 11/12/01 60 format_string_test d d 07 12 61 format_string_test e e " 7" 12 62 format_string_test F F "1970-02-07" "2001-11-12" 63 format_string_test G G 1970 2001 64 format_string_test g g 70 01 65 format_string_test H H 07 21 66 format_string_test h h Feb Nov 67 format_string_test I I 07 09 68 format_string_test j j 038 316 69 format_string_test k k " 7" 21 70 format_string_test l l " 7" " 9" 71 format_string_test M M 04 20 72 format_string_test m m 02 11 73 format_string_test p p AM PM 74 format_string_test R R 07:04 21:20 75 format_string_test r r "07:04:03 AM" "09:20:00 PM" 76 format_string_test S S 03 00 77 format_string_test s s ${TEST1} ${TEST2} 78 format_string_test U U 05 45 79 format_string_test u u 6 1 80 format_string_test V V 06 46 81 format_string_test v v " 7-Feb-1970" "12-Nov-2001" 82 format_string_test W W 05 46 83 format_string_test w w 6 1 84 format_string_test X X "07:04:03" "21:20:00" 85 format_string_test x x "02/07/70" "11/12/01" 86 format_string_test Y Y 1970 2001 87 format_string_test y y 70 01 88 format_string_test Z Z UTC UTC 89 format_string_test z z +0000 +0000 90 format_string_test percent % % % 91 format_string_test plus + "Sat Feb 7 07:04:03 UTC 1970" "Mon Nov 12 21:20:00 UTC 2001" 92} 93