t / lib-diff-alternative.shon commit Merge branch 'dk/send-email-avoid-net-smtp-ssl-when-able' into maint (f381e42)
   1# Helpers shared by the test scripts for diff algorithms (patience,
   2# histogram, etc).
   3
   4test_diff_frobnitz() {
   5        cat >file1 <<\EOF
   6#include <stdio.h>
   7
   8// Frobs foo heartily
   9int 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
  19int fact(int n)
  20{
  21    if(n > 1)
  22    {
  23        return fact(n-1) * n;
  24    }
  25    return 1;
  26}
  27
  28int main(int argc, char **argv)
  29{
  30    frobnitz(fact(10));
  31}
  32EOF
  33
  34        cat >file2 <<\EOF
  35#include <stdio.h>
  36
  37int 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
  47int frobnitz(int foo)
  48{
  49    int i;
  50    for(i = 0; i < 10; i++)
  51    {
  52        printf("%d\n", foo);
  53    }
  54}
  55
  56int main(int argc, char **argv)
  57{
  58    frobnitz(fib(10));
  59}
  60EOF
  61
  62        cat >expect <<\EOF
  63diff --git a/file1 b/file2
  64index 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 }
 104EOF
 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
 120test_diff_unique() {
 121        cat >uniq1 <<\EOF
 1221
 1232
 1243
 1254
 1265
 1276
 128EOF
 129
 130        cat >uniq2 <<\EOF
 131a
 132b
 133c
 134d
 135e
 136f
 137EOF
 138
 139        cat >expect <<\EOF
 140diff --git a/uniq1 b/uniq2
 141index 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
 157EOF
 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