Merge branch 'maint'
[git/dscho.git] / t / t4109-apply-multifrag.sh
blob5988e1ae4c0b394adfa743a159c32024db62bf1e
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
4 # Copyright (c) 2005 Robert Fitzsimons
7 test_description='git-apply test patches with multiple fragments.
10 . ./test-lib.sh
12 # setup
14 cat > patch1.patch <<\EOF
15 diff --git a/main.c b/main.c
16 new file mode 100644
17 --- /dev/null
18 +++ b/main.c
19 @@ -0,0 +1,23 @@
20 +#include <stdio.h>
22 +int func(int num);
23 +void print_int(int num);
25 +int main() {
26 + int i;
28 + for (i = 0; i < 10; i++) {
29 + print_int(func(i));
30 + }
32 + return 0;
35 +int func(int num) {
36 + return num * num;
39 +void print_int(int num) {
40 + printf("%d", num);
43 EOF
44 cat > patch2.patch <<\EOF
45 diff --git a/main.c b/main.c
46 --- a/main.c
47 +++ b/main.c
48 @@ -1,7 +1,9 @@
49 +#include <stdlib.h>
50 #include <stdio.h>
52 int func(int num);
53 void print_int(int num);
54 +void print_ln();
56 int main() {
57 int i;
58 @@ -10,6 +12,8 @@
59 print_int(func(i));
62 + print_ln();
64 return 0;
67 @@ -21,3 +25,7 @@
68 printf("%d", num);
71 +void print_ln() {
72 + printf("\n");
75 EOF
76 cat > patch3.patch <<\EOF
77 diff --git a/main.c b/main.c
78 --- a/main.c
79 +++ b/main.c
80 @@ -1,9 +1,7 @@
81 -#include <stdlib.h>
82 #include <stdio.h>
84 int func(int num);
85 void print_int(int num);
86 -void print_ln();
88 int main() {
89 int i;
90 @@ -12,8 +10,6 @@
91 print_int(func(i));
94 - print_ln();
96 return 0;
99 @@ -25,7 +21,3 @@
100 printf("%d", num);
103 -void print_ln() {
104 - printf("\n");
108 cat > patch4.patch <<\EOF
109 diff --git a/main.c b/main.c
110 --- a/main.c
111 +++ b/main.c
112 @@ -1,13 +1,14 @@
113 #include <stdio.h>
115 int func(int num);
116 -void print_int(int num);
117 +int func2(int num);
119 int main() {
120 int i;
122 for (i = 0; i < 10; i++) {
123 - print_int(func(i));
124 + printf("%d", func(i));
125 + printf("%d", func3(i));
128 return 0;
129 @@ -17,7 +18,7 @@
130 return num * num;
133 -void print_int(int num) {
134 - printf("%d", num);
135 +int func2(int num) {
136 + return num * num * num;
141 test_expect_success "S = git-apply (1)" \
142 'git-apply patch1.patch patch2.patch'
143 mv main.c main.c.git
145 test_expect_success "S = patch (1)" \
146 'cat patch1.patch patch2.patch | patch -p1'
148 test_expect_success "S = cmp (1)" \
149 'cmp main.c.git main.c'
151 rm -f main.c main.c.git
153 test_expect_success "S = git-apply (2)" \
154 'git-apply patch1.patch patch2.patch patch3.patch'
155 mv main.c main.c.git
157 test_expect_success "S = patch (2)" \
158 'cat patch1.patch patch2.patch patch3.patch | patch -p1'
160 test_expect_success "S = cmp (2)" \
161 'cmp main.c.git main.c'
163 rm -f main.c main.c.git
165 test_expect_success "S = git-apply (3)" \
166 'git-apply patch1.patch patch4.patch'
167 mv main.c main.c.git
169 test_expect_success "S = patch (3)" \
170 'cat patch1.patch patch4.patch | patch -p1'
172 test_expect_success "S = cmp (3)" \
173 'cmp main.c.git main.c'
175 test_done