]> git.ipfire.org Git - thirdparty/git.git/blob - t/lib-diff-alternative.sh
completion: fix __gitcomp_builtin no longer consider extra options
[thirdparty/git.git] / t / lib-diff-alternative.sh
1 # Helpers shared by the test scripts for diff algorithms (patience,
2 # histogram, etc).
3
4 test_diff_frobnitz() {
5 cat >file1 <<\EOF
6 #include <stdio.h>
7
8 // Frobs foo heartily
9 int frobnitz(int foo)
10 {
11 int i;
12 for(i = 0; i < 10; i++)
13 {
14 printf("Your answer is: ");
15 printf("%d\n", foo);
16 }
17 }
18
19 int fact(int n)
20 {
21 if(n > 1)
22 {
23 return fact(n-1) * n;
24 }
25 return 1;
26 }
27
28 int main(int argc, char **argv)
29 {
30 frobnitz(fact(10));
31 }
32 EOF
33
34 cat >file2 <<\EOF
35 #include <stdio.h>
36
37 int fib(int n)
38 {
39 if(n > 2)
40 {
41 return fib(n-1) + fib(n-2);
42 }
43 return 1;
44 }
45
46 // Frobs foo heartily
47 int frobnitz(int foo)
48 {
49 int i;
50 for(i = 0; i < 10; i++)
51 {
52 printf("%d\n", foo);
53 }
54 }
55
56 int main(int argc, char **argv)
57 {
58 frobnitz(fib(10));
59 }
60 EOF
61
62 cat >expect <<\EOF
63 diff --git a/file1 b/file2
64 index 6faa5a3..e3af329 100644
65 --- a/file1
66 +++ b/file2
67 @@ -1,26 +1,25 @@
68 #include <stdio.h>
69
70 +int fib(int n)
71 +{
72 + if(n > 2)
73 + {
74 + return fib(n-1) + fib(n-2);
75 + }
76 + return 1;
77 +}
78 +
79 // Frobs foo heartily
80 int frobnitz(int foo)
81 {
82 int i;
83 for(i = 0; i < 10; i++)
84 {
85 - printf("Your answer is: ");
86 printf("%d\n", foo);
87 }
88 }
89
90 -int fact(int n)
91 -{
92 - if(n > 1)
93 - {
94 - return fact(n-1) * n;
95 - }
96 - return 1;
97 -}
98 -
99 int main(int argc, char **argv)
100 {
101 - frobnitz(fact(10));
102 + frobnitz(fib(10));
103 }
104 EOF
105
106 STRATEGY=$1
107
108 test_expect_success "$STRATEGY diff" '
109 test_must_fail git diff --no-index "--$STRATEGY" file1 file2 > output &&
110 test_cmp expect output
111 '
112
113 test_expect_success "$STRATEGY diff output is valid" '
114 mv file2 expect &&
115 git apply < output &&
116 test_cmp expect file2
117 '
118 }
119
120 test_diff_unique() {
121 cat >uniq1 <<\EOF
122 1
123 2
124 3
125 4
126 5
127 6
128 EOF
129
130 cat >uniq2 <<\EOF
131 a
132 b
133 c
134 d
135 e
136 f
137 EOF
138
139 cat >expect <<\EOF
140 diff --git a/uniq1 b/uniq2
141 index b414108..0fdf397 100644
142 --- a/uniq1
143 +++ b/uniq2
144 @@ -1,6 +1,6 @@
145 -1
146 -2
147 -3
148 -4
149 -5
150 -6
151 +a
152 +b
153 +c
154 +d
155 +e
156 +f
157 EOF
158
159 STRATEGY=$1
160
161 test_expect_success 'completely different files' '
162 test_must_fail git diff --no-index "--$STRATEGY" uniq1 uniq2 > output &&
163 test_cmp expect output
164 '
165 }
166