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 <sunshine@sunshineco.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Dec 9, 2021 at 00:11 UTC 88511d271b503e7e4681d7d8ae01cd3ee3294e35
1 file changed +21 -21
t/t4202-log.sh
+21 -21
@@ -120,48 +120,48 @@ test_expect_success 'diff-filter=A' '
120
121 test_expect_success 'diff-filter=M' '
122
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
126
127 '
128
129 test_expect_success 'diff-filter=D' '
130
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
134
135 '
136
137 test_expect_success 'diff-filter=R' '
138
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
142
143 '
144
145 test_expect_success 'diff-filter=C' '
146
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
150
151 '
152
153 test_expect_success 'git log --follow' '
154
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
158 '
159
160 test_expect_success 'git config log.follow works like --follow' '
161 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
165 '
166
167 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' '
176
177 test_expect_success 'git config log.follow is overridden by --no-follow' '
178 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
182 '
183
184 # Note that these commits are intentionally listed out of order.