Merge tag 'v2.23.0-rc0' of git://git.kernel.org/pub/scm/git/git
[git/raj.git] / t / lib-diff-alternative.sh
blob8d1e408bb58f5e097f242d5c1fd2c7bb036deb6e
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 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>
72 +int fib(int n)
74 + if(n > 2)
75 + {
76 + return fib(n-1) + fib(n-2);
77 + }
78 + return 1;
81 // Frobs foo heartily
82 int frobnitz(int foo)
84 int i;
85 for(i = 0; i < 10; i++)
87 - printf("Your answer is: ");
88 printf("%d\n", foo);
92 -int fact(int n)
94 - if(n > 1)
95 - {
96 - return fact(n-1) * n;
97 - }
98 - return 1;
101 int main(int argc, char **argv)
103 - frobnitz(fact(10));
104 + frobnitz(fib(10));
108 STRATEGY=$1
110 test_expect_success "$STRATEGY diff" '
111 test_must_fail git diff --no-index "--$STRATEGY" file1 file2 > output &&
112 test_cmp expect output
115 test_expect_success "$STRATEGY diff output is valid" '
116 mv file2 expect &&
117 git apply < output &&
118 test_cmp expect file2
122 test_diff_unique() {
123 cat >uniq1 <<\EOF
132 cat >uniq2 <<\EOF
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 @@
163 STRATEGY=$1
165 test_expect_success 'completely different files' '
166 test_must_fail git diff --no-index "--$STRATEGY" uniq1 uniq2 > output &&
167 test_cmp expect output