From 45294f88af9e499dc97434fe89c9e356888b0e00 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 13:16:02 -1000 Subject: 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. --- tests/t0107-diff.sh | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) (limited to 'tests/t0107-diff.sh') 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 "This diff is too large to be rendered inline. View it on its own page." 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 "file-5" tmp && + grep "
1 file changed, 1 insertion, 0 deletions
" tmp && + ! grep "class=.hunk." tmp && + ! grep "" 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 "
@@ -1 +1 @@
" 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 "
@@ -47,7 +47,7 @@
" tmp && + cgit_ok widerc "url=wide/diff/&context=1" >tmp && + grep "
@@ -49,3 +49,3 @@
" tmp && + cgit_ok widerc "url=wide/diff/&context=999" >tmp && + grep "
@@ -10,81 +10,81 @@
" 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 "
" tmp && + cgit_ok ssrc "url=wide/diff/&dt=0" >tmp && + grep "
" 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 " (renamed from a.txt)" tmp && + grep " (renamed from b.txt)" tmp && + cgitrc_repo renamesrc renames rename-limit=1 && + cgit_ok renamesrc "url=renames/diff/" >tmp && + grep "diff --git a/c.txt b/c.txt
new file mode 100644" tmp && + grep "diff --git a/a.txt b/a.txt
deleted file mode 100644" tmp && + ! grep "renamed from" tmp && + cgitrc_repo renamesrc renames rename-limit=0 && + cgit_ok renamesrc "url=renames/diff/" >tmp && + grep " (renamed from a.txt)" tmp && + grep " (renamed from b.txt)" 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 -- cgit 2.12.1