summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2016-09-19 12:36:18 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2016-09-19 12:48:32 -0700
commit1db94ee969b984bbd00b97c6abbe2f69db8e0000 (patch)
treefcd52754a6a4337e07e4996cb6cf37939e2655f0 /tests
parente0953783024a113b186547aca186777f9ce3b798 (diff)
downloadcoreutils-1db94ee969b984bbd00b97c6abbe2f69db8e0000.tar.xz
ls: fix %%b format and precompute more
The old code mishandled --time-spec='+%%b', as it misinterpreted the '%b' as being the month abbreviation. Also, it mishandled the extremely unlikely case of a month abbreviation containing '%'. The performance part of this patch sped up 'ls' by about 1% on my little benchmark of 'ls -lR' on the source directory in the en_US.UTF-8 locale (Fedora 24 x86-64). * NEWS: Document the bug fix. * src/ls.c (first_percent_b, abformat_init): New static functions. (ABFORMAT_SIZE): New constant. (use_abformat): New static var. (abmon, required_mon_width): Remove these static vars. (abmon_init): Now accepts a pointer to abmon, and returns a boolean. All callers changed. Reject month abbrs containing '%', as these would mess up strftime. Simplify mbsalign result checking, since (size_t) -1 exceeds ABFORMAT_SIZE. (abformat_init, align_nstrftime): Precompute all 24 formats at startup, rather than computing a format for each time stamp. (decode_switches): Call abformat_init instead of abmon_init. (align_nstrftime): Accept recentness bool instead of format. All callers changed. * tests/misc/time-style.sh: Test for format with '%%b'.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/misc/time-style.sh19
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/misc/time-style.sh b/tests/misc/time-style.sh
index 444996158..2ca0acfe6 100755
--- a/tests/misc/time-style.sh
+++ b/tests/misc/time-style.sh
@@ -27,7 +27,8 @@ echo hello >a || framework_failure_
TZ=UTC0 touch -d '1970-07-08 09:10:11' a || framework_failure_
for tz in UTC0 PST8 PST8PDT,M3.2.0,M11.1.0 XXXYYY-12:30; do
- for style in full-iso long-iso iso locale '+%Y-%m-%d %H:%M:%S %z (%Z)'; do
+ for style in full-iso long-iso iso locale '+%Y-%m-%d %H:%M:%S %z (%Z)' \
+ +%%b%b%%b%b; do
test "$style" = locale ||
TZ=$tz LC_ALL=C du --time --time-style="$style" a >>duout 2>>err || fail=1
TZ=$tz LC_ALL=C ls -no --time-style="$style" a >>lsout 2>>err || fail=1
@@ -46,18 +47,22 @@ cat <<\EOF > duexp || fail=1
1970-07-08 09:10 a
1970-07-08 a
1970-07-08 09:10:11 +0000 (UTC) a
+%bJul%bJul a
1970-07-08 01:10:11.000000000 -0800 a
1970-07-08 01:10 a
1970-07-08 a
1970-07-08 01:10:11 -0800 (PST) a
+%bJul%bJul a
1970-07-08 02:10:11.000000000 -0700 a
1970-07-08 02:10 a
1970-07-08 a
1970-07-08 02:10:11 -0700 (PDT) a
+%bJul%bJul a
1970-07-08 21:40:11.000000000 +1230 a
1970-07-08 21:40 a
1970-07-08 a
1970-07-08 21:40:11 +1230 (XXXYYY) a
+%bJul%bJul a
EOF
cat <<\EOF > lsexp || fail=1
@@ -66,32 +71,44 @@ cat <<\EOF > lsexp || fail=1
1970-07-08 a
Jul 8 1970 a
1970-07-08 09:10:11 +0000 (UTC) a
+%bJul%bJul a
1970-07-08 01:10:11.000000000 -0800 a
1970-07-08 01:10 a
1970-07-08 a
Jul 8 1970 a
1970-07-08 01:10:11 -0800 (PST) a
+%bJul%bJul a
1970-07-08 02:10:11.000000000 -0700 a
1970-07-08 02:10 a
1970-07-08 a
Jul 8 1970 a
1970-07-08 02:10:11 -0700 (PDT) a
+%bJul%bJul a
1970-07-08 21:40:11.000000000 +1230 a
1970-07-08 21:40 a
1970-07-08 a
Jul 8 1970 a
1970-07-08 21:40:11 +1230 (XXXYYY) a
+%bJul%bJul a
EOF
cat <<\EOF > prexp || fail=1
+1970-07-08 09:10:11 +0000 (UTC) a Page 1
hello
++%bJul%bJul a Page 1
+hello
+1970-07-08 01:10:11 -0800 (PST) a Page 1
hello
++%bJul%bJul a Page 1
+hello
+1970-07-08 02:10:11 -0700 (PDT) a Page 1
hello
++%bJul%bJul a Page 1
+hello
+1970-07-08 21:40:11 +1230 (XXXYYY) a Page 1
hello
++%bJul%bJul a Page 1
+hello
EOF
compare duexp dued || fail=1