[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
main: fix error message for missing argument
From: |
Akim Demaille |
Subject: |
main: fix error message for missing argument |
Date: |
Thu, 4 Oct 2018 22:22:10 +0200 |
I was surprised to see:
$ LC_ALL=C bison --defines
bison: --defines: missing operand
Try 'bison --help' for more information.
This must be quite an old error.
I confess I’m confused with the way program_name works: sometimes
it’s complete, sometimes it’s the only basename (because getprogname
and program_name are not the same). So our error messages are
inconsistent.
Messages from getopt(), full path:
$ LC_ALL=C /opt/local/bin/bison --asd
/opt/local/bin/bison: unrecognized option '--asd'
Try ‘/opt/local/bin/bison --help' for more information.
Messages from error(), base name:
$ LC_ALL=C /opt/local/bin/bison 1 2 3
bison: extra operand '2'
Try '/opt/local/bin/bison --help' for more information.
I’ve had a look at the coreutils, I don’t understand what the
difference is. It’s not really a big problem, but…
‘Operand’ sounds a bit weird. I’d rather use ‘argument’.
commit bae14b08b002495416870c7488f0f2f1d184c962
Author: Akim Demaille <address@hidden>
Date: Thu Oct 4 21:38:32 2018 +0200
main: fix error message for missing argument
* src/getargs.c (getargs): Don't display any argv other that argv[0]
when reporting a missing argument.
* tests/bison.in: Neutralize path differences in stderr.
* tests/input.at (Invalid number of arguments): New.
diff --git a/src/getargs.c b/src/getargs.c
index 95c681b5..ac9f11c8 100644
--- a/src/getargs.c
+++ b/src/getargs.c
@@ -724,7 +724,7 @@ getargs (int argc, char *argv[])
if (argc - optind != 1)
{
if (argc - optind < 1)
- error (0, 0, _("%s: missing operand"), quotearg_colon (argv[argc -
1]));
+ error (0, 0, _("missing operand"));
else
error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
usage (EXIT_FAILURE);
diff --git a/tests/bison.in b/tests/bison.in
index d3b8ba61..99f7ef40 100644
--- a/tests/bison.in
+++ b/tests/bison.in
@@ -25,9 +25,15 @@ abs_top_builddir='@abs_top_builddir@'
BISON_PKGDATADIR=$abs_top_srcdir/data
export BISON_PKGDATADIR
-$PREBISON "$abs_top_builddir/src/bison" ${1+"$@"}
+stderr=tmp-bison.$$
+$PREBISON "$abs_top_builddir/src/bison" ${1+"$@"} 2>"$stderr"
status=$?
+# Neutralize path differences in error messages so that check and
+# installcheck behave the same way.
+sed -e "s,$abs_top_builddir/src/,,g" <"$stderr" >&2
+rm -f "$stderr"
+
# As a special dark magic, if we are actually using this wrapper to
# compile Bison's src/parse-gram.y, post-process the synclines to
# avoid dependencies on the user's set up (srcdir vs. builddir).
diff --git a/tests/input.at b/tests/input.at
index 527c0398..9b8c453b 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -20,6 +20,31 @@ AT_BANNER([[Input Processing.]])
# Mostly test that we are robust to mistakes.
+## ----------------------------- ##
+## Invalid number of arguments. ##
+## ----------------------------- ##
+
+AT_SETUP([Invalid number of arguments])
+
+AT_BISON_CHECK([], [1], [],
+[[bison: missing operand
+Try 'bison --help' for more information.
+]])
+
+AT_BISON_CHECK([1.y 2.y], [1], [],
+[[bison: extra operand '2.y'
+Try 'bison --help' for more information.
+]])
+
+AT_BISON_CHECK([--skeleton], [1], [],
+[[bison: option '--skeleton' requires an argument
+Try 'bison --help' for more information.
+]])
+
+AT_CLEANUP
+
+
+
## ----------------- ##
## Invalid options. ##
## ----------------- ##
- main: fix error message for missing argument,
Akim Demaille <=