Diff options
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/t0112-stats.sh | 70 |
1 file changed, 60 insertions, 10 deletions
diff --git a/tests/t0112-stats.sh b/tests/t0112-stats.sh index 4b45ee8..9bd8b7c 100755 --- a/tests/t0112-stats.sh +++ b/tests/t0112-stats.sh @@ -1,9 +1,9 @@ #!/bin/sh # Checks the per repository statistics page, which stays off until max-stats -# turns it on and then reports commits per author. A second config sets a -# finer max-stats so that what it takes out of the period selector is covered -# as well. +# turns it on and then counts each author's commits over the last four +# periods, busiest first. A second config sets a finer max-stats so that what +# it takes out of the period selector is covered as well. test_description='Check the statistics page' . ./setup.sh @@ -17,15 +17,40 @@ test_expect_success 'stats are off by default' ' ! grep ">stats</a>" tmp ' -# The authors table counts only recent periods, so the fixture needs a commit -# dated now to sit beside the 2005 dates the shared repositories carry. +# Makes the given number of empty commits by the named author. +author_commits() { + i=0 && + while test $i -lt $2 + do + GIT_AUTHOR_NAME="$1" git commit --allow-empty -m "$1 $i" && + i=$((i + 1)) || return 1 + done +} + +# The authors table counts only recent periods, so beside the 2005 commits of +# mkrepo the fixture has commits stamped now. Each author makes a different +# number of them, in the reverse of the order of their names, so the table +# has to sort by count. One of Gil's commits comes in through a merge, which +# counts for nobody. The walk releases each commit as it goes, which a commit +# read from a commit graph has to survive, so the fixture writes one. test_expect_success 'set up a stats config' ' mkrepo repos/pulse 2 && ( cd repos/pulse && - 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 checkout -b side && + author_commits "Gil Seven" 1 && + git checkout - && + echo ada >ada.txt && + git add ada.txt && + GIT_AUTHOR_NAME="Ada One" git commit -m "add ada.txt" && + author_commits "Ben Two" 2 && + author_commits "Cy Three" 3 && + author_commits "Di Four" 4 && + author_commits "Ed Five" 5 && + author_commits "Flo Six" 6 && + author_commits "Gil Seven" 6 && + GIT_AUTHOR_NAME="Mo Merger" git merge --no-ff -m merge side && git commit-graph write --reachable ) && cgitrc_repo statsrc stat max-stats=year "repo.path=$PWD/repos/pulse/.git" && @@ -38,8 +63,33 @@ test_expect_success 'stats tab appears when enabled' ' ' test_expect_success 'stats page renders the authors table' ' - cgit_rc statsrc "url=stat/stats/" >tmp && - grep "<h2>Commits per author" tmp + cgit_ok statsrc "url=stat/stats/" >tmp && + grep "<h2>Commits per author per week</h2>" tmp +' + +# Only the sums are compared, since a run that crosses into a new week moves +# the commits from one column to the next. +test_expect_success 'each author is counted and the busiest comes first' ' + cgit_ok statsrc "url=stat/stats/" >tmp && + sed -n "s/^<tr><td class=.left.>\([^<]*\)<\/td>.*<td class=.sum.>\([0-9]*\)<\/td><\/tr>$/\1 \2/p" tmp >actual && + test_write_lines "Gil Seven 7" "Flo Six 6" "Ed Five 5" "Di Four 4" \ + "Cy Three 3" "Ben Two 2" "Ada One 1" >expect && + test_cmp expect actual && + grep "^<tr><td class=.left.>Ada One</td>\(<td>[0-9]*</td>\)\{4\}<td class=.sum.>1</td></tr>$" tmp && + grep "^<tr><td class=.total.>Total</td>\(<td class=.sum.>[0-9]*</td>\)\{4\}<td class=.sum.>28</td></tr>$" tmp +' + +test_expect_success 'a merge counts for nobody' ' + cgit_ok statsrc "url=stat/stats/" >tmp && + grep "<td class=.left.>Gil Seven</td>.*<td class=.sum.>7</td>" tmp && + ! grep ">Mo Merger<" tmp +' + +test_expect_success 'the authors past the row count share one row' ' + cgit_ok statsrc "url=stat/stats/&ofs=1" >tmp && + sed -n "s/^<tr><td class=.left.>\([^<]*\)<\/td>.*<td class=.sum.>\([0-9]*\)<\/td><\/tr>$/\1 \2/p" tmp >actual && + test_write_lines "Gil Seven 7" "Others (6) 21" >expect && + test_cmp expect actual ' # The table scrolls sideways on a narrow window with nothing in it a keyboard |
