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