Merge branch 'ep/do-not-feed-a-pointer-to-array-size'
[gitweb.git] / t / annotate-tests.sh
index 015acabf30f6fdf11dc6d6a7f2b40f8487f27db6..f5c01758ca38b58fc10e30cfac81be5becb0316b 100644 (file)
@@ -1,6 +1,17 @@
 # This file isn't used as a test script directly, instead it is
 # sourced from t8001-annotate.sh and t8002-blame.sh.
 
+if test_have_prereq MINGW
+then
+  sanitize_L () {
+       echo "$1" | sed 'sX\(^-L\|,\)\^\?/X&\\;*Xg'
+  }
+else
+  sanitize_L () {
+       echo "$1"
+  }
+fi
+
 check_count () {
        head= &&
        file='file' &&
@@ -10,6 +21,7 @@ check_count () {
                case "$1" in
                -h) head="$2"; shift; shift ;;
                -f) file="$2"; shift; shift ;;
+               -L*) options="$options $(sanitize_L "$1")"; shift ;;
                -*) options="$options $1"; shift ;;
                *) break ;;
                esac
@@ -92,7 +104,7 @@ test_expect_success 'blame 2 authors + 1 branch2 author' '
 '
 
 test_expect_success 'merge branch1 & branch2' '
-       git pull . branch1
+       git merge branch1
 '
 
 test_expect_success 'blame 2 authors + 2 merged-in authors' '
@@ -116,6 +128,27 @@ test_expect_success 'blame evil merge' '
        check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1
 '
 
+test_expect_success 'blame huge graft' '
+       test_when_finished "git checkout branch2" &&
+       test_when_finished "rm -f .git/info/grafts" &&
+       graft= &&
+       for i in 0 1 2
+       do
+               for j in 0 1 2 3 4 5 6 7 8 9
+               do
+                       git checkout --orphan "$i$j" &&
+                       printf "%s\n" "$i" "$j" >file &&
+                       test_tick &&
+                       GIT_AUTHOR_NAME=$i$j GIT_AUTHOR_EMAIL=$i$j@test.git \
+                       git commit -a -m "$i$j" &&
+                       commit=$(git rev-parse --verify HEAD) &&
+                       graft="$graft$commit "
+               done
+       done &&
+       printf "%s " $graft >.git/info/grafts &&
+       check_count -h 00 01 1 10 1
+'
+
 test_expect_success 'setup incomplete line' '
        echo "incomplete" | tr -d "\\012" >>file &&
        GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" \
@@ -185,6 +218,26 @@ test_expect_success 'blame -L Y,X (undocumented)' '
        check_count -L6,3 B 1 B1 1 B2 1 D 1
 '
 
+test_expect_success 'blame -L -X' '
+       test_must_fail $PROG -L-1 file
+'
+
+test_expect_success 'blame -L 0' '
+       test_must_fail $PROG -L0 file
+'
+
+test_expect_success 'blame -L ,0' '
+       test_must_fail $PROG -L,0 file
+'
+
+test_expect_success 'blame -L ,+0' '
+       test_must_fail $PROG -L,+0 file
+'
+
+test_expect_success 'blame -L X,+0' '
+       test_must_fail $PROG -L1,+0 file
+'
+
 test_expect_success 'blame -L X,+1' '
        check_count -L3,+1 B2 1
 '
@@ -193,6 +246,14 @@ test_expect_success 'blame -L X,+N' '
        check_count -L3,+4 B 1 B1 1 B2 1 D 1
 '
 
+test_expect_success 'blame -L ,-0' '
+       test_must_fail $PROG -L,-0 file
+'
+
+test_expect_success 'blame -L X,-0' '
+       test_must_fail $PROG -L1,-0 file
+'
+
 test_expect_success 'blame -L X,-1' '
        check_count -L3,-1 B2 1
 '
@@ -255,6 +316,75 @@ test_expect_success 'blame -L ,Y (Y > nlines)' '
        test_must_fail $PROG -L,12345 file
 '
 
+test_expect_success 'blame -L multiple (disjoint)' '
+       check_count -L2,3 -L6,7 A 1 B1 1 B2 1 "A U Thor" 1
+'
+
+test_expect_success 'blame -L multiple (disjoint: unordered)' '
+       check_count -L6,7 -L2,3 A 1 B1 1 B2 1 "A U Thor" 1
+'
+
+test_expect_success 'blame -L multiple (adjacent)' '
+       check_count -L2,3 -L4,5 A 1 B 1 B2 1 D 1
+'
+
+test_expect_success 'blame -L multiple (adjacent: unordered)' '
+       check_count -L4,5 -L2,3 A 1 B 1 B2 1 D 1
+'
+
+test_expect_success 'blame -L multiple (overlapping)' '
+       check_count -L2,4 -L3,5 A 1 B 1 B2 1 D 1
+'
+
+test_expect_success 'blame -L multiple (overlapping: unordered)' '
+       check_count -L3,5 -L2,4 A 1 B 1 B2 1 D 1
+'
+
+test_expect_success 'blame -L multiple (superset/subset)' '
+       check_count -L2,8 -L3,5 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
+'
+
+test_expect_success 'blame -L multiple (superset/subset: unordered)' '
+       check_count -L3,5 -L2,8 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
+'
+
+test_expect_success 'blame -L /RE/ (relative)' '
+       check_count -L3,3 -L/fox/ B1 1 B2 1 C 1 D 1 "A U Thor" 1
+'
+
+test_expect_success 'blame -L /RE/ (relative: no preceding range)' '
+       check_count -L/dog/ A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1
+'
+
+test_expect_success 'blame -L /RE/ (relative: adjacent)' '
+       check_count -L1,1 -L/dog/,+1 A 1 E 1
+'
+
+test_expect_success 'blame -L /RE/ (relative: not found)' '
+       test_must_fail $PROG -L4,4 -L/dog/ file
+'
+
+test_expect_success 'blame -L /RE/ (relative: end-of-file)' '
+       test_must_fail $PROG -L, -L/$/ file
+'
+
+test_expect_success 'blame -L ^/RE/ (absolute)' '
+       check_count -L3,3 -L^/dog/,+2 A 1 B2 1
+'
+
+test_expect_success 'blame -L ^/RE/ (absolute: no preceding range)' '
+       check_count -L^/dog/,+2 A 1 B2 1
+'
+
+test_expect_success 'blame -L ^/RE/ (absolute: not found)' '
+       test_must_fail $PROG -L4,4 -L^/tambourine/ file
+'
+
+test_expect_success 'blame -L ^/RE/ (absolute: end-of-file)' '
+       n=$(expr $(wc -l <file) + 1) &&
+       check_count -L$n -L^/$/,+2 A 1 C 1 E 1
+'
+
 test_expect_success 'setup -L :regex' '
        tr Q "\\t" >hello.c <<-\EOF &&
        int main(int argc, const char *argv[])
@@ -275,7 +405,7 @@ test_expect_success 'setup -L :regex' '
        mv hello.c hello.orig &&
        echo "#include <stdio.h>" >hello.c &&
        cat hello.orig >>hello.c &&
-       tr Q "\\t" >>hello.c <<-\EOF
+       tr Q "\\t" >>hello.c <<-\EOF &&
        void mail()
        {
        Qputs("mail");
@@ -297,6 +427,39 @@ test_expect_success 'blame -L :nomatch' '
        test_must_fail $PROG -L:nomatch hello.c
 '
 
+test_expect_success 'blame -L :RE (relative)' '
+       check_count -f hello.c -L3,3 -L:ma.. F 1 H 4
+'
+
+test_expect_success 'blame -L :RE (relative: no preceding range)' '
+       check_count -f hello.c -L:ma.. F 4 G 1
+'
+
+test_expect_success 'blame -L :RE (relative: not found)' '
+       test_must_fail $PROG -L3,3 -L:tambourine hello.c
+'
+
+test_expect_success 'blame -L :RE (relative: end-of-file)' '
+       test_must_fail $PROG -L, -L:main hello.c
+'
+
+test_expect_success 'blame -L ^:RE (absolute)' '
+       check_count -f hello.c -L3,3 -L^:ma.. F 4 G 1
+'
+
+test_expect_success 'blame -L ^:RE (absolute: no preceding range)' '
+       check_count -f hello.c -L^:ma.. F 4 G 1
+'
+
+test_expect_success 'blame -L ^:RE (absolute: not found)' '
+       test_must_fail $PROG -L4,4 -L^:tambourine hello.c
+'
+
+test_expect_success 'blame -L ^:RE (absolute: end-of-file)' '
+       n=$(printf "%d" $(wc -l <hello.c)) &&
+       check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1
+'
+
 test_expect_success 'setup incremental' '
        (
        GIT_AUTHOR_NAME=I &&
@@ -317,8 +480,8 @@ test_expect_success 'blame empty' '
        check_count -h HEAD^^ -f incremental
 '
 
-test_expect_success 'blame -L 0 empty (undocumented)' '
-       check_count -h HEAD^^ -f incremental -L0
+test_expect_success 'blame -L 0 empty' '
+       test_must_fail $PROG -L0 incremental HEAD^^
 '
 
 test_expect_success 'blame -L 1 empty' '
@@ -333,8 +496,8 @@ test_expect_success 'blame half' '
        check_count -h HEAD^ -f incremental I 1
 '
 
-test_expect_success 'blame -L 0 half (undocumented)' '
-       check_count -h HEAD^ -f incremental -L0 I 1
+test_expect_success 'blame -L 0 half' '
+       test_must_fail $PROG -L0 incremental HEAD^
 '
 
 test_expect_success 'blame -L 1 half' '
@@ -353,8 +516,8 @@ test_expect_success 'blame full' '
        check_count -f incremental I 1
 '
 
-test_expect_success 'blame -L 0 full (undocumented)' '
-       check_count -f incremental -L0 I 1
+test_expect_success 'blame -L 0 full' '
+       test_must_fail $PROG -L0 incremental
 '
 
 test_expect_success 'blame -L 1 full' '
@@ -396,3 +559,7 @@ test_expect_success 'blame -L X,+N (non-numeric N)' '
 test_expect_success 'blame -L X,-N (non-numeric N)' '
        test_must_fail $PROG -L1,-N file
 '
+
+test_expect_success 'blame -L ,^/RE/' '
+       test_must_fail $PROG -L1,^/99/ file
+'