]> git.ipfire.org Git - thirdparty/git.git/blob - t/lib-diff-alternative.sh
l10n: fr v2.23.0 round 2
[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 file1=$(git rev-parse --short $(git hash-object file1))
63 file2=$(git rev-parse --short $(git hash-object file2))
64 cat >expect <<EOF
65 diff --git a/file1 b/file2
66 index $file1..$file2 100644
67 --- a/file1
68 +++ b/file2
69 @@ -1,26 +1,25 @@
70 #include <stdio.h>
71
72 +int fib(int n)
73 +{
74 + if(n > 2)
75 + {
76 + return fib(n-1) + fib(n-2);
77 + }
78 + return 1;
79 +}
80 +
81 // Frobs foo heartily
82 int frobnitz(int foo)
83 {
84 int i;
85 for(i = 0; i < 10; i++)
86 {
87 - printf("Your answer is: ");
88 printf("%d\n", foo);
89 }
90 }
91
92 -int fact(int n)
93 -{
94 - if(n > 1)
95 - {
96 - return fact(n-1) * n;
97 - }
98 - return 1;
99 -}
100 -
101 int main(int argc, char **argv)
102 {
103 - frobnitz(fact(10));
104 + frobnitz(fib(10));
105 }
106 EOF
107
108 STRATEGY=$1
109
110 test_expect_success "$STRATEGY diff" '
111 test_must_fail git diff --no-index "--$STRATEGY" file1 file2 > output &&
112 test_cmp expect output
113 '
114
115 test_expect_success "$STRATEGY diff output is valid" '
116 mv file2 expect &&
117 git apply < output &&
118 test_cmp expect file2
119 '
120 }
121
122 test_diff_unique() {
123 cat >uniq1 <<\EOF
124 1
125 2
126 3
127 4
128 5
129 6
130 EOF
131
132 cat >uniq2 <<\EOF
133 a
134 b
135 c
136 d
137 e
138 f
139 EOF
140
141 uniq1=$(git rev-parse --short $(git hash-object uniq1))
142 uniq2=$(git rev-parse --short $(git hash-object uniq2))
143 cat >expect <<EOF
144 diff --git a/uniq1 b/uniq2
145 index $uniq1..$uniq2 100644
146 --- a/uniq1
147 +++ b/uniq2
148 @@ -1,6 +1,6 @@
149 -1
150 -2
151 -3
152 -4
153 -5
154 -6
155 +a
156 +b
157 +c
158 +d
159 +e
160 +f
161 EOF
162
163 STRATEGY=$1
164
165 test_expect_success 'completely different files' '
166 test_must_fail git diff --no-index "--$STRATEGY" uniq1 uniq2 > output &&
167 test_cmp expect output
168 '
169 }
170