Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Check the dates each format and timezone shows
The index and log checks were absence-only, so a page with no dates
passed, and date-format=local ran under UTC on a commit made at +0000,
where local time and the commit's own read the same. local-time, the
-local formats and the rule keeping a listed date on one line had no
test.
| -rwxr-xr-x | tests/t0203-dates.sh | 86 |
1 file changed, 61 insertions, 25 deletions
diff --git a/tests/t0203-dates.sh b/tests/t0203-dates.sh index fc21758..36b11df 100755 --- a/tests/t0203-dates.sh +++ b/tests/t0203-dates.sh @@ -1,9 +1,9 @@ #!/bin/sh # Checks how cgit shows a commit date, which is either an age relative to now -# or a calendar date in the format the config names. The config is rewritten -# between cases so that each one names only the settings it is about and -# leaves the rest at their defaults. +# or a calendar date in the format the config names, and in which timezone. +# The config is rewritten between cases so that each one names only the +# settings it is about and leaves the rest at their defaults. test_description='Check the date display options' . ./setup.sh @@ -34,18 +34,12 @@ test_expect_success 'set up a dated repo' ' ' daterc() { - { - echo "virtual-root=/" - echo "cache-size=0" - printf '%s\n' "$@" - echo "repo.url=dated" - echo "repo.path=$PWD/repos/dated/.git" - } >daterc + cgitrc_repo daterc dated "$@" } test_expect_success 'relative dates are on by default' ' daterc && - cgit_rc daterc "url=dated/refs/" >tmp && + cgit_ok daterc "url=dated/refs/" >tmp && grep "class=.age-" tmp ' @@ -79,56 +73,90 @@ test_expect_success 'an age keeps the date it stands for' ' test_expect_success 'enable-relative-dates=0 shows a calendar date' ' daterc "enable-relative-dates=0" && - cgit_rc daterc "url=dated/refs/" >tmp && + cgit_ok daterc "url=dated/refs/" >tmp && ! grep "class=.age-" tmp && grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp ' test_expect_success 'the index and log columns follow the same flag' ' daterc "enable-relative-dates=0" && - cgit_rc daterc "" >tmp && + cgit_ok daterc "" >tmp && + grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp && ! grep "class=.age-" tmp && - cgit_rc daterc "url=dated/log/" >tmp && + cgit_ok daterc "url=dated/log/" >tmp && + grep ">2005-04-07<" tmp && ! grep "class=.age-" tmp ' test_expect_success 'date-format selects the calendar format' ' daterc "enable-relative-dates=0" "date-format=iso8601" && - cgit_rc daterc "url=dated/refs/" >tmp && + cgit_ok daterc "url=dated/refs/" >tmp && grep ">[0-9-]* [0-9][0-9]:[0-9][0-9]:[0-9][0-9] +0000<" tmp ' -test_expect_success 'date-format accepts a strftime format' ' +test_expect_success 'date-format accepts a strftime format, on the index too' ' daterc "enable-relative-dates=0" "date-format=format:%Y/%m/%d" && - cgit_rc daterc "url=dated/refs/" >tmp && + cgit_ok daterc "url=dated/refs/" >tmp && + grep ">[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]<" tmp && + cgit_ok daterc "" >tmp && grep ">[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]<" tmp ' test_expect_success 'an unknown date-format falls back to short' ' daterc "enable-relative-dates=0" "date-format=nonsense" && - cgit_rc daterc "url=dated/refs/" >tmp && + cgit_ok daterc "url=dated/refs/" >tmp && grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp && daterc "enable-relative-dates=0" "date-format=format:" && - cgit_rc daterc "url=dated/refs/" >tmp && + cgit_ok daterc "url=dated/refs/" >tmp && grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp ' test_expect_success 'a date-format git would refuse falls back to short' ' daterc "enable-relative-dates=0" "date-format=local-local" && - cgit_rc daterc "url=dated/refs/" >tmp && - grep "^Status: 200" tmp && + cgit_ok daterc "url=dated/refs/" >tmp && grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]<" tmp ' +# The tests run under TZ=UTC, and the first commit was made at +0200, so the +# local time differs from the commit's own by two hours. test_expect_success 'date-format=local is the default format in local time' ' daterc "enable-relative-dates=0" "date-format=local" && - cgit_rc daterc "url=dated/refs/" >tmp && - grep ">[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [0-9:]* [0-9]*<" tmp + cgit_ok daterc "url=dated/log/" >tmp && + grep ">Fri Apr 1 11:14:15 2005<" tmp +' + +# A POSIX timezone string needs no zone files, so EST5 works anywhere. +test_expect_success 'a -local date-format shows the server timezone' ' + daterc "enable-relative-dates=0" "date-format=iso8601-local" && + ( + TZ=EST5 && + export TZ && + cgit_ok daterc "url=dated/log/" + ) >tmp && + grep ">2005-04-07 17:13:13 -0500<" tmp +' + +test_expect_success 'local-time shows commit times in the server timezone' ' + sha=$(git -C repos/dated rev-parse HEAD~1) && + daterc "local-time=1" && + ( + TZ=EST5 && + export TZ && + cgit_ok daterc "url=dated/commit/&id=$sha" + ) >tmp && + grep ">2005-04-07 17:13:13 -0500<" tmp && + daterc && + ( + TZ=EST5 && + export TZ && + cgit_ok daterc "url=dated/commit/&id=$sha" + ) >tmp && + grep ">2005-04-07 22:13:13 +0000<" tmp ' test_expect_success 'date-format still formats the log fallback' ' daterc "date-format=rfc2822" && - cgit_rc daterc "url=dated/log/" >tmp && + cgit_ok daterc "url=dated/log/" >tmp && grep "class=.age-" tmp && grep ">[A-Z][a-z][a-z], [0-9]* Apr 2005 " tmp ' @@ -136,9 +164,17 @@ test_expect_success 'date-format still formats the log fallback' ' test_expect_success 'date-format leaves the commit page on ISO 8601' ' daterc "date-format=rfc2822" && sha=$(git -C repos/dated rev-parse HEAD~1) && - cgit_rc daterc "url=dated/commit/&id=$sha" >tmp && + cgit_ok daterc "url=dated/commit/&id=$sha" >tmp && grep "2005-04-07 [0-9:]* +0000" tmp && ! grep "Apr 2005" tmp ' +# Only a browser shows the wrap itself, so this checks the rule against it. +test_expect_success 'a date in a listing stays on one line' ' + sed -n "/^div#cgit time.age-mins,$/,/^}/p" \ + "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" >rule && + grep "^div#cgit table.list time {$" rule && + grep "^ white-space: nowrap;$" rule +' + test_done |
