Merge branch 'jk/common-make-variables-export-safety'
[git] / t / t4051-diff-function-context.sh
1 #!/bin/sh
2
3 test_description='diff function context'
4
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/diff-lib.sh
7
8
9 cat <<\EOF >hello.c
10 #include <stdio.h>
11
12 static int a(void)
13 {
14         /*
15          * Dummy.
16          */
17 }
18
19 static int hello_world(void)
20 {
21         /* Classic. */
22         printf("Hello world.\n");
23
24         /* Success! */
25         return 0;
26 }
27 static int b(void)
28 {
29         /*
30          * Dummy, too.
31          */
32 }
33
34 int main(int argc, char **argv)
35 {
36         a();
37         b();
38         return hello_world();
39 }
40 EOF
41
42 test_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
51 cat <<\EOF >expected
52 diff --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  }
64 EOF
65
66 test_expect_success 'diff -U0 -W' '
67         git diff -U0 -W >actual &&
68         compare_diff_patch actual expected
69 '
70
71 cat <<\EOF >expected
72 diff --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  }
85 EOF
86
87 test_expect_success 'diff -W' '
88         git diff -W >actual &&
89         compare_diff_patch actual expected
90 '
91
92 test_done