Diff options
Diffstat (limited to '')
| -rwxr-xr-x | tests/t0107-diff.sh | 49 |
1 file changed, 21 insertions, 28 deletions
diff --git a/tests/t0107-diff.sh b/tests/t0107-diff.sh index f058246..e173d00 100755 --- a/tests/t0107-diff.sh +++ b/tests/t0107-diff.sh @@ -1,8 +1,8 @@ #!/bin/sh -# The diff page, unified or side by side under dt=1. The first checks read +# 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 +# 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. @@ -22,6 +22,16 @@ test_expect_success 'find added line' ' grep "<div class=.add.>+5</div>" tmp ' +# A revision that names no commit is quoted the way the request wrote it, as +# the commit and patch pages quote it, on either side of the diff. +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 "<div class=.error.>Not a commit: $tree</div>" tmp && + cgit_url "foo/diff/&id2=$tree" >tmp && + grep "<div class=.error.>Not a commit: $tree</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 @@ -36,24 +46,19 @@ test_expect_success 'set up a repo with single-line hunks' ' printf "ONLY\n" >one.txt && git commit -am "change one.txt" ) && - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "repo.url=hunk1" && - echo "repo.path=$PWD/repos/hunk1/.git" - } >hunk1rc && + cgitrc_repo hunk1rc hunk1 && git -C repos/hunk1 diff HEAD~1 HEAD >raw.diff && grep "^@@ -1 +1 @@" raw.diff ' test_expect_success 'ssdiff numbers a comma-less hunk from its real line' ' - CGIT_CONFIG="$PWD/hunk1rc" QUERY_STRING="url=hunk1/diff/&dt=1" cgit >tmp && + cgit_rc hunk1rc "url=hunk1/diff/&dt=1" >tmp && grep "#n1.>1</a>" tmp && ! grep "#n0.>0</a>" tmp ' test_expect_success 'ssdiff still numbers a hunk that carries a length' ' - cgit_query "url=foo/diff&dt=1" >tmp && + cgit_url "foo/diff&dt=1" >tmp && grep "#n1.>1</a>" tmp ' @@ -75,16 +80,11 @@ test_expect_success 'set up a repo with shrinking changed lines' ' s=s sprintf(\"%c\",c)} print s}}" >lines.txt && git commit -am "change every line" ) && - { - echo "virtual-root=/" && - echo "cache-size=0" && - echo "repo.url=lcs" && - echo "repo.path=$PWD/repos/lcs/.git" - } >lcsrc + cgitrc_repo lcsrc lcs ' test_expect_success 'every changed pair gets both a del and an add span' ' - CGIT_CONFIG="$PWD/lcsrc" QUERY_STRING="url=lcs/diff/&dt=1" cgit >tmp && + cgit_rc lcsrc "url=lcs/diff/&dt=1" >tmp && deletions=$(grep -o "<span class=.del.>" tmp | wc -l) && additions=$(grep -o "<span class=.add.>" tmp | wc -l) && test "$deletions" -gt 0 && @@ -93,22 +93,15 @@ test_expect_success 'every changed pair gets both a del and an add span' ' test_expect_success 'stripping the highlight leaves every line intact' ' sed -e "s/<[^>]*>//g" tmp >plain.out && - git -C repos/lcs show HEAD~1:lines.txt >old.txt && - git -C repos/lcs show HEAD:lines.txt >new.txt && - while read -r line - do - grep -qF "$line" plain.out || { - echo "missing old line: $line" - return 1 - } - done <old.txt && + git -C repos/lcs show HEAD~1:lines.txt >lines && + git -C repos/lcs show HEAD:lines.txt >>lines && while read -r line do grep -qF "$line" plain.out || { - echo "missing new line: $line" + echo "missing line: $line" return 1 } - done <new.txt + done <lines ' test_done |
