From ec17b1c3352cc47aeef3ba87b04453edf9d9f019 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 13:37:06 -1000 Subject: Check every age bucket and a date past now Only the class prefix was checked, and the fixture held nothing between the two week cutoff and now, so a bucket bound that slipped or a date past now shown as a negative age passed. Each tag sits in the upper half of its bucket, which the bucket below takes if its bound slips. --- tests/t0203-dates.sh | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/tests/t0203-dates.sh b/tests/t0203-dates.sh index 5c3567f..fc21758 100755 --- a/tests/t0203-dates.sh +++ b/tests/t0203-dates.sh @@ -8,9 +8,12 @@ test_description='Check the date display options' . ./setup.sh -# One old commit and one fresh one, so a single page shows both the relative -# rendering and the calendar fallback that takes over past the two week -# cutoff. +# The repo holds the commit mkrepo dates in 2005 at +0200, an old one at +0000 +# and a fresh one, so that the log shows both the relative rendering and the +# calendar fallback that takes over past the two week cutoff. Each tag is +# dated in the upper half of an age bucket, where the bucket below would take +# it if its bound slipped, and one is dated a day from now. The minutes stop +# 20 seconds short of 90, which a slow run still rounds to. test_expect_success 'set up a dated repo' ' mkrepo repos/dated 1 && ( @@ -18,9 +21,15 @@ test_expect_success 'set up a dated repo' ' GIT_AUTHOR_DATE="@1112911993 +0000" \ GIT_COMMITTER_DATE="@1112911993 +0000" \ git commit --allow-empty -m old && - GIT_AUTHOR_DATE="@$(date +%s) +0000" \ - GIT_COMMITTER_DATE="@$(date +%s) +0000" \ - git commit --allow-empty -m fresh + unset GIT_AUTHOR_DATE GIT_COMMITTER_DATE && + git commit --allow-empty -m fresh && + now=$(git log -1 --format=%ct) && + for age in mins:5380 hours:108000 days:864000 weeks:3628800 \ + months:47304000 years:94608000 future:-86400 + do + GIT_COMMITTER_DATE="@$((now - ${age#*:})) +0000" \ + git tag -a -m ${age%%:*} ${age%%:*} || return 1 + done ) ' @@ -40,6 +49,34 @@ test_expect_success 'relative dates are on by default' ' grep "class=.age-" tmp ' +test_expect_success 'each age bucket counts in its own unit' ' + daterc && + cgit_ok daterc "url=dated/refs/" >tmp && + grep ">mins.*" tmp && + grep ">hours.*" tmp && + grep ">days.*" tmp && + grep ">weeks.*" tmp && + grep ">months.*" tmp && + grep ">years.*" tmp +' + +test_expect_success 'a date past now reads as no age at all' ' + daterc && + cgit_ok daterc "url=dated/refs/" >tmp && + grep ">future.*" tmp +' + +# The age is what shows, while the element keeps the date itself, strict in +# the attribute a machine reads and plain in the one a reader hovers over. +test_expect_success 'an age keeps the date it stands for' ' + iso=$(git -C repos/dated for-each-ref --format="%(taggerdate:iso8601)" refs/tags/years) && + strict=$(git -C repos/dated for-each-ref --format="%(taggerdate:iso-strict)" refs/tags/years) && + test -n "$iso" && + daterc && + cgit_ok daterc "url=dated/refs/" >tmp && + grep "" tmp +' + test_expect_success 'enable-relative-dates=0 shows a calendar date' ' daterc "enable-relative-dates=0" && cgit_rc daterc "url=dated/refs/" >tmp && -- cgit 2.12.1