Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Test the diff options a request or config sets
None of dt=2, ignorews, context and its cap, side-by-side-diffs or
rename-limit had a test anywhere in the suite, nor the 0 that the
MANUAL says lifts the rename limit.
Diffstat (limited to 'tests/t0107-diff.sh')
| -rwxr-xr-x | tests/t0107-diff.sh | 94 |
1 file changed, 94 insertions, 0 deletions
diff --git a/tests/t0107-diff.sh b/tests/t0107-diff.sh index f069894..2560c42 100755 --- a/tests/t0107-diff.sh +++ b/tests/t0107-diff.sh @@ -223,6 +223,100 @@ test_expect_success 'a side-by-side diff past max-diff-lines is cut short' ' grep "<tr><td colspan=.4. class=.truncated.>This diff is too large to be rendered inline. <a href=./cells/diff/long.txt?dt=1.>View it on its own page</a>.</td></tr>" tmp ' +# A stat limited to one file is no use, so the file links leave dt=2 behind. +test_expect_success 'dt=2 shows the diffstat alone' ' + cgit_ok_url "foo/diff&dt=2" >tmp && + grep "<td class=.add.><a href=./foo/diff/file-5.>file-5</a></td>" tmp && + grep "<div class=.diffstat-summary.>1 file changed, 1 insertion, 0 deletions</div>" tmp && + ! grep "class=.hunk." tmp && + ! grep "<table class=.diff. role=.presentation.>" tmp +' + +test_expect_success 'set up a change to whitespace alone' ' + mkrepo repos/space 1 && + ( + cd repos/space && + echo "a b" >space.txt && + git add space.txt && + git commit -m "add space.txt" && + echo "a b" >space.txt && + git commit -am "widen space.txt" + ) && + cgitrc_repo spacerc space +' + +test_expect_success 'ignorews=1 hides a change to whitespace alone' ' + cgit_ok spacerc "url=space/diff/" >tmp && + grep "<div class=.hunk.>@@ -1 +1 @@</div>" tmp && + cgit_ok spacerc "url=space/diff/&ignorews=1" >tmp && + grep "diff --git a/space.txt b/space.txt" tmp && + ! grep "class=.hunk." tmp +' + +# The context is capped, since context lines do not count against +# max-diff-lines and an unbounded width would render the whole blob. +test_expect_success 'context sets the lines around a change, up to a cap' ' + mkrepo repos/wide 1 && + ( + cd repos/wide && + test_seq 1 100 >wide.txt && + git add wide.txt && + git commit -m "add wide.txt" && + test_seq 1 100 | sed s/^50$/fifty/ >wide.txt && + git commit -am "change wide.txt" + ) && + cgitrc_repo widerc wide && + cgit_ok widerc "url=wide/diff/" >tmp && + grep "<div class=.hunk.>@@ -47,7 +47,7 @@</div>" tmp && + cgit_ok widerc "url=wide/diff/&context=1" >tmp && + grep "<div class=.hunk.>@@ -49,3 +49,3 @@</div>" tmp && + cgit_ok widerc "url=wide/diff/&context=999" >tmp && + grep "<div class=.hunk.>@@ -10,81 +10,81 @@</div>" tmp +' + +test_expect_success 'side-by-side-diffs=1 makes side by side the default' ' + cgitrc_repo ssrc wide side-by-side-diffs=1 && + cgit_ok ssrc "url=wide/diff/" >tmp && + grep "<table class=.ssdiff.>" tmp && + cgit_ok ssrc "url=wide/diff/&dt=0" >tmp && + grep "<table class=.diff. role=.presentation.>" tmp +' + +# Exact renames are found whatever the limit, so both of these change a line. +# Two sources against two destinations is past a limit of one, and 0 sets no +# limit at all. +test_expect_success 'set up two renames that are not exact' ' + mkrepo repos/renames 1 && + ( + cd repos/renames && + test_seq 1 10 >a.txt && + test_seq 11 20 >b.txt && + git add a.txt b.txt && + git commit -m "add a.txt and b.txt" && + git mv a.txt c.txt && + git mv b.txt d.txt && + echo more >>c.txt && + echo more >>d.txt && + git commit -am "rename both" + ) +' + +test_expect_success 'rename-limit bounds the renames a diff looks for' ' + cgitrc_repo renamesrc renames && + cgit_ok renamesrc "url=renames/diff/" >tmp && + grep "</a> (renamed from a.txt)</td>" tmp && + grep "</a> (renamed from b.txt)</td>" tmp && + cgitrc_repo renamesrc renames rename-limit=1 && + cgit_ok renamesrc "url=renames/diff/" >tmp && + grep "diff --git a/c.txt b/c.txt<br>new file mode 100644" tmp && + grep "diff --git a/a.txt b/a.txt<br>deleted file mode 100644" tmp && + ! grep "renamed from" tmp && + cgitrc_repo renamesrc renames rename-limit=0 && + cgit_ok renamesrc "url=renames/diff/" >tmp && + grep "</a> (renamed from a.txt)</td>" tmp && + grep "</a> (renamed from b.txt)</td>" tmp +' + # The diffstat links a renamed file by its new name, and so does the log of # that file, but the old name lies outside a diff limited to the new one. That # diff runs over the whole commit to find the rename, so the commit changes |
