tests: expose automake bug#14560
[platform/upstream/automake.git] / gen-testsuite-part
index 0021362..4584d2b 100755 (executable)
@@ -3,7 +3,7 @@
 # of the Automake testsuite.  Also, automatically generate some more
 # tests from them (for particular cases/setups only).
 
-# Copyright (C) 2011-2012 Free Software Foundation, Inc.
+# Copyright (C) 2011-2013 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
@@ -31,6 +31,13 @@ my $me = File::Basename::basename $0;
 # For use in VPATH builds.
 my $srcdir = ".";
 
+# The testsuite subdirectory, relative to the top-lever source directory.
+my $testdir = "t";
+
+# Where testsuite-related helper scripts, data files and shell libraries
+# are placed.  Relative to the top-lever source directory.
+my $testauxdir = "$testdir/ax";
+
 #--------------------------------------------------------------------------
 
 sub unindent ($)
@@ -89,14 +96,14 @@ sub write_wrapper_script ($$$)
   print $file_handle unindent <<EOF;
     #! /bin/sh
     # This file has been automatically generated.  DO NOT EDIT BY HAND!
-    . ./defs-static || exit 1
+    . test-lib.sh
     $shell_setup_code
     # In the spirit of VPATH, we prefer a test in the build tree
     # over one in the source tree.
     for dir in . "\$am_top_srcdir"; do
       if test -f "\$dir/$wrapped_test"; then
         echo "\$0: will source \$dir/$wrapped_test"
-        . "\$dir/$wrapped_test"; exit "\$?"
+        . "\$dir/$wrapped_test"; exit \$?
       fi
     done
     echo "\$0: cannot find wrapped test '$wrapped_test'" >&2
@@ -109,7 +116,7 @@ sub get_list_of_tests ()
   my $make = defined $ENV{MAKE} ? $ENV{MAKE} : "make";
   # Unset MAKEFLAGS, for when we are called from make itself.
   my $cmd = "MAKEFLAGS= && unset MAKEFLAGS && cd '$srcdir' && "
-            . "$make -s -f t/list-of-tests.mk print-list-of-tests";
+            . "$make -s -f $testdir/list-of-tests.mk print-list-of-tests";
   my @tests_list = split /\s+/, `$cmd`;
   die "$me: cannot get list of tests\n" unless $? == 0 && @tests_list;
   my $ok = 1;
@@ -135,52 +142,53 @@ sub parse_options (@)
 
 #--------------------------------------------------------------------------
 
-# Where testsuite-related helper scripts, data files and shell libraries
-# are placed.  Relative to the 't/' subdirectory.
-my $auxdir = "ax";
-
 my %deps_extractor =
   (
     libtool_macros =>
       {
         line_matcher => qr/^\s*required=.*\blibtool/,
-        nodist_prereqs => "t/libtool-macros.log",
+        nodist_prereqs => "$testdir/libtool-macros.log",
       },
     gettext_macros =>
       {
         line_matcher => qr/^\s*required=.*\bgettext/,
-        nodist_prereqs => "t/gettext-macros.log",
+        nodist_prereqs => "$testdir/gettext-macros.log",
+      },
+    pkgconfig_macros =>
+      {
+        line_matcher => qr/^\s*required=.*\bpkg-config/,
+        nodist_prereqs => "$testdir/pkg-config-macros.log",
       },
     use_trivial_test_driver =>
       {
         line_matcher => qr/\btrivial-test-driver\b/,
-        dist_prereqs => "t/$auxdir/trivial-test-driver",
+        dist_prereqs => "$testauxdir/trivial-test-driver",
       },
     check_testsuite_summary =>
       {
         line_matcher => qr/\btestsuite-summary-checks\.sh\b/,
-        dist_prereqs => "t/$auxdir/testsuite-summary-checks.sh",
+        dist_prereqs => "$testauxdir/testsuite-summary-checks.sh",
       },
     extract_testsuite_summary =>
       {
         line_matcher => qr/\bextract-testsuite-summary\.pl\b/,
-        dist_prereqs => "t/$auxdir/extract-testsuite-summary.pl",
+        dist_prereqs => "$testauxdir/extract-testsuite-summary.pl",
       },
     check_tap_testsuite_summary =>
       {
         line_matcher => qr/\btap-summary-aux\.sh\b/,
-        dist_prereqs => "t/$auxdir/tap-summary-aux.sh",
+        dist_prereqs => "$testauxdir/tap-summary-aux.sh",
       },
     on_tap_with_common_setup =>
       {
         line_matcher => qr/\btap-setup\.sh\b/,
-        dist_prereqs => "t/$auxdir/tap-setup.sh",
-        nodist_prereqs => "t/tap-common-setup.log",
+        dist_prereqs => "$testauxdir/tap-setup.sh",
+        nodist_prereqs => "$testdir/tap-common-setup.log",
       },
     depcomp =>
       {
         line_matcher => qr/\bdepcomp\.sh\b/,
-        dist_prereqs => "t/$auxdir/depcomp.sh",
+        dist_prereqs => "$testauxdir/depcomp.sh",
       },
   );
 
@@ -267,37 +275,55 @@ print <<EOF;
 
 EOF
 
-# FIXME: the following is not really right, since cannot compose wrapping
-# of tests matching more than one condition.  Still, there should be no
-# such test at the moment, so the limitation is (temporarily) acceptable.
-while (my ($k, $g) = each %test_generators)
+# A test script '$test' can possibly match more than one condition, so
+# for each tests we need to keep a list of generated wrapper tests.
+# Since what defines these wrapper scripts is the set of initializations
+# that are issued before sourcing the original, wrapped tests, these
+# initializations is what we put in our list entries.
+# The list will be saved in the hash entry '$wrapper_setups{$test}'.
+my %wrapper_setups = ();
+foreach my $test (@all_tests)
+  {
+    my @setups = ('');
+    foreach my $x (values %test_generators)
+    {
+      next
+        if not line_match $x->{line_matcher}, $test;
+      next
+        if $x->{line_rejecter} and line_match $x->{line_rejecter}, $test;
+      @setups = map { ($_, "$_\n$x->{shell_setup_code}") } @setups;
+    }
+    @setups = grep { $_ ne '' } @setups;
+    $wrapper_setups{$test} = \@setups if @setups;
+  }
+# And now create all the wrapper tests.
+while (my ($wrapped_test, $setup_list) = each %wrapper_setups)
   {
-    my @wrapped_tests = grep {
-      line_match ($g->{line_matcher}, $_)
-        && (!$g->{line_rejecter} || !line_match ($g->{line_rejecter}, $_))
-    } @all_tests;
-    foreach my $wrapped_test (@wrapped_tests)
+    (my $base = $wrapped_test) =~ s/\.([^.]*)$//;
+    my $suf = $1 or die "$me: test '$wrapped_test' lacks a suffix\n";
+    my $count = 0;
+    foreach my $setup (@$setup_list)
       {
-        (my $base = $wrapped_test) =~ s/\.([^.]*)$//;
-        my $suf = $1 or die "$me: test '$wrapped_test' lacks a suffix\n";
-        my $wrapper_test =  "$base-w.$suf";
+        $count++;
+        my $wbase = "$base-w" . ($count > 1 ? $count : '');
+        my $wrapper_test =  "$wbase.$suf";
         # Register wrapper test as "autogenerated".
         push @generated_tests, $wrapper_test;
         # Create wrapper test.
         atomic_write $wrapper_test,
                      sub { write_wrapper_script $_[0], $wrapped_test,
-                           $g->{shell_setup_code} },
-                     0555;
+                                                $setup },
+                     0444;
         # The generated test works by sourcing the original test, so that
         # it has to be re-run every time that changes ...
-        print "$base-w.log: $wrapped_test\n";
+        print "$wbase.log: $wrapped_test\n";
         # ... but also every time the prerequisites of the wrapped test
         # changes.  The simpler (although suboptimal) way to do so is to
-        # ensure that the wrapped tests runs before the wrappee one (in
-        # case it needs to be re-run *at all*.
+        # ensure that the wrapped tests runs before the wrapper one (in
+        # case it needs to be re-run *at all*).
         # FIXME: we could maybe refactor the script to find a more
         # granular way to express such implicit dependencies.
-        print "$base-w.log: $base.log\n";
+        print "$wbase.log: $base.log\n";
       }
   }
 
@@ -319,8 +345,11 @@ my %depmodes =
     makedepend   => ["cc", "makedepend"],
     dashmstdout  => ["gcc"],
     cpp          => ["gcc"],
-# This is for older (pre-3.x) GCC versions.  Newer versions
-# have depmode "gcc3".
+# This was for older (pre-3.x) GCC versions (newer versions
+# have depmode "gcc3").  But other compilers use this depmode
+# as well (for example, the IMB xlc/xlC compilers, and the HP
+# C compiler, see 'lib/depcomp' for more info), so it's not
+# obsolete, and it's worth giving it some coverage.
     gcc          => ["gcc"],
 # This is for older (pre-7) msvc versions.  Newer versions
 # have depmodes "msvc7" and "msvc7msys".
@@ -344,7 +373,7 @@ foreach my $lt (TRUE, FALSE)
             "depmode=$m",
             "depcomp_with_libtool=" . ($lt ? "yes" : "no"),
           );
-        my $test = "t/depcomp" . ($lt ? "-lt-" : "-") . $m . ".tap";
+        my $test = "$testdir/depcomp" . ($lt ? "-lt-" : "-") . "$m.tap";
         # Register wrapper test as "autogenerated" ...
         push @generated_tests, $test;
         # ... and create it.
@@ -356,12 +385,13 @@ foreach my $lt (TRUE, FALSE)
               # Automatically generated test.  DO NOT EDIT BY HAND!
               @vars_init
               required="@required"
-              . ./defs || exit 1
+              . test-init.sh
               plan_ $planned
-              . "\$am_testauxdir/depcomp.sh"; exit "\$?"
+              . depcomp.sh
+              exit \$?
 EOF
           },
-          0555);
+          0444);
       }
    }