[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[FYI] {testsuite-work} test defs: new subroutine 'seq_', simulating GNU
From: |
Stefano Lattarini |
Subject: |
[FYI] {testsuite-work} test defs: new subroutine 'seq_', simulating GNU seq(1) |
Date: |
Sat, 16 Jul 2011 14:00:24 +0200 |
* 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.
---
ChangeLog | 10 ++++++
tests/Makefile.am | 1 +
tests/Makefile.in | 1 +
tests/defs | 36 +++++++++++++++++++++
tests/instmany-mans.test | 9 +-----
tests/instmany-python.test | 8 +----
tests/instmany.test | 9 +-----
tests/self-check-seq.test | 75 ++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 126 insertions(+), 23 deletions(-)
create mode 100755 tests/self-check-seq.test
diff --git a/ChangeLog b/ChangeLog
index 88611c5..7e24e10 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2011-07-16 Stefano Lattarini <address@hidden>
+ 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 <address@hidden>
+
tests: remove duplication about testing of config.* aux files
* tests/add-missing.test: Also check that the `AC_CANONICAL_SYSTEM'
autoconf macro causes the `config.sub' and `config.guess' scripts
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bfede0d..925c2ca 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -903,6 +903,7 @@ self-check-me.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 \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 235f2ef..f5aea3b 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -1191,6 +1191,7 @@ self-check-me.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 \
diff --git a/tests/defs b/tests/defs
index aaedbc2..0ba346a 100644
--- a/tests/defs
+++ b/tests/defs
@@ -257,6 +257,42 @@ using_gmake ()
}
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.
diff --git a/tests/instmany-mans.test b/tests/instmany-mans.test
index 0462164..f0b15f4 100755
--- a/tests/instmany-mans.test
+++ b/tests/instmany-mans.test
@@ -28,14 +28,7 @@
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
diff --git a/tests/instmany-python.test b/tests/instmany-python.test
index d0c7423..0031913 100755
--- a/tests/instmany-python.test
+++ b/tests/instmany-python.test
@@ -24,13 +24,7 @@ required='python'
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
diff --git a/tests/instmany.test b/tests/instmany.test
index 69c7e86..5a5a324 100755
--- a/tests/instmany.test
+++ b/tests/instmany.test
@@ -36,14 +36,7 @@
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
diff --git a/tests/self-check-seq.test b/tests/self-check-seq.test
new file mode 100755
index 0000000..7e0fdf4
--- /dev/null
+++ b/tests/self-check-seq.test
@@ -0,0 +1,75 @@
+#! /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
+
+:
--
1.7.2.3