Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
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.
| -rwxr-xr-x | tests/t0107-diff.sh | 88 |
1 file changed, 74 insertions, 14 deletions
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 "<a href=./foo/tree/file-5?id=" tmp' -test_expect_success 'find added file' 'grep "new file mode 100644" tmp' - -test_expect_success 'find hunk header' ' - grep "<div class=.hunk.>@@ -0,0 +1 @@</div>" 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 "<a href=./foo/tree/file-5?id=" tmp && + grep "new file mode 100644" tmp && + grep "<div class=.hunk.>@@ -0,0 +1 @@</div>" tmp && grep "<div class=.add.>+5</div>" 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 "<table class=.diff. role=.presentation.>" 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 "<div class=.error.>Not a commit: $tree</div>" tmp && cgit_url "foo/diff/&id2=$tree" >tmp && + grep "^Status: 404" tmp && grep "<div class=.error.>Not a commit: $tree</div>" tmp ' +test_expect_success 'a path limits the diff and the stat says so' ' + cgit_ok_url "foo/diff/file-5" >tmp && + grep "Diffstat</a> (limited to .file-5.)</div>" 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 "<div class=.diffstat-summary.>2 files changed, 2 insertions, 0 deletions</div>" 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<br>new file mode 100644" tmp && + grep "<div class=.diffstat-summary.>1 file changed, 1 insertion, 0 deletions</div>" 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<br>deleted file mode 100644" tmp && + grep "<td class=.mode.>-rwxr-xr-x<span class=.modechange.>\[-rw-r--r--\]</span></td>" tmp && + grep "<br>index [0-9a-f]*\.\.[0-9a-f]* 100644\.\.100755<br>" tmp && + grep "<td class=.right.>bin</td><td class=.graph.>4 -> 4 bytes</td>" tmp && + grep "Binary files differ" tmp && + grep "<div class=.del.>-Subproject $one</div><div class=.add.>+Subproject $two</div>" 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 |
