I noticed Ubuntu 25.10 upgrades were broken due to uutils mishandling date -r:
https://www.phoronix.com/news/Ubuntu-25.10-Broken-Upgrade
Upon reviewing our date(1) test coverage I see that our current level of 79.8%
for date.c, did not in fact cover --reference or --resolution.
The attached two patches brings test coverage for date.c to 87.1%
cheers,
Padraig
From 14d24f7a530f587099057fa5411ebcf3cfc55e7d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Thu, 23 Oct 2025 15:25:14 +0100
Subject: [PATCH 1/2] tests: date: test --reference
* tests/date/reference.sh: Ensure the -r option is tested.
* tests/local.mk: Add the test.
---
tests/date/reference.sh | 50 +++++++++++++++++++++++++++++++++++++++++
tests/local.mk | 1 +
2 files changed, 51 insertions(+)
create mode 100755 tests/date/reference.sh
diff --git a/tests/date/reference.sh b/tests/date/reference.sh
new file mode 100755
index 000000000..f7db9fd5b
--- /dev/null
+++ b/tests/date/reference.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+# Test date --reference
+
+# Copyright (C) 2025 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ date
+
+# Avoid any possible glitches due to daylight-saving changes near the
+# timestamps used during the test.
+TZ=UTC0
+export TZ
+
+t1='2025-10-23 03:00'
+t2='2025-10-23 04:00'
+
+# date(1) only considers modiication time
+touch -m -d "$t1" a || framework_failure_
+touch -m -d "$t2" b || framework_failure_
+
+test $(date +%s -r a) -lt $(date +%s -r b) || fail=1
+
+if test "$(date +%s -d "$t1")" -lt "$(date +%s)"; then
+ test "$(date +%s -r a)" -lt "$(date +%s)" || fail=1
+fi
+
+ln -s t1 t1s || framework_failure_
+if ! test t1 -ot t1s && ! test t1 -nt t1s; then
+ test "$(date -r t1)" = "$(date -r t1s)" || fail=1
+fi
+
+returns_ 1 date --reference || fail=1
+returns_ 1 date --reference= || fail=1
+returns_ 1 date --reference=missing || fail=1
+returns_ 1 date -d "$t1" -r/ || fail=1
+
+Exit $fail
diff --git a/tests/local.mk b/tests/local.mk
index bd7d602aa..b31346a5c 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -318,6 +318,7 @@ all_tests = \
tests/date/date-ethiopia.sh \
tests/date/date-iran.sh \
tests/date/date-locale-hour.sh \
+ tests/date/reference.sh \
tests/date/date-sec.sh \
tests/date/date-thailand.sh \
tests/date/date-tz.sh \
--
2.51.0
From 1dabab70273f64cda228d244f9e262a3f77ef087 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Thu, 23 Oct 2025 16:44:14 +0100
Subject: [PATCH 2/2] tests: date: test --resolution and %-N
* tests/date/resolution.sh: New test for --resolution and %-N.
* tests/local.mk: Reference the new test.
---
tests/date/resolution.sh | 31 +++++++++++++++++++++++++++++++
tests/local.mk | 1 +
2 files changed, 32 insertions(+)
create mode 100755 tests/date/resolution.sh
diff --git a/tests/date/resolution.sh b/tests/date/resolution.sh
new file mode 100755
index 000000000..730983dc9
--- /dev/null
+++ b/tests/date/resolution.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+# Test date resolution interface
+
+# Copyright (C) 2025 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ date
+
+# Ensure --resolution is supported
+res=$(date --resolution) || fail=1
+
+# Ensure %-N format is supported
+subsec1=$(printf "%s" "$res" | cut -d. -f2- | wc -c) || framework_failure_
+subsec2=$(date +%-N | wc -c) || framework_failure_
+test "$subsec1" = "$subsec2" || fail=1
+
+
+Exit $fail
diff --git a/tests/local.mk b/tests/local.mk
index b31346a5c..53fc53e00 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -319,6 +319,7 @@ all_tests = \
tests/date/date-iran.sh \
tests/date/date-locale-hour.sh \
tests/date/reference.sh \
+ tests/date/resolution.sh \
tests/date/date-sec.sh \
tests/date/date-thailand.sh \
tests/date/date-tz.sh \
--
2.51.0