* tests/defs (seq_): New subroutine.
* tests/instmany.test: Use it.
* tests/instmany-mans.test: Likewise.
* tests/instmany-python.test: Likewise.
* tests/self-check-seq.test: New self test.
* tests/Makefile.am (TESTS): Update.
+2011-07-16 Stefano Lattarini <stefano.lattarini@gmail.com>
+
+ test defs: new subroutine 'seq_', simulating GNU seq(1)
+ * tests/defs (seq_): New subroutine.
+ * tests/instmany.test: Use it.
+ * tests/instmany-mans.test: Likewise.
+ * tests/instmany-python.test: Likewise.
+ * tests/self-check-seq.test: New self test.
+ * tests/Makefile.am (TESTS): Update.
+
2011-07-16 Stefano Lattarini <stefano.lattarini@gmail.com>
tests: remove duplication about testing of config.* aux files
self-check-reexec.test \
self-check-report.test \
self-check-sanity.test \
+self-check-seq.test \
self-check-unindent.test \
sanity.test \
scripts.test \
self-check-reexec.test \
self-check-report.test \
self-check-sanity.test \
+self-check-seq.test \
self-check-unindent.test \
sanity.test \
scripts.test \
}
am__using_gmake="" # Avoid interferences from the environment.
+# seq_ - print a sequence of numbers
+# ----------------------------------
+# This function simulates GNU seq(1) portably. Valid usages:
+# - seq LAST
+# - seq FIRST LAST
+# - seq FIRST INCREMENT LAST
+seq_ ()
+{
+ case $# in
+ 0) fatal_ "seq_: missing argument";;
+ 1) seq_first=1 seq_incr=1 seq_last=$1;;
+ 2) seq_first=$1 seq_incr=1 seq_last=$2;;
+ 3) seq_first=$1 seq_incr=$2 seq_last=$3;;
+ *) fatal_ "seq_: too many arguments";;
+ esac
+ # Try to avoid forks if possible.
+ case "$BASH_VERSION" in
+ ""|[12].*)
+ : Not bash, or a too old bash version. ;;
+ *)
+ # Use eval to protect dumber shells from parsing errors.
+ eval 'for ((i = seq_first; i <= seq_last; i += seq_incr)); do
+ echo $i
+ done'
+ return 0;;
+ esac
+ # Else, use GNU seq if available.
+ seq "$@" && return 0
+ # Otherwise revert to a slower loop using expr(1).
+ i=$seq_first
+ while test $i -le $seq_last; do
+ echo $i
+ i=`expr $i + $seq_incr`
+ done
+}
+
commented_sed_unindent_prog='
/^$/b # Nothing to do for empty lines.
x # Get x<indent> into pattern space.
limit=2500
subdir=long_subdir_name_with_many_characters
nfiles=81
-
-# Let's use `seq' if available, it's faster than the loop.
-list=`(seq 1 $nfiles) 2>/dev/null || {
- i=1
- while test $i -le $nfiles; do
- echo $i
- i=\`expr $i + 1\`
- done; }`
+list=`seq_ 1 $nfiles`
sed "s|@limit@|$limit|g" >myinstall.in <<'END'
#! /bin/sh
limit=2500
subdir=long_subdir_name_with_many_characters
nfiles=81
-
-list=`(seq 1 $nfiles) 2>/dev/null || {
- i=1
- while test $i -le $nfiles; do
- echo $i
- i=\`expr $i + 1\`
- done; }`
+list=`seq_ 1 $nfiles`
sed "s|@limit@|$limit|g" >myinstall.in <<'END'
#! /bin/sh
limit=2500
subdir=long_subdir_name_with_many_characters
nfiles=81
-
-# Let's use `seq' if available, it's faster than the loop.
-list=`(seq 1 $nfiles) 2>/dev/null || {
- i=1
- while test $i -le $nfiles; do
- echo $i
- i=\`expr $i + 1\`
- done; }`
+list=`seq_ 1 $nfiles`
sed "s|@limit@|$limit|g" >myinstall.in <<'END'
#! /bin/sh
--- /dev/null
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Sanity check for the automake testsuite.
+# Check the `seq_' subroutine.
+
+. ./defs || Exit 1
+
+unset stderr_fileno_ || :
+
+: One-argument form.
+exp="\
+1
+2
+3
+4
+5"
+got=`seq_ 5` || Exit 1
+test x"$exp" = x"$got" || Exit 1
+
+: Two-arguments form.
+exp="\
+7
+8
+9
+10
+11"
+got=`seq_ 7 11` || Exit 1
+test x"$exp" = x"$got" || Exit 1
+
+: Three-arguments form [1].
+exp="\
+120
+125
+130
+135"
+got=`seq_ 120 5 135` || Exit 1
+test x"$exp" = x"$got" || Exit 1
+
+: Three-arguments form [2].
+exp="\
+13
+17
+21"
+got=`seq_ 13 4 23` || Exit 1
+test x"$exp" = x"$got" || Exit 1
+
+: No argument is an error.
+st=0
+(seq_) 2>stderr || st=$?
+test $st -eq 99
+grep 'seq_: missing argument' stderr
+
+: Four or more arguments is an error.
+for args in '1 1 2 1' '1 1 1 1 1 1'; do
+ st=0
+ (seq_ $args) 2>stderr || st=$?
+ test $st -eq 99
+ grep 'seq_: too many arguments' stderr
+done
+
+: