Skip to content

Commit 28d294a

Browse files
committed
Merge branch 'ab/portable-more'
Portability fix. * ab/portable-more: tests: fix non-portable iconv invocation tests: fix non-portable "${var:-"str"}" construct tests: fix and add lint for non-portable grep --file tests: fix version-specific portability issue in Perl JSON tests: use shorter labels in chainlint.sed for AIX sed tests: fix comment syntax in chainlint.sed for AIX sed tests: fix and add lint for non-portable seq tests: fix and add lint for non-portable head -c N
2 parents b571c25 + f6af6f9 commit 28d294a

10 files changed

+53
-44
lines changed

t/chainlint.sed

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@
9797
/<<[ ]*[-\\']*[A-Za-z0-9_]/ {
9898
s/^\(.*\)<<[ ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
9999
s/[ ]*<<//
100-
:hereslurp
100+
:hered
101101
N
102102
/^<\([^>]*\)>.*\n[ ]*\1[ ]*$/!{
103103
s/\n.*$//
104-
bhereslurp
104+
bhered
105105
}
106106
s/^<[^>]*>//
107107
s/\n.*$//
@@ -131,9 +131,8 @@ b
131131
b
132132

133133
:subshell
134-
# bare "(" line?
134+
# bare "(" line? -- stash for later printing
135135
/^[ ]*([ ]*$/ {
136-
# stash for later printing
137136
h
138137
bnextline
139138
}
@@ -150,7 +149,7 @@ s/.*\n//
150149

151150
:slurp
152151
# incomplete line "...\"
153-
/\\$/bincomplete
152+
/\\$/bicmplte
154153
# multi-line quoted string "...\n..."?
155154
/"/bdqstring
156155
# multi-line quoted string '...\n...'? (but not contraction in string "it's")
@@ -172,7 +171,7 @@ s/.*\n//
172171
/"[^"]*#[^"]*"/!s/[ ]#.*$//
173172
}
174173
# one-liner "case ... esac"
175-
/^[ ]*case[ ]*..*esac/bcheckchain
174+
/^[ ]*case[ ]*..*esac/bchkchn
176175
# multi-line "case ... esac"
177176
/^[ ]*case[ ]..*[ ]in/bcase
178177
# multi-line "for ... done" or "while ... done"
@@ -201,32 +200,32 @@ s/.*\n//
201200
/^[ ]*fi[ ]*[<>|]/bdone
202201
/^[ ]*fi[ ]*)/bdone
203202
# nested one-liner "(...) &&"
204-
/^[ ]*(.*)[ ]*&&[ ]*$/bcheckchain
203+
/^[ ]*(.*)[ ]*&&[ ]*$/bchkchn
205204
# nested one-liner "(...)"
206-
/^[ ]*(.*)[ ]*$/bcheckchain
205+
/^[ ]*(.*)[ ]*$/bchkchn
207206
# nested one-liner "(...) >x" (or "2>x" or "<x" or "|x")
208-
/^[ ]*(.*)[ ]*[0-9]*[<>|]/bcheckchain
207+
/^[ ]*(.*)[ ]*[0-9]*[<>|]/bchkchn
209208
# nested multi-line "(...\n...)"
210209
/^[ ]*(/bnest
211210
# multi-line "{...\n...}"
212211
/^[ ]*{/bblock
213212
# closing ")" on own line -- exit subshell
214-
/^[ ]*)/bclosesolo
213+
/^[ ]*)/bclssolo
215214
# "$((...))" -- arithmetic expansion; not closing ")"
216-
/\$(([^)][^)]*))[^)]*$/bcheckchain
215+
/\$(([^)][^)]*))[^)]*$/bchkchn
217216
# "$(...)" -- command substitution; not closing ")"
218-
/\$([^)][^)]*)[^)]*$/bcheckchain
217+
/\$([^)][^)]*)[^)]*$/bchkchn
219218
# multi-line "$(...\n...)" -- command substitution; treat as nested subshell
220219
/\$([^)]*$/bnest
221220
# "=(...)" -- Bash array assignment; not closing ")"
222-
/=(/bcheckchain
221+
/=(/bchkchn
223222
# closing "...) &&"
224223
/)[ ]*&&[ ]*$/bclose
225224
# closing "...)"
226225
/)[ ]*$/bclose
227226
# closing "...) >x" (or "2>x" or "<x" or "|x")
228227
/)[ ]*[<>|]/bclose
229-
:checkchain
228+
:chkchn
230229
# mark suspect if line uses ";" internally rather than "&&" (but not ";" in a
231230
# string and not ";;" in one-liner "case...esac")
232231
/;/{
@@ -245,7 +244,7 @@ n
245244
bslurp
246245

247246
# found incomplete line "...\" -- slurp up next line
248-
:incomplete
247+
:icmplte
249248
N
250249
s/\\\n//
251250
bslurp
@@ -283,11 +282,11 @@ bfolded
283282
:heredoc
284283
s/^\(.*\)<<[ ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
285284
s/[ ]*<<//
286-
:hereslurpsub
285+
:heredsub
287286
N
288287
/^<\([^>]*\)>.*\n[ ]*\1[ ]*$/!{
289288
s/\n.*$//
290-
bhereslurpsub
289+
bheredsub
291290
}
292291
s/^<[^>]*>//
293292
s/\n.*$//
@@ -317,43 +316,43 @@ x
317316
# is 'done' or 'fi' cuddled with ")" to close subshell?
318317
/done.*)/bclose
319318
/fi.*)/bclose
320-
bcheckchain
319+
bchkchn
321320

322321
# found nested multi-line "(...\n...)" -- pass through untouched
323322
:nest
324323
x
325-
:nestslurp
324+
:nstslurp
326325
n
327326
# closing ")" on own line -- stop nested slurp
328-
/^[ ]*)/bnestclose
327+
/^[ ]*)/bnstclose
329328
# comment -- not closing ")" if in comment
330-
/^[ ]*#/bnestcontinue
329+
/^[ ]*#/bnstcnt
331330
# "$((...))" -- arithmetic expansion; not closing ")"
332-
/\$(([^)][^)]*))[^)]*$/bnestcontinue
331+
/\$(([^)][^)]*))[^)]*$/bnstcnt
333332
# "$(...)" -- command substitution; not closing ")"
334-
/\$([^)][^)]*)[^)]*$/bnestcontinue
333+
/\$([^)][^)]*)[^)]*$/bnstcnt
335334
# closing "...)" -- stop nested slurp
336-
/)/bnestclose
337-
:nestcontinue
335+
/)/bnstclose
336+
:nstcnt
338337
x
339-
bnestslurp
340-
:nestclose
338+
bnstslurp
339+
:nstclose
341340
s/^/>>/
342341
# is it "))" which closes nested and parent subshells?
343342
/)[ ]*)/bslurp
344-
bcheckchain
343+
bchkchn
345344

346345
# found multi-line "{...\n...}" block -- pass through untouched
347346
:block
348347
x
349348
n
350349
# closing "}" -- stop block slurp
351-
/}/bcheckchain
350+
/}/bchkchn
352351
bblock
353352

354353
# found closing ")" on own line -- drop "suspect" from final line of subshell
355354
# since that line legitimately lacks "&&" and exit subshell loop
356-
:closesolo
355+
:clssolo
357356
x
358357
s/?!AMP?!//
359358
p

t/check-non-portable-shell.pl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ sub err {
4141
/^\s*[^#]\s*which\s/ and err 'which is not portable (use type)';
4242
/\btest\s+[^=]*==/ and err '"test a == b" is not portable (use =)';
4343
/\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable (use test_line_count)';
44+
/\bhead\s+-c\b/ and err 'head -c is not portable (use test_copy_bytes BYTES <file >out)';
45+
/(?:\$\(seq|^\s*seq\b)/ and err 'seq is not portable (use test_seq)';
46+
/\bgrep\b.*--file\b/ and err 'grep --file FILE is not portable (use grep -f FILE)';
4447
/\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (use FOO=bar && export FOO)';
4548
/^\s*([A-Z0-9_]+=(\w+|(["']).*?\3)\s+)+(\w+)/ and exists($func{$4}) and
4649
err '"FOO=bar shell_func" assignment extends beyond "shell_func"';

t/t0019/parse_json.perl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ sub dump_item {
3434
} elsif (ref($value) eq 'HASH') {
3535
print "$label_in hash\n";
3636
dump_hash($label_in, $value);
37+
} elsif (ref $value) {
38+
my $bool = $value ? 1 : 0;
39+
print "$label_in $bool\n";
3740
} elsif (defined $value) {
3841
print "$label_in $value\n";
3942
} else {

t/t0028-working-tree-encoding.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ test_expect_success 'error if encoding garbage is already in Git' '
203203
test_i18ngrep "error: BOM is required" err.out
204204
'
205205

206-
test_expect_success 'check roundtrip encoding' '
206+
test_lazy_prereq ICONV_SHIFT_JIS '
207+
iconv -f UTF-8 -t SHIFT-JIS </dev/null
208+
'
209+
210+
test_expect_success ICONV_SHIFT_JIS 'check roundtrip encoding' '
207211
test_when_finished "rm -f roundtrip.shift roundtrip.utf16" &&
208212
test_when_finished "git reset --hard HEAD" &&
209213

t/t4013-diff-various.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ do
140140
expect="$TEST_DIRECTORY/t4013/diff.$test"
141141
actual="$pfx-diff.$test"
142142

143-
test_expect_success "git $cmd # magic is ${magic:-"(not used)"}" '
143+
test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
144144
{
145145
echo "$ git $cmd"
146146
case "$magic" in

t/t5310-pack-bitmaps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ test_expect_success 'truncated bitmap fails gracefully' '
335335
git rev-list --use-bitmap-index --count --all >expect &&
336336
bitmap=$(ls .git/objects/pack/*.bitmap) &&
337337
test_when_finished "rm -f $bitmap" &&
338-
head -c 512 <$bitmap >$bitmap.tmp &&
338+
test_copy_bytes 512 <$bitmap >$bitmap.tmp &&
339339
mv -f $bitmap.tmp $bitmap &&
340340
git rev-list --use-bitmap-index --count --all >actual 2>stderr &&
341341
test_cmp expect actual &&

t/t5318-commit-graph.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ test_expect_success 'Add one more commit' '
134134
git branch commits/8 &&
135135
ls $objdir/pack | grep idx >existing-idx &&
136136
git repack &&
137-
ls $objdir/pack| grep idx | grep -v --file=existing-idx >new-idx
137+
ls $objdir/pack| grep idx | grep -v -f existing-idx >new-idx
138138
'
139139

140140
# Current graph structure:

t/t5552-skipping-fetch-negotiator.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ test_expect_success 'commits with no parents are sent regardless of skip distanc
4646
test_commit -C server to_fetch &&
4747
4848
git init client &&
49-
for i in $(seq 7)
49+
for i in $(test_seq 7)
5050
do
5151
test_commit -C client c$i
5252
done &&
@@ -89,7 +89,7 @@ test_expect_success 'when two skips collide, favor the larger one' '
8989
test_commit -C server to_fetch &&
9090
9191
git init client &&
92-
for i in $(seq 11)
92+
for i in $(test_seq 11)
9393
do
9494
test_commit -C client c$i
9595
done &&
@@ -168,14 +168,14 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC
168168
test_commit -C server to_fetch &&
169169
170170
git init client &&
171-
for i in $(seq 8)
171+
for i in $(test_seq 8)
172172
do
173173
git -C client checkout --orphan b$i &&
174174
test_commit -C client b$i.c0
175175
done &&
176-
for j in $(seq 19)
176+
for j in $(test_seq 19)
177177
do
178-
for i in $(seq 8)
178+
for i in $(test_seq 8)
179179
do
180180
git -C client checkout b$i &&
181181
test_commit -C client b$i.c$j
@@ -205,7 +205,7 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC
205205
206206
# fetch-pack should thus not send any more commits in the b1 branch, but
207207
# should still send the others (in this test, just check b2).
208-
for i in $(seq 0 8)
208+
for i in $(test_seq 0 8)
209209
do
210210
have_not_sent b1.c$i
211211
done &&

t/t5703-upload-pack-ref-in-want.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ test_expect_success 'setup repos for change-while-negotiating test' '
176176
git clone "http://127.0.0.1:$LIB_HTTPD_PORT/smart/repo" "$LOCAL_PRISTINE" &&
177177
cd "$LOCAL_PRISTINE" &&
178178
git checkout -b side &&
179-
for i in $(seq 1 33); do test_commit s$i; done &&
179+
for i in $(test_seq 1 33); do test_commit s$i; done &&
180180
181181
# Add novel commits to upstream
182182
git checkout master &&
@@ -289,7 +289,7 @@ test_expect_success 'setup repos for fetching with ref-in-want tests' '
289289
git clone "file://$REPO" "$LOCAL_PRISTINE" &&
290290
cd "$LOCAL_PRISTINE" &&
291291
git checkout -b side &&
292-
for i in $(seq 1 33); do test_commit s$i; done &&
292+
for i in $(test_seq 1 33); do test_commit s$i; done &&
293293
294294
# Add novel commits to upstream
295295
git checkout master &&

t/test-lib.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ then
867867
# handle only executables, unless they are shell libraries that
868868
# need to be in the exec-path.
869869
test -x "$1" ||
870-
test "# " = "$(head -c 2 <"$1")" ||
870+
test "# " = "$(test_copy_bytes 2 <"$1")" ||
871871
return;
872872

873873
base=$(basename "$1")
@@ -882,7 +882,7 @@ then
882882
# do not override scripts
883883
if test -x "$symlink_target" &&
884884
test ! -d "$symlink_target" &&
885-
test "#!" != "$(head -c 2 < "$symlink_target")"
885+
test "#!" != "$(test_copy_bytes 2 <"$symlink_target")"
886886
then
887887
symlink_target=../valgrind.sh
888888
fi

0 commit comments

Comments
 (0)