@matheusbsbs / matheus-bagliano / commits / dd0c69e956
Fork 0

t4017 (diff-retval): replace manual exit code check with test_expect_code

This commit takes advantage of Ævar Arnfjörð Bjarmason's recent change to test_expect_code (test-lib: make test_expect_code a test command) to simplify several testcases. Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Oct 3, 2010 at 14:00 UTC dd0c69e95638d49f576c3774b8073b68d82ec0ff
1 file changed +20 -49
t/t4017-diff-retval.sh
+20 -49
@@ -29,66 +29,49 @@ test_expect_success 'git diff --quiet -w HEAD^ HEAD' '
29 '
30
31 test_expect_success 'git diff-tree HEAD^ HEAD' '
32 - git diff-tree --exit-code HEAD^ HEAD
33 - test $? = 1
32 + test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD
33 '
34 test_expect_success 'git diff-tree HEAD^ HEAD -- a' '
35 git diff-tree --exit-code HEAD^ HEAD -- a
37 - test $? = 0
36 '
37 test_expect_success 'git diff-tree HEAD^ HEAD -- b' '
40 - git diff-tree --exit-code HEAD^ HEAD -- b
41 - test $? = 1
38 + test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD -- b
39 '
40 test_expect_success 'echo HEAD | git diff-tree --stdin' '
44 - echo $(git rev-parse HEAD) | git diff-tree --exit-code --stdin
45 - test $? = 1
41 + echo $(git rev-parse HEAD) | test_expect_code 1 git diff-tree --exit-code --stdin
42 '
43 test_expect_success 'git diff-tree HEAD HEAD' '
44 git diff-tree --exit-code HEAD HEAD
49 - test $? = 0
45 '
46 test_expect_success 'git diff-files' '
47 git diff-files --exit-code
53 - test $? = 0
48 '
49 test_expect_success 'git diff-index --cached HEAD' '
50 git diff-index --exit-code --cached HEAD
57 - test $? = 0
51 '
52 test_expect_success 'git diff-index --cached HEAD^' '
60 - git diff-index --exit-code --cached HEAD^
61 - test $? = 1
53 + test_expect_code 1 git diff-index --exit-code --cached HEAD^
54 '
55 test_expect_success 'git diff-index --cached HEAD^' '
56 echo text >>b &&
57 echo 3 >c &&
66 - git add . && {
67 - git diff-index --exit-code --cached HEAD^
68 - test $? = 1
69 - }
58 + git add . &&
59 + test_expect_code 1 git diff-index --exit-code --cached HEAD^
60 '
61 test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' '
72 - git commit -m "text in b" && {
73 - git diff-tree -p --exit-code -Stext HEAD^ HEAD -- b
74 - test $? = 1
75 - }
62 + git commit -m "text in b" &&
63 + test_expect_code 1 git diff-tree -p --exit-code -Stext HEAD^ HEAD -- b
64 '
65 test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' '
66 git diff-tree -p --exit-code -Snot-found HEAD^ HEAD -- b
79 - test $? = 0
67 '
68 test_expect_success 'git diff-files' '
82 - echo 3 >>c && {
83 - git diff-files --exit-code
84 - test $? = 1
85 - }
69 + echo 3 >>c &&
70 + test_expect_code 1 git diff-files --exit-code
71 '
72 test_expect_success 'git diff-index --cached HEAD' '
88 - git update-index c && {
89 - git diff-index --exit-code --cached HEAD
90 - test $? = 1
91 - }
73 + git update-index c &&
74 + test_expect_code 1 git diff-index --exit-code --cached HEAD
75 '
76
77 test_expect_success '--check --exit-code returns 0 for no difference' '
@@ -100,30 +83,26 @@ test_expect_success '--check --exit-code returns 0 for no difference' '
83 test_expect_success '--check --exit-code returns 1 for a clean difference' '
84
85 echo "good" > a &&
103 - git diff --check --exit-code
104 - test $? = 1
86 + test_expect_code 1 git diff --check --exit-code
87
88 '
89
90 test_expect_success '--check --exit-code returns 3 for a dirty difference' '
91
92 echo "bad " >> a &&
111 - git diff --check --exit-code
112 - test $? = 3
93 + test_expect_code 3 git diff --check --exit-code
94
95 '
96
97 test_expect_success '--check with --no-pager returns 2 for dirty difference' '
98
118 - git --no-pager diff --check
119 - test $? = 2
99 + test_expect_code 2 git --no-pager diff --check
100
101 '
102
103 test_expect_success 'check should test not just the last line' '
104 echo "" >>a &&
125 - git --no-pager diff --check
126 - test $? = 2
105 + test_expect_code 2 git --no-pager diff --check
106
107 '
108
@@ -133,10 +112,8 @@ test_expect_success 'check detects leftover conflict markers' '
112 echo binary >>b &&
113 git commit -m "side" b &&
114 test_must_fail git merge master &&
136 - git add b && (
137 - git --no-pager diff --cached --check >test.out
138 - test $? = 2
139 - ) &&
115 + git add b &&
116 + test_expect_code 2 git --no-pager diff --cached --check >test.out &&
117 test 3 = $(grep "conflict marker" test.out | wc -l) &&
118 git reset --hard
119 '
@@ -146,19 +123,13 @@ test_expect_success 'check honors conflict marker length' '
123 echo ">>>>>>> boo" >>b &&
124 echo "======" >>a &&
125 git diff --check a &&
149 - (
150 - git diff --check b
151 - test $? = 2
152 - ) &&
126 + test_expect_code 2 git diff --check b &&
127 git reset --hard &&
128 echo ">>>>>>>> boo" >>b &&
129 echo "========" >>a &&
130 git diff --check &&
131 echo "b conflict-marker-size=8" >.gitattributes &&
158 - (
159 - git diff --check b
160 - test $? = 2
161 - ) &&
132 + test_expect_code 2 git diff --check b &&
133 git diff --check a &&
134 git reset --hard
135 '