Git fork

tests: do not rely on external "patch"

Some of our tests assumed a working "patch" command to produce expected
results when checking "git-apply", but some systems have broken "patch".

We can compare our output with expected output that is precomputed
instead to sidestep this issue.

Signed-off-by: Junio C Hamano <gitster@pobox.com>

+190 -123
+19 -36
t/t4109-apply-multifrag.sh
··· 4 # Copyright (c) 2005 Robert Fitzsimons 5 # 6 7 - test_description='git apply test patches with multiple fragments. 8 9 - ' 10 . ./test-lib.sh 11 12 - cp ../t4109/patch1.patch . 13 - cp ../t4109/patch2.patch . 14 - cp ../t4109/patch3.patch . 15 - cp ../t4109/patch4.patch . 16 17 - test_expect_success "S = git apply (1)" \ 18 - 'git apply patch1.patch patch2.patch' 19 - mv main.c main.c.git 20 21 - test_expect_success "S = patch (1)" \ 22 - 'cat patch1.patch patch2.patch | patch -p1' 23 24 - test_expect_success "S = cmp (1)" \ 25 - 'cmp main.c.git main.c' 26 - 27 - rm -f main.c main.c.git 28 - 29 - test_expect_success "S = git apply (2)" \ 30 - 'git apply patch1.patch patch2.patch patch3.patch' 31 mv main.c main.c.git 32 - 33 - test_expect_success "S = patch (2)" \ 34 - 'cat patch1.patch patch2.patch patch3.patch | patch -p1' 35 - 36 - test_expect_success "S = cmp (2)" \ 37 - 'cmp main.c.git main.c' 38 - 39 - rm -f main.c main.c.git 40 - 41 - test_expect_success "S = git apply (3)" \ 42 - 'git apply patch1.patch patch4.patch' 43 - mv main.c main.c.git 44 - 45 - test_expect_success "S = patch (3)" \ 46 - 'cat patch1.patch patch4.patch | patch -p1' 47 - 48 - test_expect_success "S = cmp (3)" \ 49 - 'cmp main.c.git main.c' 50 51 test_done 52
··· 4 # Copyright (c) 2005 Robert Fitzsimons 5 # 6 7 + test_description='git apply test patches with multiple fragments.' 8 9 . ./test-lib.sh 10 11 + cp "$TEST_DIRECTORY/t4109/patch1.patch" . 12 + cp "$TEST_DIRECTORY/t4109/patch2.patch" . 13 + cp "$TEST_DIRECTORY/t4109/patch3.patch" . 14 + cp "$TEST_DIRECTORY/t4109/patch4.patch" . 15 16 + test_expect_success 'git apply (1)' ' 17 + git apply patch1.patch patch2.patch && 18 + test_cmp "$TEST_DIRECTORY/t4109/expect-1" main.c 19 + ' 20 + rm -f main.c 21 22 + test_expect_success 'git apply (2)' ' 23 + git apply patch1.patch patch2.patch patch3.patch && 24 + test_cmp "$TEST_DIRECTORY/t4109/expect-2" main.c 25 + ' 26 + rm -f main.c 27 28 + test_expect_success 'git apply (3)' ' 29 + git apply patch1.patch patch4.patch && 30 + test_cmp "$TEST_DIRECTORY/t4109/expect-3" main.c 31 + ' 32 mv main.c main.c.git 33 34 test_done 35
+31
t/t4109/expect-1
···
··· 1 + #include <stdlib.h> 2 + #include <stdio.h> 3 + 4 + int func(int num); 5 + void print_int(int num); 6 + void print_ln(); 7 + 8 + int main() { 9 + int i; 10 + 11 + for (i = 0; i < 10; i++) { 12 + print_int(func(i)); 13 + } 14 + 15 + print_ln(); 16 + 17 + return 0; 18 + } 19 + 20 + int func(int num) { 21 + return num * num; 22 + } 23 + 24 + void print_int(int num) { 25 + printf("%d", num); 26 + } 27 + 28 + void print_ln() { 29 + printf("\n"); 30 + } 31 +
+23
t/t4109/expect-2
···
··· 1 + #include <stdio.h> 2 + 3 + int func(int num); 4 + void print_int(int num); 5 + 6 + int main() { 7 + int i; 8 + 9 + for (i = 0; i < 10; i++) { 10 + print_int(func(i)); 11 + } 12 + 13 + return 0; 14 + } 15 + 16 + int func(int num) { 17 + return num * num; 18 + } 19 + 20 + void print_int(int num) { 21 + printf("%d", num); 22 + } 23 +
+24
t/t4109/expect-3
···
··· 1 + #include <stdio.h> 2 + 3 + int func(int num); 4 + int func2(int num); 5 + 6 + int main() { 7 + int i; 8 + 9 + for (i = 0; i < 10; i++) { 10 + printf("%d", func(i)); 11 + printf("%d", func3(i)); 12 + } 13 + 14 + return 0; 15 + } 16 + 17 + int func(int num) { 18 + return num * num; 19 + } 20 + 21 + int func2(int num) { 22 + return num * num * num; 23 + } 24 +
+9 -87
t/t4110-apply-scan.sh
··· 9 ' 10 . ./test-lib.sh 11 12 - # setup 13 - 14 - cat > patch1.patch <<\EOF 15 - diff --git a/new.txt b/new.txt 16 - new file mode 100644 17 - --- /dev/null 18 - +++ b/new.txt 19 - @@ -0,0 +1,12 @@ 20 - +a1 21 - +a11 22 - +a111 23 - +a1111 24 - +b1 25 - +b11 26 - +b111 27 - +b1111 28 - +c1 29 - +c11 30 - +c111 31 - +c1111 32 - EOF 33 - cat > patch2.patch <<\EOF 34 - diff --git a/new.txt b/new.txt 35 - --- a/new.txt 36 - +++ b/new.txt 37 - @@ -1,7 +1,3 @@ 38 - -a1 39 - -a11 40 - -a111 41 - -a1111 42 - b1 43 - b11 44 - b111 45 - EOF 46 - cat > patch3.patch <<\EOF 47 - diff --git a/new.txt b/new.txt 48 - --- a/new.txt 49 - +++ b/new.txt 50 - @@ -6,6 +6,10 @@ 51 - b11 52 - b111 53 - b1111 54 - +b2 55 - +b22 56 - +b222 57 - +b2222 58 - c1 59 - c11 60 - c111 61 - EOF 62 - cat > patch4.patch <<\EOF 63 - diff --git a/new.txt b/new.txt 64 - --- a/new.txt 65 - +++ b/new.txt 66 - @@ -1,3 +1,7 @@ 67 - +a1 68 - +a11 69 - +a111 70 - +a1111 71 - b1 72 - b11 73 - b111 74 - EOF 75 - cat > patch5.patch <<\EOF 76 - diff --git a/new.txt b/new.txt 77 - --- a/new.txt 78 - +++ b/new.txt 79 - @@ -10,3 +10,7 @@ 80 - c11 81 - c111 82 - c1111 83 - +c2 84 - +c22 85 - +c222 86 - +c2222 87 - EOF 88 - 89 - test_expect_success "S = git apply scan" \ 90 - 'git apply patch1.patch patch2.patch patch3.patch patch4.patch patch5.patch' 91 - mv new.txt apply.txt 92 - 93 - test_expect_success "S = patch scan" \ 94 - 'cat patch1.patch patch2.patch patch3.patch patch4.patch patch5.patch | patch' 95 - mv new.txt patch.txt 96 - 97 - test_expect_success "S = cmp" \ 98 - 'cmp apply.txt patch.txt' 99 100 test_done
··· 9 ' 10 . ./test-lib.sh 11 12 + test_expect_success 'git apply scan' ' 13 + git apply \ 14 + "$TEST_DIRECTORY/t4110/patch1.patch" \ 15 + "$TEST_DIRECTORY/t4110/patch2.patch" \ 16 + "$TEST_DIRECTORY/t4110/patch3.patch" \ 17 + "$TEST_DIRECTORY/t4110/patch4.patch" \ 18 + "$TEST_DIRECTORY/t4110/patch5.patch" && 19 + test_cmp new.txt "$TEST_DIRECTORY/t4110/expect" 20 + ' 21 22 test_done
+20
t/t4110/expect
···
··· 1 + a1 2 + a11 3 + a111 4 + a1111 5 + b1 6 + b11 7 + b111 8 + b1111 9 + b2 10 + b22 11 + b222 12 + b2222 13 + c1 14 + c11 15 + c111 16 + c1111 17 + c2 18 + c22 19 + c222 20 + c2222
+17
t/t4110/patch1.patch
···
··· 1 + diff --git a/new.txt b/new.txt 2 + new file mode 100644 3 + --- /dev/null 4 + +++ b/new.txt 5 + @@ -0,0 +1,12 @@ 6 + +a1 7 + +a11 8 + +a111 9 + +a1111 10 + +b1 11 + +b11 12 + +b111 13 + +b1111 14 + +c1 15 + +c11 16 + +c111 17 + +c1111
+11
t/t4110/patch2.patch
···
··· 1 + diff --git a/new.txt b/new.txt 2 + --- a/new.txt 3 + +++ b/new.txt 4 + @@ -1,7 +1,3 @@ 5 + -a1 6 + -a11 7 + -a111 8 + -a1111 9 + b1 10 + b11 11 + b111
+14
t/t4110/patch3.patch
···
··· 1 + diff --git a/new.txt b/new.txt 2 + --- a/new.txt 3 + +++ b/new.txt 4 + @@ -6,6 +6,10 @@ 5 + b11 6 + b111 7 + b1111 8 + +b2 9 + +b22 10 + +b222 11 + +b2222 12 + c1 13 + c11 14 + c111
+11
t/t4110/patch4.patch
···
··· 1 + diff --git a/new.txt b/new.txt 2 + --- a/new.txt 3 + +++ b/new.txt 4 + @@ -1,3 +1,7 @@ 5 + +a1 6 + +a11 7 + +a111 8 + +a1111 9 + b1 10 + b11 11 + b111
+11
t/t4110/patch5.patch
···
··· 1 + diff --git a/new.txt b/new.txt 2 + --- a/new.txt 3 + +++ b/new.txt 4 + @@ -10,3 +10,7 @@ 5 + c11 6 + c111 7 + c1111 8 + +c2 9 + +c22 10 + +c222 11 + +c2222