Skip to content

Commit d17cf5f

Browse files
mkiedrowiczgitster
authored andcommitted
tests: Introduce test_seq
Jeff King wrote: The seq command is GNU-ism, and is missing at least in older BSD releases and their derivatives, not to mention antique commercial Unixes. We already purged it in b3431bc (Don't use seq in tests, not everyone has it, 2007-05-02), but a few new instances have crept in. They went unnoticed because they are in scripts that are not run by default. Replace them with test_seq that is implemented with a Perl snippet (proposed by Jeff). This is better than inlining this snippet everywhere it's needed because it's easier to read and it's easier to change the implementation (e.g. to C) if we ever decide to remove Perl from the test suite. Note that test_seq is not a complete replacement for seq(1). It just has what we need now, in addition that it makes it possible for us to do something like "test_seq a m" if we wanted to in the future. There are also many places that do `for i in 1 2 3 ...` but I'm not sure if it's worth converting them to test_seq. That would introduce running more processes of Perl. Signed-off-by: Michał Kiedrowicz <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0e4c882 commit d17cf5f

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

t/perf/perf-lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ test_perf () {
163163
else
164164
echo "perf $test_count - $1:"
165165
fi
166-
for i in $(seq 1 $GIT_PERF_REPEAT_COUNT); do
166+
for i in $(test_seq 1 $GIT_PERF_REPEAT_COUNT); do
167167
say >&3 "running: $2"
168168
if test_run_perf_ "$2"
169169
then

t/t5551-http-fetch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
114114
test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
115115
(
116116
cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
117-
for i in `seq 50000`
117+
for i in `test_seq 50000`
118118
do
119119
echo "commit refs/heads/too-many-refs"
120120
echo "mark :$i"

t/test-lib-functions.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,27 @@ test_cmp() {
530530
$GIT_TEST_CMP "$@"
531531
}
532532

533+
# Print a sequence of numbers or letters in increasing order. This is
534+
# similar to GNU seq(1), but the latter might not be available
535+
# everywhere (and does not do letters). It may be used like:
536+
#
537+
# for i in `test_seq 100`; do
538+
# for j in `test_seq 10 20`; do
539+
# for k in `test_seq a z`; do
540+
# echo $i-$j-$k
541+
# done
542+
# done
543+
# done
544+
545+
test_seq () {
546+
case $# in
547+
1) set 1 "$@" ;;
548+
2) ;;
549+
*) error "bug in the test script: not 1 or 2 parameters to test_seq" ;;
550+
esac
551+
"$PERL_PATH" -le 'print for $ARGV[0]..$ARGV[1]' -- "$@"
552+
}
553+
533554
# This function can be used to schedule some commands to be run
534555
# unconditionally at the end of the test to restore sanity:
535556
#

0 commit comments

Comments
 (0)