From: Alexandre Duret-Lutz Date: Sun, 21 Nov 2004 23:31:45 +0000 (+0000) Subject: * automake.in (parse_arguments): Diagnose empty arguments, options X-Git-Tag: Release-1-9b~252 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6da85a6a6ca544d90dadb95e136ee950322b753;p=thirdparty%2Fautomake.git * 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. --- diff --git a/ChangeLog b/ChangeLog index 2657567bd..4a60f5895 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2004-11-21 Alexandre Duret-Lutz + * 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. diff --git a/aclocal.in b/aclocal.in index 3cbee97de..1f8583a68 100644 --- a/aclocal.in +++ b/aclocal.in @@ -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) diff --git a/automake.in b/automake.in index fffa548d8..9437f9253 100755 --- a/automake.in +++ b/automake.in @@ -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); diff --git a/tests/Makefile.am b/tests/Makefile.am index f126d7904..3efb44e8b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -53,6 +53,7 @@ autohdr.test \ autohdr2.test \ autohdr3.test \ autohdr4.test \ +automake.test \ auxdir.test \ auxdir2.test \ auxdir3.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 31f799c4d..f53831506 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -172,6 +172,7 @@ autohdr.test \ autohdr2.test \ autohdr3.test \ autohdr4.test \ +automake.test \ auxdir.test \ auxdir2.test \ auxdir3.test \ diff --git a/tests/aclocal.test b/tests/aclocal.test index a1e22987e..9ad7f5dd9 100755 --- a/tests/aclocal.test +++ b/tests/aclocal.test @@ -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 index 000000000..60dceca31 --- /dev/null +++ b/tests/automake.test @@ -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 diff --git a/tests/postproc.test b/tests/postproc.test index 7ff3502ac..7259b29d8 100755 --- a/tests/postproc.test +++ b/tests/postproc.test @@ -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