From 5bf3bd660fb52d4587003d504a959c74e59413b0 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 13:53:23 -1000 Subject: Check the rest of what the diff page prints Nothing checked a deleted file, a change of mode, a binary file, a submodule, a path, a range between two commits or the root commit on the HTML page, nor the 404 a revision that is no commit gets. The first checks were steps titled as actions that read one page in turn, so each now fetches its own. --- tests/t0107-diff.sh | 88 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 14 deletions(-) (limited to 'tests/t0107-diff.sh') diff --git a/tests/t0107-diff.sh b/tests/t0107-diff.sh index 6caf539..d0296d5 100755 --- a/tests/t0107-diff.sh +++ b/tests/t0107-diff.sh @@ -1,30 +1,29 @@ #!/bin/sh # The diff page, unified or side-by-side under dt=1. The first checks read -# the markup for one added file in the fixture repository. The rest build -# repositories of their own, shaped for the side-by-side renderer's two -# trickiest cases, a hunk covering a single line and a file where every -# line changed. +# the markup for one added file in the fixture repository, then a path, a +# range, the root commit and a commit holding every kind of change the +# unified view words differently. The rest build repositories of their own, +# shaped for the side-by-side renderer's line numbers and character marking, +# for the options a request or the config sets, and for a renamed or +# followed file. test_description='Check content on diff page' . ./setup.sh -test_expect_success 'generate foo/diff' 'cgit_url "foo/diff" >tmp' -test_expect_success 'find diff header' 'grep "a/file-5 b/file-5" tmp' -test_expect_success 'find blob link' 'grep "@@ -0,0 +1 @@" tmp -' - -test_expect_success 'find added line' ' +test_expect_success 'an added file shows its header, links and line' ' + cgit_ok_url "foo/diff" >tmp && + grep "a/file-5 b/file-5" tmp && + grep "@@ -0,0 +1 @@" tmp && grep "
+5
" tmp ' # The unified diff sits in a single cell, which holds the files together # rather than tabulating them, so a screen reader is told it is layout. test_expect_success 'the unified diff table is read as layout' ' + cgit_ok_url "foo/diff" >tmp && grep "" tmp ' @@ -33,11 +32,72 @@ test_expect_success 'the unified diff table is read as layout' ' test_expect_success 'a tree on either side is named as the request gave it' ' tree=$(git -C repos/foo rev-parse --short HEAD^{tree}) && cgit_url "foo/diff/&id=$tree" >tmp && + grep "^Status: 404" tmp && grep "
Not a commit: $tree
" tmp && cgit_url "foo/diff/&id2=$tree" >tmp && + grep "^Status: 404" tmp && grep "
Not a commit: $tree
" tmp ' +test_expect_success 'a path limits the diff and the stat says so' ' + cgit_ok_url "foo/diff/file-5" >tmp && + grep "Diffstat (limited to .file-5.)" tmp && + grep "diff --git a/file-5 b/file-5" tmp +' + +test_expect_success 'a diff between two named commits spans both' ' + id=$(git -C repos/foo rev-parse HEAD) && + id2=$(git -C repos/foo rev-parse HEAD~2) && + cgit_ok_url "foo/diff&id=$id&id2=$id2" >tmp && + grep "diff --git a/file-4 b/file-4" tmp && + grep "diff --git a/file-5 b/file-5" tmp && + grep "
2 files changed, 2 insertions, 0 deletions
" tmp +' + +test_expect_success 'the root commit is diffed against nothing' ' + root=$(git -C repos/foo rev-list --max-parents=0 HEAD) && + cgit_ok_url "foo/diff&id=$root" >tmp && + grep "diff --git a/file-1 b/file-1
new file mode 100644" tmp && + grep "
1 file changed, 1 insertion, 0 deletions
" tmp +' + +# One commit deletes a file, changes the mode of another, changes a binary +# file and moves a submodule to another commit. The changes are staged one by +# one, since commit -a would take the submodule for deleted. +test_expect_success 'set up a commit of every kind of change' ' + mkrepo repos/kinds 1 && + ( + cd repos/kinds && + one=$(git rev-parse HEAD) && + echo gone >gone.txt && + echo mode >mode.sh && + printf "\000old" >bin.dat && + git add gone.txt mode.sh bin.dat && + git update-index --add --cacheinfo 160000,$one,sub && + git commit -m "add the files" && + two=$(git rev-parse HEAD) && + git rm -q gone.txt && + git update-index --chmod=+x mode.sh && + printf "\000new" >bin.dat && + git add bin.dat && + git update-index --cacheinfo 160000,$two,sub && + git commit -m "change the files" + ) && + cgitrc_repo kindsrc kinds +' + +test_expect_success 'each kind of change is worded as git words it' ' + one=$(git -C repos/kinds rev-parse HEAD~2) && + two=$(git -C repos/kinds rev-parse HEAD~1) && + cgit_ok kindsrc "url=kinds/diff/" >tmp && + grep "diff --git a/gone.txt b/gone.txt
deleted file mode 100644" tmp && + grep "" tmp && + grep "
index [0-9a-f]*\.\.[0-9a-f]* 100644\.\.100755
" tmp && + grep "" tmp && + grep "Binary files differ" tmp && + grep "
-Subproject $one
+Subproject $two
" tmp +' + # git writes a hunk length only when the hunk spans more than one line, so the # header for a single line reads "@@ -1 +1 @@" with no comma in it. Requiring # that comma left those hunks numbered from zero, which dropped the line -- cgit 2.12.1
-rwxr-xr-x\[-rw-r--r--\]bin4 -> 4 bytes