]> sourceware.org Git - automake.git/commitdiff
* automake.in (parse_arguments): Diagnose empty arguments, options
authorAlexandre Duret-Lutz <adl@gnu.org>
Sun, 21 Nov 2004 23:31:43 +0000 (23:31 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Sun, 21 Nov 2004 23:31:43 +0000 (23:31 +0000)
with missing argument, and support `--'.
* aclocal.in (parse_arguments): Diagnose options with missing
argument.
* tests/aclocal.test: More checks.
* tests/automake.test: New file.
* tests/postprog.test: Use `--' for fun.
* tests/Makefile.am (TESTS): Add automake.test.
Report from Eric Blake.

ChangeLog
aclocal.in
automake.in
tests/Makefile.am
tests/Makefile.in
tests/aclocal.test
tests/automake.test [new file with mode: 0755]
tests/postproc.test

index 2657567bd603007a6a8159772084ae379d687662..4a60f5895adb3af866c2dabd3c394e9d2ccc31dc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2004-11-21  Alexandre Duret-Lutz  <adl@gnu.org>
 
+       * automake.in (parse_arguments): Diagnose empty arguments, options
+       with missing argument, and support `--'.
+       * aclocal.in (parse_arguments): Diagnose options with missing
+       argument.
+       * tests/aclocal.test: More checks.
+       * tests/automake.test: New file.
+       * tests/postprog.test: Use `--' for fun.
+       * tests/Makefile.am (TESTS): Add automake.test.
+       Report from Eric Blake.
+
        * lib/am/progs.am (installcheck-%DIR%PROGRAMS): Run programs with
        /dev/null as input, so we do not hang on programs that read their
        input without supporting --help and --version.
index 3cbee97de2f57bf1432b8bf4b66d8ae7751c96a4..1f8583a6808849a545ff61b09a63aeebc36f7330 100644 (file)
@@ -636,7 +636,7 @@ sub parse_arguments ()
      'output=s'                => \$output_file,
      'print-ac-dir'     => \$print_and_exit,
      'verbose'         => sub { setup_channel 'verb', silent => 0; },
-     'W|warnings:s'     => \&parse_warnings,
+     'W|warnings=s'     => \&parse_warnings,
      );
   use Getopt::Long;
   Getopt::Long::config ("bundling", "pass_through");
@@ -666,8 +666,25 @@ sub parse_arguments ()
 
   if (@ARGV)
     {
-      fatal ("unrecognized option `$ARGV[0]'\n"
-            . "Try `$0 --help' for more information.");
+      my %argopts;
+      for my $k (keys %cli_options)
+       {
+         if ($k =~ /(.*)=s$/)
+           {
+             map { $argopts{(length ($_) == 1)
+                            ? "-$_" : "--$_" } = 1; } (split (/\|/, $1));
+           }
+       }
+      if (exists $argopts{$ARGV[0]})
+       {
+         fatal ("option `$ARGV[0]' requires an argument\n"
+                . "Try `$0 --help' for more information.");
+       }
+      else
+       {
+         fatal ("unrecognized option `$ARGV[0]'\n"
+                . "Try `$0 --help' for more information.");
+       }
     }
 
   if ($print_and_exit)
index fffa548d8e077415164167b7767fabe1eb3fc352..9437f925358bdbc6d6d963aeac87c6f42098a821 100755 (executable)
@@ -7433,7 +7433,7 @@ sub parse_arguments ()
   my $cli_where = new Automake::Location;
   my %cli_options =
     (
-     'libdir:s'        => \$libdir,
+     'libdir=s'        => \$libdir,
      'gnu'             => sub { set_strictness ('gnu'); },
      'gnits'           => sub { set_strictness ('gnits'); },
      'cygnus'          => sub { set_global_option ('cygnus', $cli_where); },
@@ -7443,11 +7443,11 @@ sub parse_arguments ()
                                                    $cli_where); },
      'no-force'        => sub { $force_generation = 0; },
      'f|force-missing'  => \$force_missing,
-     'o|output-dir:s'  => \$output_directory,
+     'o|output-dir=s'  => \$output_directory,
      'a|add-missing'   => \$add_missing,
      'c|copy'          => \$copy_missing,
      'v|verbose'       => sub { setup_channel 'verb', silent => 0; },
-     'W|warnings:s'     => \&parse_warnings,
+     'W|warnings=s'     => \&parse_warnings,
      # These long options (--Werror and --Wno-error) for backward
      # compatibility.  Use -Werror and -Wno-error today.
      'Werror'           => sub { parse_warnings 'W', 'error'; },
@@ -7489,14 +7489,40 @@ sub parse_arguments ()
       $output_directory = '.';
     }
 
-  my $errspec = 0;
-  foreach my $arg (@ARGV)
+  return unless @ARGV;
+
+  if ($ARGV[0] =~ /^-./)
     {
-      if ($arg =~ /^-./)
+      my %argopts;
+      for my $k (keys %cli_options)
+       {
+         if ($k =~ /(.*)=s$/)
+           {
+             map { $argopts{(length ($_) == 1)
+                            ? "-$_" : "--$_" } = 1; } (split (/\|/, $1));
+           }
+       }
+      if ($ARGV[0] eq '--')
+       {
+         shift @ARGV;
+       }
+      elsif (exists $argopts{$ARGV[0]})
        {
-         fatal ("unrecognized option `$arg'\n"
+         fatal ("option `$ARGV[0]' requires an argument\n"
                 . "Try `$0 --help' for more information.");
        }
+      else
+       {
+         fatal ("unrecognized option `$ARGV[0]'.\n"
+                . "Try `$0 --help' for more information.");
+       }
+    }
+
+  my $errspec = 0;
+  foreach my $arg (@ARGV)
+    {
+      fatal ("empty argument\nTry `$0 --help' for more information.")
+       if ($arg eq '');
 
       # Handle $local:$input syntax.
       my ($local, @rest) = split (/:/, $arg);
index f126d79041c075e17ea0f7459446921c29009c4c..3efb44e8bf3518b51ca40546a17a720b3a4eb7b7 100644 (file)
@@ -53,6 +53,7 @@ autohdr.test \
 autohdr2.test \
 autohdr3.test \
 autohdr4.test \
+automake.test \
 auxdir.test \
 auxdir2.test \
 auxdir3.test \
index 31f799c4df002b1ad53659dd1eb693c04909e9b7..f53831506d6563956506159f48b16cfb4aba7b0d 100644 (file)
@@ -172,6 +172,7 @@ autohdr.test \
 autohdr2.test \
 autohdr3.test \
 autohdr4.test \
+automake.test \
 auxdir.test \
 auxdir2.test \
 auxdir3.test \
index a1e22987e6af7fcae050f4069e2afd208cb99e82..9ad7f5dd903d637391b66c49a687533d52c75369 100755 (executable)
@@ -27,7 +27,12 @@ set -e
 $ACLOCAL --output=fred
 test -f fred
 
+$ACLOCAL --output 2>stderr && exit 1
+grep 'option.*--output.*an argument' stderr
+grep help stderr
+
 $ACLOCAL --unknown-option 2>stderr && exit 1
+grep 'unrecognized.*--unknown-option' stderr
 grep help stderr
 
 test "`$ACLOCAL --print-ac-dir`" = "$testaclocaldir"
diff --git a/tests/automake.test b/tests/automake.test
new file mode 100755 (executable)
index 0000000..60dceca
--- /dev/null
@@ -0,0 +1,39 @@
+#! /bin/sh
+# Copyright (C) 2004  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake 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.
+#
+# GNU Automake 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 Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# Test Automake's command-line options.
+. ./defs || exit 1
+
+set -e
+
+$AUTOMAKE --help
+$AUTOMAKE --version
+AUTOMAKE_fails --voo
+grep 'unrecognized option.*--voo' stderr
+AUTOMAKE_fails -- --voo
+grep 'input file.*--voo' stderr
+AUTOMAKE_fails ''
+grep 'empty argument' stderr
+AUTOMAKE_fails -W
+grep 'option.*-W.*requires an argument' stderr
+AUTOMAKE_fails --warnings
+grep 'option.*--warning.*requires an argument' stderr
+AUTOMAKE_fails --warnings --help
+grep 'unknown warning.*--help' stderr
index 7ff3502acd0ee0a19b16b2587cb308df04758b74..7259b29d86600b3a83c7854225f817d4ef4f2ea0 100755 (executable)
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2002  Free Software Foundation, Inc.
+# Copyright (C) 2002, 2004  Free Software Foundation, Inc.
 #
 # This file is part of GNU Automake.
 #
@@ -38,7 +38,7 @@ END
 
 $ACLOCAL || exit 1
 $AUTOCONF || exit 1
-$AUTOMAKE myMakefile || exit 1
+$AUTOMAKE -- myMakefile || exit 1
 
 mv myMakefile.in myMakefile.old
 echo '# Post-processed by post-processor 3.14.' > myMakefile.in
This page took 0.052411 seconds and 5 git commands to generate.