Skip to content

Commit a167ece

Browse files
peffgitster
authored andcommitted
t: use verbose instead of hand-rolled errors
Many tests that predate the "verbose" helper function use a pattern like: test ... || { echo ... false } to give more verbose output. Using the helper, we can do this with a single line, and avoid a || which interacts badly with &&-chaining (besides fooling --chain-lint, we hit the error block no matter which command in the chain failed, so we may often show useless results). In most cases, the messages printed by "verbose" are equally good (in some cases better; t6006 accidentally redirects the message to a file!). The exception is t7001, whose output suffers slightly. However, it's still enough to show the user which part failed, given that we will have just printed the test script to stderr. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ca812a commit a167ece

File tree

5 files changed

+10
-45
lines changed

5 files changed

+10
-45
lines changed

t/t4022-diff-rewrite.sh

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ test_expect_success setup '
2020
test_expect_success 'detect rewrite' '
2121
2222
actual=$(git diff-files -B --summary test) &&
23-
expr "$actual" : " rewrite test ([0-9]*%)$" || {
24-
echo "Eh? <<$actual>>"
25-
false
26-
}
23+
verbose expr "$actual" : " rewrite test ([0-9]*%)$"
2724
2825
'
2926

t/t4202-log.sh

+5-25
Original file line numberDiff line numberDiff line change
@@ -113,59 +113,39 @@ test_expect_success 'diff-filter=M' '
113113
114114
actual=$(git log --pretty="format:%s" --diff-filter=M HEAD) &&
115115
expect=$(echo second) &&
116-
test "$actual" = "$expect" || {
117-
echo Oops
118-
echo "Actual: $actual"
119-
false
120-
}
116+
verbose test "$actual" = "$expect"
121117
122118
'
123119

124120
test_expect_success 'diff-filter=D' '
125121
126122
actual=$(git log --pretty="format:%s" --diff-filter=D HEAD) &&
127123
expect=$(echo sixth ; echo third) &&
128-
test "$actual" = "$expect" || {
129-
echo Oops
130-
echo "Actual: $actual"
131-
false
132-
}
124+
verbose test "$actual" = "$expect"
133125
134126
'
135127

136128
test_expect_success 'diff-filter=R' '
137129
138130
actual=$(git log -M --pretty="format:%s" --diff-filter=R HEAD) &&
139131
expect=$(echo third) &&
140-
test "$actual" = "$expect" || {
141-
echo Oops
142-
echo "Actual: $actual"
143-
false
144-
}
132+
verbose test "$actual" = "$expect"
145133
146134
'
147135

148136
test_expect_success 'diff-filter=C' '
149137
150138
actual=$(git log -C -C --pretty="format:%s" --diff-filter=C HEAD) &&
151139
expect=$(echo fourth) &&
152-
test "$actual" = "$expect" || {
153-
echo Oops
154-
echo "Actual: $actual"
155-
false
156-
}
140+
verbose test "$actual" = "$expect"
157141
158142
'
159143

160144
test_expect_success 'git log --follow' '
161145
162146
actual=$(git log --follow --pretty="format:%s" ichi) &&
163147
expect=$(echo third ; echo second ; echo initial) &&
164-
test "$actual" = "$expect" || {
165-
echo Oops
166-
echo "Actual: $actual"
167-
false
168-
}
148+
verbose test "$actual" = "$expect"
169149
170150
'
171151

t/t6006-rev-list-format.sh

+1-4
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,7 @@ test_expect_success 'empty email' '
358358
test_tick &&
359359
C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&
360360
A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) &&
361-
test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" || {
362-
echo "Eh? $A" >failure
363-
false
364-
}
361+
verbose test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700"
365362
'
366363

367364
test_expect_success 'del LF before empty (1)' '

t/t7001-mv.sh

+1-4
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ test_expect_success "Michael Cassar's test case" '
161161
git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf &&
162162
163163
T=`git write-tree` &&
164-
git ls-tree -r $T | grep partA/outline.txt || {
165-
git ls-tree -r $T
166-
(exit 1)
167-
}
164+
git ls-tree -r $T | verbose grep partA/outline.txt
168165
'
169166

170167
rm -fr papers partA path?

t/t7300-clean.sh

+2-8
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ test_expect_success C_LOCALE_OUTPUT 'git clean with relative prefix' '
119119
git clean -n ../src |
120120
sed -n -e "s|^Would remove ||p"
121121
) &&
122-
test "$would_clean" = ../src/part3.c || {
123-
echo "OOps <$would_clean>"
124-
false
125-
}
122+
verbose test "$would_clean" = ../src/part3.c
126123
'
127124

128125
test_expect_success C_LOCALE_OUTPUT 'git clean with absolute path' '
@@ -134,10 +131,7 @@ test_expect_success C_LOCALE_OUTPUT 'git clean with absolute path' '
134131
git clean -n "$(pwd)/../src" |
135132
sed -n -e "s|^Would remove ||p"
136133
) &&
137-
test "$would_clean" = ../src/part3.c || {
138-
echo "OOps <$would_clean>"
139-
false
140-
}
134+
verbose test "$would_clean" = ../src/part3.c
141135
'
142136

143137
test_expect_success 'git clean with out of work tree relative path' '

0 commit comments

Comments
 (0)