1#!/bin/sh
2# Ensure ls output is aligned when using abbreviated months from the locale
3
4# Copyright (C) 2009-2023 Free Software Foundation, Inc.
5
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ ls
21
22mid_month="$(date +%Y-%m-15)" || framework_failure_
23for mon in $(seq -w 12); do
24    touch -d"$mid_month +$mon month" $mon.ts || framework_failure_
25done
26
27
28# Note some of the following locales may be missing but if so
29# we should fail back to the C locale which should be aligned
30
31for format in "%b" "[%b" "%b]" "[%b]"; do
32  for LOC in C gv_GB ga_IE fi_FI.utf8 zh_CN ar_SY $LOCALE_FR_UTF8; do
33    # The sed usage here is slightly different from the original,
34    # removing the \(.*\), to avoid triggering misbehavior in at least
35    # GNU sed 4.2 (possibly miscompiled) on Mac OS X (Darwin 9.8.0).
36    months="$(
37      LC_ALL=$LOC TIME_STYLE=+"$format" ls -lgG *.ts |
38      LC_ALL=C sed 's/.\{15\}//;s/ ..\.ts$//;s/ /./g')"
39    n_widths=$(echo "$months" |
40      while read mon; do echo "$mon" | LC_ALL=$LOC wc -L; done |
41      uniq | wc -l
42    )
43    n_dupes=$(echo "$months" | sort | uniq -d | wc -l)
44    test "$n_widths" = "1" || { fail=1; break 2; }
45    test "$n_dupes" = "0" || { fail=1; break 2; }
46  done
47done
48if test "$fail" = "1"; then
49   echo "misalignment or ambiguous output in $LOC locale:"
50   LC_ALL=$LOC TIME_STYLE=+%b ls -lgG *.ts
51fi
52
53Exit $fail
54