Skip to content

Commit f6b7572

Browse files
peffgitster
authored andcommitted
t: convert some here-doc test bodies
The t1404 script checks a lot of output from Git which contains single quotes. Because the test snippets are themselves wrapped in the same single-quotes, we have to resort to using $SQ to match them. This is error-prone and makes the tests harder to read. Instead, let's use the new here-doc feature added in the previous commit, which lets us write anything in the test body we want (except the here-doc end marker on a line by itself, of course). Note that we do use "\" in our marker to avoid interpolation (which is the whole point). But we don't use "<<-", as we want to preserve whitespace in the snippet (and running with "-v" before and after shows that we produce the exact same output, except with the ugly $SQ references fixed). I just converted every test here, even though only some of them use $SQ. But it would be equally correct to mix-and-match styles if we don't mind the inconsistency. I've also converted a few tests in t0600 which were moved from t1404 (I had written this patch before they were moved, but it seemed worth porting over the changes rather than losing them). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d133ae commit f6b7572

File tree

2 files changed

+117
-117
lines changed

2 files changed

+117
-117
lines changed

t/t0600-reffiles-backend.sh

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,82 +91,82 @@ test_expect_success 'empty directory should not fool 1-arg delete' '
9191
git update-ref --stdin
9292
'
9393

94-
test_expect_success 'non-empty directory blocks create' '
94+
test_expect_success 'non-empty directory blocks create' - <<\EOT
9595
prefix=refs/ne-create &&
9696
mkdir -p .git/$prefix/foo/bar &&
9797
: >.git/$prefix/foo/bar/baz.lock &&
9898
test_when_finished "rm -f .git/$prefix/foo/bar/baz.lock" &&
9999
cat >expected <<-EOF &&
100-
fatal: cannot lock ref $SQ$prefix/foo$SQ: there is a non-empty directory $SQ.git/$prefix/foo$SQ blocking reference $SQ$prefix/foo$SQ
100+
fatal: cannot lock ref '$prefix/foo': there is a non-empty directory '.git/$prefix/foo' blocking reference '$prefix/foo'
101101
EOF
102102
printf "%s\n" "update $prefix/foo $C" |
103103
test_must_fail git update-ref --stdin 2>output.err &&
104104
test_cmp expected output.err &&
105105
cat >expected <<-EOF &&
106-
fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ
106+
fatal: cannot lock ref '$prefix/foo': unable to resolve reference '$prefix/foo'
107107
EOF
108108
printf "%s\n" "update $prefix/foo $D $C" |
109109
test_must_fail git update-ref --stdin 2>output.err &&
110110
test_cmp expected output.err
111-
'
111+
EOT
112112

113-
test_expect_success 'broken reference blocks create' '
113+
test_expect_success 'broken reference blocks create' - <<\EOT
114114
prefix=refs/broken-create &&
115115
mkdir -p .git/$prefix &&
116116
echo "gobbledigook" >.git/$prefix/foo &&
117117
test_when_finished "rm -f .git/$prefix/foo" &&
118118
cat >expected <<-EOF &&
119-
fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken
119+
fatal: cannot lock ref '$prefix/foo': unable to resolve reference '$prefix/foo': reference broken
120120
EOF
121121
printf "%s\n" "update $prefix/foo $C" |
122122
test_must_fail git update-ref --stdin 2>output.err &&
123123
test_cmp expected output.err &&
124124
cat >expected <<-EOF &&
125-
fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken
125+
fatal: cannot lock ref '$prefix/foo': unable to resolve reference '$prefix/foo': reference broken
126126
EOF
127127
printf "%s\n" "update $prefix/foo $D $C" |
128128
test_must_fail git update-ref --stdin 2>output.err &&
129129
test_cmp expected output.err
130-
'
130+
EOT
131131

132-
test_expect_success 'non-empty directory blocks indirect create' '
132+
test_expect_success 'non-empty directory blocks indirect create' - <<\EOT
133133
prefix=refs/ne-indirect-create &&
134134
git symbolic-ref $prefix/symref $prefix/foo &&
135135
mkdir -p .git/$prefix/foo/bar &&
136136
: >.git/$prefix/foo/bar/baz.lock &&
137137
test_when_finished "rm -f .git/$prefix/foo/bar/baz.lock" &&
138138
cat >expected <<-EOF &&
139-
fatal: cannot lock ref $SQ$prefix/symref$SQ: there is a non-empty directory $SQ.git/$prefix/foo$SQ blocking reference $SQ$prefix/foo$SQ
139+
fatal: cannot lock ref '$prefix/symref': there is a non-empty directory '.git/$prefix/foo' blocking reference '$prefix/foo'
140140
EOF
141141
printf "%s\n" "update $prefix/symref $C" |
142142
test_must_fail git update-ref --stdin 2>output.err &&
143143
test_cmp expected output.err &&
144144
cat >expected <<-EOF &&
145-
fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ
145+
fatal: cannot lock ref '$prefix/symref': unable to resolve reference '$prefix/foo'
146146
EOF
147147
printf "%s\n" "update $prefix/symref $D $C" |
148148
test_must_fail git update-ref --stdin 2>output.err &&
149149
test_cmp expected output.err
150-
'
150+
EOT
151151

152-
test_expect_success 'broken reference blocks indirect create' '
152+
test_expect_success 'broken reference blocks indirect create' - <<\EOT
153153
prefix=refs/broken-indirect-create &&
154154
git symbolic-ref $prefix/symref $prefix/foo &&
155155
echo "gobbledigook" >.git/$prefix/foo &&
156156
test_when_finished "rm -f .git/$prefix/foo" &&
157157
cat >expected <<-EOF &&
158-
fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken
158+
fatal: cannot lock ref '$prefix/symref': unable to resolve reference '$prefix/foo': reference broken
159159
EOF
160160
printf "%s\n" "update $prefix/symref $C" |
161161
test_must_fail git update-ref --stdin 2>output.err &&
162162
test_cmp expected output.err &&
163163
cat >expected <<-EOF &&
164-
fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ: reference broken
164+
fatal: cannot lock ref '$prefix/symref': unable to resolve reference '$prefix/foo': reference broken
165165
EOF
166166
printf "%s\n" "update $prefix/symref $D $C" |
167167
test_must_fail git update-ref --stdin 2>output.err &&
168168
test_cmp expected output.err
169-
'
169+
EOT
170170

171171
test_expect_success 'no bogus intermediate values during delete' '
172172
prefix=refs/slow-transaction &&
@@ -224,7 +224,7 @@ test_expect_success 'no bogus intermediate values during delete' '
224224
test_must_fail git rev-parse --verify --quiet $prefix/foo
225225
'
226226

227-
test_expect_success 'delete fails cleanly if packed-refs file is locked' '
227+
test_expect_success 'delete fails cleanly if packed-refs file is locked' - <<\EOT
228228
prefix=refs/locked-packed-refs &&
229229
# Set up a reference with differing loose and packed versions:
230230
git update-ref $prefix/foo $C &&
@@ -236,9 +236,9 @@ test_expect_success 'delete fails cleanly if packed-refs file is locked' '
236236
test_when_finished "rm -f .git/packed-refs.lock" &&
237237
test_must_fail git update-ref -d $prefix/foo >out 2>err &&
238238
git for-each-ref $prefix >actual &&
239-
test_grep "Unable to create $SQ.*packed-refs.lock$SQ: " err &&
239+
test_grep "Unable to create '.*packed-refs.lock': " err &&
240240
test_cmp unchanged actual
241-
'
241+
EOT
242242

243243
test_expect_success 'delete fails cleanly if packed-refs.new write fails' '
244244
# Setup and expectations are similar to the test above.

0 commit comments

Comments
 (0)