Diff options
Diffstat (limited to '')
-rwxr-xr-xtests/t0112-stats.sh71
1 file changed, 42 insertions, 29 deletions
diff --git a/tests/t0112-stats.sh b/tests/t0112-stats.sh
index 7b08a6b..722a61c 100755
--- a/tests/t0112-stats.sh
+++ b/tests/t0112-stats.sh
@@ -28,50 +28,32 @@ test_expect_success 'set up a stats config' '
git commit --allow-empty -m fresh &&
git commit-graph write --reachable
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "max-stats=year" &&
- echo "repo.url=stat" &&
- echo "repo.path=$PWD/repos/pulse/.git"
- } >statsrc &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "max-stats=month" &&
- echo "repo.url=stat" &&
- echo "repo.path=$PWD/repos/pulse/.git"
- } >statmaxrc
+ cgitrc_repo statsrc stat max-stats=year "repo.path=$PWD/repos/pulse/.git" &&
+ cgitrc_repo statmaxrc stat max-stats=month "repo.path=$PWD/repos/pulse/.git"
'
-statq() { CGIT_CONFIG="$PWD/statsrc" QUERY_STRING="$1" cgit; }
-
test_expect_success 'stats tab appears when enabled' '
- statq "url=stat/" >tmp &&
+ cgit_rc statsrc "url=stat/" >tmp &&
grep ">stats</a>" tmp
'
test_expect_success 'stats page renders the authors table' '
- statq "url=stat/stats/" >tmp &&
+ cgit_rc statsrc "url=stat/stats/" >tmp &&
grep "<h2>Commits per author" tmp
'
-test_expect_success 'no language breakdown is rendered' '
- ! grep -i "language" tmp
-'
-
test_expect_success 'stat options sit above the content' '
tr -d "\n" <tmp | sed "s/<h2>Commits per author.*//" | grep "cgit-panel"
'
test_expect_success 'stats below a path stay a normal page' '
- statq "url=stat/stats/file-1" >tmp &&
+ cgit_rc statsrc "url=stat/stats/file-1" >tmp &&
grep "Status: 200" tmp &&
grep "<h2>Commits per author" tmp
'
test_expect_success 'max-stats=year offers all four periods' '
- statq "url=stat/stats/" >tmp &&
+ cgit_rc statsrc "url=stat/stats/" >tmp &&
grep "<option value=.w." tmp &&
grep "<option value=.m." tmp &&
grep "<option value=.q." tmp &&
@@ -79,21 +61,52 @@ test_expect_success 'max-stats=year offers all four periods' '
'
test_expect_success 'max-stats bounds the selectable periods' '
- CGIT_CONFIG="$PWD/statmaxrc" QUERY_STRING="url=stat/stats/&period=y" cgit >tmp &&
+ cgit_rc statmaxrc "url=stat/stats/&period=y" >tmp &&
grep "Statistics type disabled" tmp &&
- CGIT_CONFIG="$PWD/statmaxrc" QUERY_STRING="url=stat/stats/" cgit >tmp &&
+ cgit_rc statmaxrc "url=stat/stats/" >tmp &&
! grep "<option value=.q." tmp
'
# Each period buckets commits and labels its columns its own way, so every one
# gets a page of its own here.
test_expect_success 'every period renders its own columns' '
- statq "url=stat/stats/&period=m" >tmp &&
+ cgit_rc statsrc "url=stat/stats/&period=m" >tmp &&
grep -E "<th[^>]*>[A-Z][a-z][a-z] [0-9]{4}</th>" tmp &&
- statq "url=stat/stats/&period=q" >tmp &&
+ cgit_rc statsrc "url=stat/stats/&period=q" >tmp &&
grep -E "<th[^>]*>Q[1-4] [0-9]{4}</th>" tmp &&
- statq "url=stat/stats/&period=y" >tmp &&
+ cgit_rc statsrc "url=stat/stats/&period=y" >tmp &&
grep -E "<th[^>]*>[0-9]{4}</th>" tmp
'
+# The yearly window opens on the first of January three years back. cgit reads
+# the real clock, so the two commits sit either side of midnight on that day.
+test_expect_success 'the window opens at midnight on its first day' '
+ first=$(($(date -u +%Y) - 3)) &&
+ test_create_repo repos/edge &&
+ (
+ cd repos/edge &&
+ GIT_AUTHOR_NAME="Too Early" \
+ GIT_AUTHOR_DATE="$((first - 1))-12-31 23:59:59 +0000" \
+ GIT_COMMITTER_DATE="$((first - 1))-12-31 23:59:59 +0000" \
+ git commit --allow-empty -m before &&
+ GIT_AUTHOR_NAME="Early Bird" \
+ GIT_AUTHOR_DATE="$first-01-01 00:00:00 +0000" \
+ GIT_COMMITTER_DATE="$first-01-01 00:00:00 +0000" \
+ git commit --allow-empty -m first
+ ) &&
+ cgitrc_repo edgerc edge max-stats=year &&
+ cgit_rc edgerc "url=edge/stats/&period=y" >tmp &&
+ grep ">Early Bird<" tmp &&
+ ! grep ">Too Early<" tmp
+'
+
+# A path starting with a colon would reach git as pathspec magic, which the
+# log, the feed and the patch page refuse as well.
+test_expect_success 'a path with pathspec magic is refused' '
+ cgit_rc statsrc "url=stat/stats/%3A%28icase%29FILE-1" >tmp &&
+ grep "^Status: 400" tmp &&
+ cgit_rc statsrc "url=stat/stats/file-1" >tmp &&
+ grep "^Status: 200" tmp
+'
+
test_done