use xcalloc() to allocate zero-initialized memory
[alt-git.git] / t / lib-diff-alternative.sh
blob8b4dbf22d2d140bef7ca0e106a389cb0ca1d4681
1 # Helpers shared by the test scripts for diff algorithms (patience,
2 # histogram, etc).
4 test_diff_frobnitz() {
5 cat >file1 <<\EOF
6 #include <stdio.h>
8 // Frobs foo heartily
9 int frobnitz(int foo)
11 int i;
12 for(i = 0; i < 10; i++)
14 printf("Your answer is: ");
15 printf("%d\n", foo);
19 int fact(int n)
21 if(n > 1)
23 return fact(n-1) * n;
25 return 1;
28 int main(int argc, char **argv)
30 frobnitz(fact(10));
32 EOF
34 cat >file2 <<\EOF
35 #include <stdio.h>
37 int fib(int n)
39 if(n > 2)
41 return fib(n-1) + fib(n-2);
43 return 1;
46 // Frobs foo heartily
47 int frobnitz(int foo)
49 int i;
50 for(i = 0; i < 10; i++)
52 printf("%d\n", foo);
56 int main(int argc, char **argv)
58 frobnitz(fib(10));
60 EOF
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>
70 +int fib(int n)
72 + if(n > 2)
73 + {
74 + return fib(n-1) + fib(n-2);
75 + }
76 + return 1;
79 // Frobs foo heartily
80 int frobnitz(int foo)
82 int i;
83 for(i = 0; i < 10; i++)
85 - printf("Your answer is: ");
86 printf("%d\n", foo);
90 -int fact(int n)
92 - if(n > 1)
93 - {
94 - return fact(n-1) * n;
95 - }
96 - return 1;
99 int main(int argc, char **argv)
101 - frobnitz(fact(10));
102 + frobnitz(fib(10));
106 STRATEGY=$1
108 test_expect_success "$STRATEGY diff" '
109 test_must_fail git diff --no-index "--$STRATEGY" file1 file2 > output &&
110 test_cmp expect output
113 test_expect_success "$STRATEGY diff output is valid" '
114 mv file2 expect &&
115 git apply < output &&
116 test_cmp expect file2
120 test_diff_unique() {
121 cat >uniq1 <<\EOF
130 cat >uniq2 <<\EOF
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 @@
159 STRATEGY=$1
161 test_expect_success 'completely different files' '
162 test_must_fail git diff --no-index "--$STRATEGY" uniq1 uniq2 > output &&
163 test_cmp expect output