autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Avoid long lines in testsuite script.


From: Ralf Wildenhues
Subject: Avoid long lines in testsuite script.
Date: Sat, 7 Aug 2010 10:46:27 +0200
User-agent: Mutt/1.5.20 (2010-04-22)

Even if the shell and its internal echo may not have any issues with
long lines and command-line arguments, given enough test groups, some
seds and (h)awks will still eventually barf (when used to extract tests)
and editing testsuite manually won't work with some vendor vi.

So, time to have newline-separated $at_groups_all and $at_groups.

The new code tries to ensure we don't ever get stray newlines in
$at_groups, so that a newline can be used as detector for "we have more
than one test, so enable banners", and an empty line as separator in the
input to the awk script that does --list.

It's not relevant for the patch whether $at_groups_all is computed at m4
time (as done before the patch) or at shell time (done in the patch),
you decide whether to trade 0.1% script size for two forks or not.

I have tried the patch on a couple of systems to ensure the testsuite
addition really exposes at least one failure, but the patch hasn't
undergone extensive testing yet.  If the next Autoconf release is 4+
weeks away, I'd assume we find remaining issues along the way, but if
you consider a quick release for AC_INIT(,,BUG-REPORT?) then I'd be just
as happy to postpone this patch.

Thanks,
Ralf

    Avoid long lines in testsuite script.
    
    * lib/autotest/general.m4 (AT_INIT): Remove definition of
    AT_groups_all.  Initialize at_groups from at_help_all, with
    newlines instead of spaces separating test groups numbers.
    Adjust all code to newlines.
    * NEWS: Update.
    * tests/autotest.at (Huge testsuite): New test.

diff --git a/NEWS b/NEWS
index d7c74df..b017a43 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,9 @@ GNU Autoconf NEWS - User visible changes.
 ** AT_BANNER() with empty argument will cause visual separation from previous
    test category.
 
+** Autotest testsuites should not contain long text lines any more, and be
+   portable even when very many test groups are used.
+
 
 * Major changes in Autoconf 2.67 (2010-07-21) [stable]
   Released by Eric Blake, based on git versions 2.66.*.
diff --git a/lib/autotest/general.m4 b/lib/autotest/general.m4
index 170200c..4439cc9 100644
--- a/lib/autotest/general.m4
+++ b/lib/autotest/general.m4
@@ -202,7 +202,6 @@ m4_define([AT_INIT],
    [m4_expand([: $1])]))]
 [m4_define([AT_ordinal], 0)]
 [m4_define([AT_banner_ordinal], 0)]
-[m4_define([AT_groups_all], [])]
 [m4_define([AT_help_all], [])]
 [m4_map_args([_m4_popdef], _AT_DEFINE_INIT_LIST)]
 [m4_wrap([_AT_FINISH])]
@@ -226,11 +225,10 @@ at_cli_args="address@hidden"
 
 m4_divert_push([BANNERS])dnl
 
-# Should we print banners?  at_groups is space-separated for entire test,
-# newline-separated if only a subset of the testsuite is run.
-case $at_groups in
-  *' '*' '* | *"$as_nl"*"$as_nl"* )
-      at_print_banners=: ;;
+# Should we print banners?  Yes if more than one test is run.
+case $at_groups in #(
+  *$as_nl* )
+      at_print_banners=: ;; #(
   * ) at_print_banners=false ;;
 esac
 # Text for banner N, set to a single space once printed.
@@ -435,14 +433,14 @@ at_color=m4_ifdef([AT_color], [AT_color], [no])
 # List of the tested programs.
 at_tested='m4_ifdef([AT_tested],
   [m4_translit(m4_dquote(m4_defn([AT_tested])), [ ], m4_newline)])'
-# List of the all the test groups.
-at_groups_all='AT_groups_all'
 # As many question marks as there are digits in the last test group number.
 # Used to normalize the test group numbers so that `ls' lists them in
 # numerical order.
 at_format='m4_bpatsubst(m4_defn([AT_ordinal]), [.], [?])'
 # Description of all the test groups.
 at_help_all="AS_ESCAPE(m4_dquote(m4_defn([AT_help_all])))"
+# List of the all the test groups.
+at_groups_all=`AS_ECHO(["$at_help_all"]) | sed 's/;.*//'`
 
 AS_FUNCTION_DESCRIBE([at_fn_validate_ranges], [NAME...],
 [Validate and normalize the test group number contained in each
@@ -535,24 +533,24 @@ do
 
     [[0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9]])
        at_fn_validate_ranges at_option
-       AS_VAR_APPEND([at_groups], ["$at_option "])
+       AS_VAR_APPEND([at_groups], ["$at_option$as_nl"])
        ;;
 
     # Ranges
     [[0-9]- | [0-9][0-9]- | [0-9][0-9][0-9]- | [0-9][0-9][0-9][0-9]-])
        at_range_start=`echo $at_option |tr -d X-`
        at_fn_validate_ranges at_range_start
-       at_range=`AS_ECHO([" $at_groups_all "]) | \
-         sed -e 's/^.* \('$at_range_start' \)/\1/'`
-       AS_VAR_APPEND([at_groups], ["$at_range "])
+       at_range=`AS_ECHO(["$at_groups_all"]) | \
+         sed -ne '/^'$at_range_start'$/,$p'`
+       AS_VAR_APPEND([at_groups], ["$at_range$as_nl"])
        ;;
 
     [-[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | -[0-9][0-9][0-9][0-9]])
        at_range_end=`echo $at_option |tr -d X-`
        at_fn_validate_ranges at_range_end
-       at_range=`AS_ECHO([" $at_groups_all "]) | \
-         sed -e 's/\( '$at_range_end'\) .*$/\1/'`
-       AS_VAR_APPEND([at_groups], ["$at_range "])
+       at_range=`AS_ECHO(["$at_groups_all"]) | \
+         sed -ne '1,/^'$at_range_end'$/p'`
+       AS_VAR_APPEND([at_groups], ["$at_range$as_nl"])
        ;;
 
     [[0-9]-[0-9] | [0-9]-[0-9][0-9] | [0-9]-[0-9][0-9][0-9]] | \
@@ -569,10 +567,9 @@ do
          at_range_start=$at_tmp
        fi
        at_fn_validate_ranges at_range_start at_range_end
-       at_range=`AS_ECHO([" $at_groups_all "]) | \
-         sed -e 's/^.*\( '$at_range_start' \)/\1/' \
-             -e 's/\( '$at_range_end'\) .*$/\1/'`
-       AS_VAR_APPEND([at_groups], ["$at_range "])
+       at_range=`AS_ECHO(["$at_groups_all"]) | \
+         sed -ne '/^'$at_range_start'$/,/^'$at_range_end'$/p'`
+       AS_VAR_APPEND([at_groups], ["$at_range$as_nl"])
        ;;
 
     # Directory selection.
@@ -627,11 +624,9 @@ do
          at_groups_selected=`AS_ECHO(["$at_groups_selected"]) |
              grep -i $at_invert ["^[1-9][^;]*;.*[; ]$at_keyword[ ;]"]`
        done
-       # Smash the newlines.
-       at_groups_selected=`AS_ECHO(["$at_groups_selected"]) | sed 's/;.*//' |
-         tr "$as_nl" ' '
-       `
-       AS_VAR_APPEND([at_groups], ["$at_groups_selected "])
+       # Smash the keywords.
+       at_groups_selected=`AS_ECHO(["$at_groups_selected"]) | sed 's/;.*//'`
+       AS_VAR_APPEND([at_groups], ["$at_groups_selected$as_nl"])
        ;;
     --recheck)
        at_recheck=:
@@ -679,11 +674,11 @@ else
        s/^[ ]*\([1-9][0-9]*\):.*/\1/p
       }
       /^## Detailed failed tests/q
-      '] "$at_suite_log" | tr "$as_nl" ' '`
-    AS_VAR_APPEND([at_groups], ["$at_oldfails"])
+      '] "$at_suite_log"`
+    AS_VAR_APPEND([at_groups], ["$at_oldfails$as_nl"])
   fi
   # Sort the tests, removing duplicates.
-  at_groups=`AS_ECHO(["$at_groups"]) | tr ' ' "$as_nl" | sort -nu`
+  at_groups=`AS_ECHO(["$at_groups"]) | sort -nu | sed '/^$/d'`
 fi
 
 if test x"$at_color" = xalways \
@@ -777,21 +772,13 @@ AT_TESTSUITE_NAME test groups:
       KEYWORDS
 
 _ATEOF
-  # Passing at_groups is tricky.  We cannot use it to form a literal string
-  # or regexp because of the limitation of AIX awk.  And Solaris' awk
-  # doesn't grok more than 99 fields in a record, so we have to use `split'.
-  # at_groups needs to be space-separated for this script to work.
-  case $at_groups in
-    *"$as_nl"* )
-      at_groups=`AS_ECHO(["$at_groups"]) | tr "$as_nl" ' '` ;;
-  esac
-  AS_ECHO(["$at_groups$as_nl$at_help_all"]) |
-    awk 'BEGIN { FS = ";" }
-        NR == 1 {
-          for (n = split ($ 0, a, " "); n; n--)
-            selected[[a[n]]] = 1
+  # Pass an empty line as separator between selected groups and help.
+  AS_ECHO(["$at_groups$as_nl$as_nl$at_help_all"]) |
+    awk 'NF == 1 && FS != ";" {
+          selected[[$ 1]] = 1
           next
         }
+        /^$/ { FS = ";" }
         NF > 0 {
           if (selected[[$ 1]]) {
             printf " %3d: %-18s %s\n", $ 1, $ 2, $ 3
@@ -1388,8 +1375,7 @@ dnl cause changed test semantics; e.g., a sleep will be 
interrupted.
 
   echo
   # Turn jobs into a list of numbers, starting from 1.
-  at_joblist=`AS_ECHO([" $at_groups_all "]) | \
-    sed 's/\( '$at_jobs'\) .*/\1/'`
+  at_joblist=`AS_ECHO(["$at_groups"]) | sed -n 1,${at_jobs}p`
 
   set X $at_joblist
   shift
@@ -1840,7 +1826,6 @@ m4_define([AT_line], AT_LINE)
 m4_define([AT_xfail], [at_xfail=no])
 m4_define([AT_description], m4_expand([$1]))
 m4_define([AT_ordinal], m4_incr(AT_ordinal))
-m4_append([AT_groups_all], [ ]m4_defn([AT_ordinal]))
 m4_divert_push([TEST_GROUPS])dnl
 [#AT_START_]AT_ordinal
 at_fn_group_banner AT_ordinal 'm4_defn([AT_line])' \
diff --git a/tests/autotest.at b/tests/autotest.at
index 7c0a7df..dea1350 100644
--- a/tests/autotest.at
+++ b/tests/autotest.at
@@ -775,6 +775,20 @@ AT_CHECK([:])
 ])
 
 
+## ---------------- ##
+## Huge testsuite.  ##
+## ---------------- ##
+
+# Ensure we don't hit line length limits with large test suites.
+
+AT_CHECK_AT_TEST([Huge testsuite],
+[m4_for([nnn], [1], [1999], [],
+[AT_CLEANUP
+AT_SETUP([test ]nnn)
+])
+], [], [], [], [ignore], [], [], [1999])
+
+
 ## ----------------- ##
 ## Debugging a test. ##
 ## ----------------- ##



reply via email to

[Prev in Thread] Current Thread [Next in Thread]