diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Add `enable-relative-dates` and `date-format`
Diffstat (limited to 'tests/t0203-dates.sh')
| -rwxr-xr-x | tests/t0203-dates.sh | 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 91 insertions, 0 deletions
diff --git a/tests/t0203-dates.sh b/tests/t0203-dates.sh new file mode 100755 index 0000000..1bd6253 --- /dev/null +++ b/tests/t0203-dates.sh @@ -0,0 +1,91 @@ +#!/bin/sh + +test_description='Check the date display options' +. ./setup.sh + +# An old commit and a fresh one, so a single log page exercises both the +# relative rendering and the calendar fallback past the two week cutoff. +test_expect_success 'set up a dated repo' ' + mkrepo repos/dated 1 && + ( + cd repos/dated && + 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 + ) +' + +# Each argument is written as one extra config line. +daterc() { + { + echo "virtual-root=/" + echo "cache-size=0" + printf '%s\n' "$@" + echo "repo.url=dated" + echo "repo.path=$PWD/repos/dated/.git" + } >daterc +} + +dateq() { CGIT_CONFIG="$PWD/daterc" QUERY_STRING="$1" cgit; } + +test_expect_success 'relative dates are on by default' ' + daterc && + dateq "url=dated/refs/" >tmp && + grep "class=.age-" tmp +' + +test_expect_success 'enable-relative-dates=0 shows a calendar date' ' + daterc "enable-relative-dates=0" && + dateq "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" && + dateq "" >tmp && + ! grep "class=.age-" tmp && + dateq "url=dated/log/" >tmp && + ! grep "class=.age-" tmp +' + +test_expect_success 'date-format selects the calendar format' ' + daterc "enable-relative-dates=0" "date-format=iso8601" && + dateq "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' ' + daterc "enable-relative-dates=0" "date-format=format:%Y/%m/%d" && + dateq "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 'an unknown date-format falls back to short' ' + daterc "enable-relative-dates=0" "date-format=nonsense" && + dateq "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:" && + dateq "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 'date-format still formats the log fallback' ' + daterc "date-format=rfc2822" && + dateq "url=dated/log/" >tmp && + grep "class=.age-" tmp && + grep ">[A-Z][a-z][a-z], [0-9]* Apr 2005 " tmp +' + +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) && + dateq "url=dated/commit/&id=$sha" >tmp && + grep "2005-04-07 [0-9:]* +0000" tmp && + ! grep "Apr 2005" tmp +' + +test_done |
