From: Stefano Lattarini Date: Sat, 16 Jul 2011 08:55:05 +0000 (+0200) Subject: test defs: new subroutine 'seq_', simulating GNU seq(1) X-Git-Tag: v1.11b~257^2~162 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f37035c3296ce3f199d3ea004cc4fe9042359c2d;p=platform%2Fupstream%2Fautomake.git 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. --- diff --git a/ChangeLog b/ChangeLog index 88611c5..7e24e10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2011-07-16 Stefano Lattarini + 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 + 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 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 . + +# 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 + +: