diff: add tests for --relative without optional prefix value

We already have tests for --relative, but they currently only test when a prefix has been provided. This fails to test the case where --relative by itself should use the current directory as the prefix. Teach the check_$type functions to take a directory argument to indicate which subdirectory to run the git commands in. Add a new test which uses this to test --relative without a prefix value. Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jacob Keller committed Dec 9, 2017 at 21:40 UTC 6d7c17ec9d4b6c384648d5bc28bc234e3083c66e
1 file changed +14 -8
t/t4045-diff-relative.sh
+14 -8
@@ -13,6 +13,7 @@ test_expect_success 'setup' '
13 '
14
15 check_diff() {
16 +dir=$1; shift
17 expect=$1; shift
18 cat >expected <<EOF
19 diff --git a/$expect b/$expect
@@ -24,50 +25,55 @@ index 0000000..25c05ef
25 +other content
26 EOF
27 test_expect_success "-p $*" "
27 - git diff -p $* HEAD^ >actual &&
28 + git -C '$dir' diff -p $* HEAD^ >actual &&
29 test_cmp expected actual
30 "
31 }
32
33 check_numstat() {
34 +dir=$1; shift
35 expect=$1; shift
36 cat >expected <<EOF
37 1 0 $expect
38 EOF
39 test_expect_success "--numstat $*" "
40 echo '1 0 $expect' >expected &&
39 - git diff --numstat $* HEAD^ >actual &&
41 + git -C '$dir' diff --numstat $* HEAD^ >actual &&
42 test_cmp expected actual
43 "
44 }
45
46 check_stat() {
47 +dir=$1; shift
48 expect=$1; shift
49 cat >expected <<EOF
50 $expect | 1 +
51 1 file changed, 1 insertion(+)
52 EOF
53 test_expect_success "--stat $*" "
51 - git diff --stat $* HEAD^ >actual &&
54 + git -C '$dir' diff --stat $* HEAD^ >actual &&
55 test_i18ncmp expected actual
56 "
57 }
58
59 check_raw() {
60 +dir=$1; shift
61 expect=$1; shift
62 cat >expected <<EOF
63 :000000 100644 0000000000000000000000000000000000000000 25c05ef3639d2d270e7fe765a67668f098092bc5 A $expect
64 EOF
65 test_expect_success "--raw $*" "
62 - git diff --no-abbrev --raw $* HEAD^ >actual &&
66 + git -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual &&
67 test_cmp expected actual
68 "
69 }
70
67 -for type in diff numstat stat raw; do
68 - check_$type file2 --relative=subdir/
69 - check_$type file2 --relative=subdir
70 - check_$type dir/file2 --relative=sub
71 +for type in diff numstat stat raw
72 +do
73 + check_$type . file2 --relative=subdir/
74 + check_$type . file2 --relative=subdir
75 + check_$type subdir file2 --relative
76 + check_$type . dir/file2 --relative=sub
77 done
78
79 test_done