Skip to content

Commit a3bb8ca

Browse files
committed
t1020: do not overuse printf and use write_script
The test prepares a sample file "dir/two" with a single incomplete line in it with "printf", and also prepares a small helper script "diff" to create a file with a single incomplete line in it, again with "printf". The output from the latter is compared with an expected output, again prepared with "printf" hence lacking the final LF. There is no reason for this test to be using files with an incomplete line at the end, and these look more like a mistake of not using printf "%s\n" "string to be written" and using printf "string to be written" Depending on what would be in $GIT_PREFIX, using the latter form could be a bug waiting to happen. Correct them. Also, the test uses hardcoded #!/bin/sh to create a small helper script. For a small task like what the generated script does, it does not matter too much in that what appears as /bin/sh would not be _so_ broken, but while we are at it, use write_script instead, which happens to make the result easier to read by reducing need of one level of quoting. Signed-off-by: Junio C Hamano <[email protected]>
1 parent ca386ee commit a3bb8ca

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

t/t1020-subdirectory.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ test_expect_success 'GIT_PREFIX for !alias' '
141141
test_expect_success 'GIT_PREFIX for built-ins' '
142142
# Use GIT_EXTERNAL_DIFF to test that the "diff" built-in
143143
# receives the GIT_PREFIX variable.
144-
printf "dir/" >expect &&
145-
printf "#!/bin/sh\n" >diff &&
146-
printf "printf \"\$GIT_PREFIX\"" >>diff &&
147-
chmod +x diff &&
144+
echo "dir/" >expect &&
145+
write_script diff <<-\EOF &&
146+
printf "%s\n" "$GIT_PREFIX"
147+
EOF
148148
(
149149
cd dir &&
150-
printf "change" >two &&
150+
echo "change" >two &&
151151
GIT_EXTERNAL_DIFF=./diff git diff >../actual
152152
git checkout -- two
153153
) &&

0 commit comments

Comments
 (0)