Skip to content

Commit 88511d2

Browse files
sunshinecogitster
authored andcommitted
t4202: clarify intent by creating expected content less cleverly
Several tests assign the output of `$(...)` command substitution to an "expect" variable, taking advantage of the fact that `$(...)` folds out the final line terminator while leaving internal line terminators intact. They do this because the "actual" string with which "expect" will be compared is shaped the same way. However, this intent (having internal line terminators, but no final line terminator) is not necessarily obvious at first glance and may confuse casual readers. The intent can be made more obvious by using `printf` instead, with which line termination is stated clearly: printf "sixth\nthird" In fact, many other tests in this script already use `printf` for precisely this purpose, thus it is an established pattern. Therefore, convert these tests to employ `printf`, as well. While at it, modernize the tests to use test_cmp() to compare the expected and actual output rather than using the semi-deprecated `verbose test "$x" = "$y"`. Signed-off-by: Eric Sunshine <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe13adb commit 88511d2

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

t/t4202-log.sh

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,48 +120,48 @@ test_expect_success 'diff-filter=A' '
120120

121121
test_expect_success 'diff-filter=M' '
122122
123-
actual=$(git log --pretty="format:%s" --diff-filter=M HEAD) &&
124-
expect=$(echo second) &&
125-
verbose test "$actual" = "$expect"
123+
git log --pretty="format:%s" --diff-filter=M HEAD >actual &&
124+
printf "second" >expect &&
125+
test_cmp expect actual
126126
127127
'
128128

129129
test_expect_success 'diff-filter=D' '
130130
131-
actual=$(git log --no-renames --pretty="format:%s" --diff-filter=D HEAD) &&
132-
expect=$(echo sixth ; echo third) &&
133-
verbose test "$actual" = "$expect"
131+
git log --no-renames --pretty="format:%s" --diff-filter=D HEAD >actual &&
132+
printf "sixth\nthird" >expect &&
133+
test_cmp expect actual
134134
135135
'
136136

137137
test_expect_success 'diff-filter=R' '
138138
139-
actual=$(git log -M --pretty="format:%s" --diff-filter=R HEAD) &&
140-
expect=$(echo third) &&
141-
verbose test "$actual" = "$expect"
139+
git log -M --pretty="format:%s" --diff-filter=R HEAD >actual &&
140+
printf "third" >expect &&
141+
test_cmp expect actual
142142
143143
'
144144

145145
test_expect_success 'diff-filter=C' '
146146
147-
actual=$(git log -C -C --pretty="format:%s" --diff-filter=C HEAD) &&
148-
expect=$(echo fourth) &&
149-
verbose test "$actual" = "$expect"
147+
git log -C -C --pretty="format:%s" --diff-filter=C HEAD >actual &&
148+
printf "fourth" >expect &&
149+
test_cmp expect actual
150150
151151
'
152152

153153
test_expect_success 'git log --follow' '
154154
155-
actual=$(git log --follow --pretty="format:%s" ichi) &&
156-
expect=$(echo third ; echo second ; echo initial) &&
157-
verbose test "$actual" = "$expect"
155+
git log --follow --pretty="format:%s" ichi >actual &&
156+
printf "third\nsecond\ninitial" >expect &&
157+
test_cmp expect actual
158158
'
159159

160160
test_expect_success 'git config log.follow works like --follow' '
161161
test_config log.follow true &&
162-
actual=$(git log --pretty="format:%s" ichi) &&
163-
expect=$(echo third ; echo second ; echo initial) &&
164-
verbose test "$actual" = "$expect"
162+
git log --pretty="format:%s" ichi >actual &&
163+
printf "third\nsecond\ninitial" >expect &&
164+
test_cmp expect actual
165165
'
166166

167167
test_expect_success 'git config log.follow does not die with multiple paths' '
@@ -176,9 +176,9 @@ test_expect_success 'git config log.follow does not die with no paths' '
176176

177177
test_expect_success 'git config log.follow is overridden by --no-follow' '
178178
test_config log.follow true &&
179-
actual=$(git log --no-follow --pretty="format:%s" ichi) &&
180-
expect="third" &&
181-
verbose test "$actual" = "$expect"
179+
git log --no-follow --pretty="format:%s" ichi >actual &&
180+
printf "third" >expect &&
181+
test_cmp expect actual
182182
'
183183

184184
# Note that these commits are intentionally listed out of order.

0 commit comments

Comments
 (0)