From: ovhrb6ho1pnnv7lo@mailinator.com
To: git@vger.kernel.org
Subject: unexpected behaviour for "git diff --word-diff"
Date: Thu, 8 May 2014 18:39:49 +0200 [thread overview]
Message-ID: <20140508163949.GA1801@else-banjo.ktb.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 715 bytes --]
Hi,
I get an unexpected behaviour for "git diff --word-diff" if 2 adjacent lines
start and end with the same letter. I tried versions 1.7.9 and 1.9.0.
Attached is a script with 7 examples. For each example, a file with 2 lines is
compared to a file with the same lines, only 1 or 2 letters appended in each
line. Each example is executed 4 times: with and without --word-diff-regex=.,
and with and without -R. The script prints the result of the diff of the 2
files. Just below it also prints the result of a counterexample: the same 2
lines with 2 lines (1 was sometimes not enough) of "xxx" between them.
Only for tests 5c,d and 6c,d the result matches the result for the
counterexample.
Kind regards,
Thomas
[-- Attachment #2: test.git-diff --]
[-- Type: text/plain, Size: 3068 bytes --]
#!/bin/bash
##########################################
# execute 6 tests with counterexamples for "git diff --word-diff"
#
# (optional) argument: (sub-)test to execute, e.g. "1" or "3b"
# if none/empty: all tests are executed
#
# common header lines of the diff output are removed
##########################################
# init global variables:
# command to execute
GITDIFF="git diff --word-diff=plain --no-index --no-color"
# names of test files
file1=$0.1
file2=$0.2
file1x=$0.1x
file2x=$0.2x
# wanted test case, info to print
want=
info=
##########################################
# do_sub_test()
# call "git diff" for a sub-test and its counterexample
# common header lines of the diff output are removed
do_sub_test() {
curr_sub_test=$1
# set additional arguments for git diff
case $curr_sub_test in
*a) add_args=;;
*b) add_args=-R;;
*c) add_args=--word-diff-regex=.;;
*d) add_args="-R --word-diff-regex=.";;
esac
# execute original test
echo " -- test" $curr_sub_test: DIFF $add_args: $info
$GITDIFF $add_args $file1 $file2 | sed '/^[di+-]\|^@@ -1,2 +1,2 /d'
# execute counterexample
echo " -- expected:"
$GITDIFF $add_args $file1x $file2x | sed '/^[di+-]\|^xxx$\|^@@ -1,4 +1,4 /d'
}
##########################################
# do_test()
# create files for a test, call do_sub_test for wanted sub-test (or all)
do_test() {
curr_test=$1
line1=$2
line2=$3
append=$4
# create files for test
echo -e "$line1\n$line2" > $file1
echo -e "$line1$append\n$line2$append" > $file2
# create files for counterexample
echo -e "$line1\nxxx\nxxx\n$line2" > $file1x
echo -e "$line1$append\nxxx\nxxx\n$line2$append" > $file2x
info="append '$append' to '$line1' <nl> '$line2'"
# call do_sub_test for wanted sub-test (or all)
case $want in ?a|?|'') do_sub_test ${curr_test}a;; esac
case $want in ?b|?|'') do_sub_test ${curr_test}b;; esac
case $want in ?c|?|'') do_sub_test ${curr_test}c;; esac
case $want in ?d|?|'') do_sub_test ${curr_test}d;; esac
}
##########################################
# do_all_tests()
# call do_test for wanted test (or all)
do_all_tests() {
want=$1
case $want in 1*|'') do_test 1 '' .a . ;; esac
case $want in 2*|'') do_test 2 . .a . ;; esac
case $want in 3*|'') do_test 3 '' a a ;; esac
case $want in 4*|'') do_test 4 a aa a ;; esac
case $want in 5*|'') do_test 5 '' a b ;; esac
case $want in 6*|'') do_test 6 '' a 'b ';; esac
}
##########################################
# main()
# prepare cleanup, do tests
# clean up test files on exit and some signals
trap "rm -f $file1 $file2 $file1x $file2x; exit" 0 1 2 15
usage="Usage: $0 [<testcase>]\n <testcase> can be [1-6][a-d] or empty\n e.g. '$0 1' or '$0 3b'"
case $1 in
[1-6]|[1-6][a-d]|'')
;;
-h|--help)
echo -e $usage
exit
;;
*)
echo -e "Error: invalid argument '$1'\n$usage"
exit
;;
esac
# do tests
do_all_tests $1
reply other threads:[~2014-05-08 16:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140508163949.GA1801@else-banjo.ktb.de \
--to=ovhrb6ho1pnnv7lo@mailinator.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).