t / t4051-diff-function-context.shon commit Merge branch 'jk/remote-literal-string-leakfix' (93542d9)
   1#!/bin/sh
   2
   3test_description='diff function context'
   4
   5. ./test-lib.sh
   6. "$TEST_DIRECTORY"/diff-lib.sh
   7
   8
   9cat <<\EOF >hello.c
  10#include <stdio.h>
  11
  12static int a(void)
  13{
  14        /*
  15         * Dummy.
  16         */
  17}
  18
  19static int hello_world(void)
  20{
  21        /* Classic. */
  22        printf("Hello world.\n");
  23
  24        /* Success! */
  25        return 0;
  26}
  27static int b(void)
  28{
  29        /*
  30         * Dummy, too.
  31         */
  32}
  33
  34int main(int argc, char **argv)
  35{
  36        a();
  37        b();
  38        return hello_world();
  39}
  40EOF
  41
  42test_expect_success 'setup' '
  43        git add hello.c &&
  44        test_tick &&
  45        git commit -m initial &&
  46
  47        grep -v Classic <hello.c >hello.c.new &&
  48        mv hello.c.new hello.c
  49'
  50
  51cat <<\EOF >expected
  52diff --git a/hello.c b/hello.c
  53--- a/hello.c
  54+++ b/hello.c
  55@@ -10,8 +10,7 @@ static int a(void)
  56 static int hello_world(void)
  57 {
  58-       /* Classic. */
  59        printf("Hello world.\n");
  60 
  61        /* Success! */
  62        return 0;
  63 }
  64EOF
  65
  66test_expect_success 'diff -U0 -W' '
  67        git diff -U0 -W >actual &&
  68        compare_diff_patch actual expected
  69'
  70
  71cat <<\EOF >expected
  72diff --git a/hello.c b/hello.c
  73--- a/hello.c
  74+++ b/hello.c
  75@@ -9,9 +9,8 @@ static int a(void)
  76 
  77 static int hello_world(void)
  78 {
  79-       /* Classic. */
  80        printf("Hello world.\n");
  81 
  82        /* Success! */
  83        return 0;
  84 }
  85EOF
  86
  87test_expect_success 'diff -W' '
  88        git diff -W >actual &&
  89        compare_diff_patch actual expected
  90'
  91
  92test_done