1# 2# SPDX-License-Identifier: BSD-2-Clause 3# 4# Copyright (c) 2023 Christos Margiolis <christos@FreeBSD.org> 5# 6 7get_months_fmt() 8{ 9 rm -f in 10 for i in $(seq 12 1); do 11 printf "2000-%02d-01\n" ${i} | xargs -I{} \ 12 date -jf "%Y-%m-%d" {} "${1}" >>in 13 done 14} 15 16atf_test_case monthsort_english 17monthsort_english_head() 18{ 19 atf_set "descr" "Test the -M flag with English months" 20} 21monthsort_english_body() 22{ 23 export LC_TIME="en_US.UTF-8" 24 25 cat >expout <<EOF 26January 27February 28March 29April 30May 31June 32July 33August 34September 35October 36November 37December 38EOF 39 40 # No need to test the rest of the formats (%b and %OB) as %b is a 41 # substring of %B and %OB is the same as %B. 42 get_months_fmt '+%B' 43 atf_check -o file:expout sort -M in 44} 45 46atf_test_case monthsort_all_formats_greek 47monthsort_all_formats_greek_head() 48{ 49 atf_set "descr" "Test the -M flag with all possible Greek month formats" 50} 51monthsort_all_formats_greek_body() 52{ 53 # Test with the Greek locale, since, unlike English, the 54 # abbreviation/full-name and standalone formats are different. 55 export LC_TIME="el_GR.UTF-8" 56 57 # Abbreviation format (e.g Jan, Ιαν) 58 cat >expout <<EOF 59Ιαν 60Φεβ 61Μαρ 62Απρ 63Μαΐ 64Ιουν 65Ιουλ 66Αυγ 67Σεπ 68Οκτ 69Νοε 70Δεκ 71EOF 72 get_months_fmt '+%b' 73 atf_check -o file:expout sort -M in 74 75 # Full-name format (e.g January, Ιανουαρίου) 76 cat >expout <<EOF 77Ιανουαρίου 78Φεβρουαρίου 79Μαρτίου 80Απριλίου 81Μαΐου 82Ιουνίου 83Ιουλίου 84Αυγούστου 85Σεπτεμβρίου 86Οκτωβρίου 87Νοεμβρίου 88Δεκεμβρίου 89EOF 90 get_months_fmt '+%B' 91 atf_check -o file:expout sort -M in 92 93 # Standalone format (e.g January, Ιανουάριος) 94 cat >expout <<EOF 95Ιανουάριος 96Φεβρουάριος 97Μάρτιος 98Απρίλιος 99Μάϊος 100Ιούνιος 101Ιούλιος 102Αύγουστος 103Σεπτέμβριος 104Οκτώβριος 105Νοέμβριος 106Δεκέμβριος 107EOF 108 get_months_fmt '+%OB' 109 atf_check -o file:expout sort -M in 110} 111 112atf_test_case monthsort_mixed_formats_greek 113monthsort_mixed_formats_greek_head() 114{ 115 atf_set "descr" "Test the -M flag with mixed Greek month formats" 116} 117monthsort_mixed_formats_greek_body() 118{ 119 export LC_TIME="el_GR.UTF-8" 120 121 cat >in <<EOF 122Δεκέμβριος 123Νοεμβρίου 124Οκτ 125Σεπ 126Αυγ 127Ιούλιος 128Ιουνίου 129Μαΐου 130Απριλίου 131Μάρτιος 132Φεβρουάριος 133Ιανουάριος 134EOF 135 136 cat >expout <<EOF 137Ιανουάριος 138Φεβρουάριος 139Μάρτιος 140Απριλίου 141Μαΐου 142Ιουνίου 143Ιούλιος 144Αυγ 145Σεπ 146Οκτ 147Νοεμβρίου 148Δεκέμβριος 149EOF 150 151 atf_check -o file:expout sort -M in 152} 153 154atf_init_test_cases() 155{ 156 atf_add_test_case monthsort_english 157 atf_add_test_case monthsort_all_formats_greek 158 atf_add_test_case monthsort_mixed_formats_greek 159} 160