aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Voelker <mail@bernhard-voelker.de>2018-10-21 21:56:43 +0200
committerBernhard Voelker <mail@bernhard-voelker.de>2018-10-26 10:54:11 +0200
commit7fd7709a7a5f3537f2f373dcc57e17001830591e (patch)
tree72512cd42ebb7bc8a1e2a28a725b679587c5e78a
parenttest: remove support for the ambigous -a unary operator (diff)
downloadcoreutils-7fd7709a7a5f3537f2f373dcc57e17001830591e.tar.gz
coreutils-7fd7709a7a5f3537f2f373dcc57e17001830591e.zip
test: simplify redundant code
Remove the function 'test_unop', as the cases therein are redundant to those handled by 'unary_operator'; exception: the cases 'o' and 'N': they had been present in test_unop and handling the commands test -N STR test -o STR and test x = x -a -N STR test x = x -a -o STR which ran into an error later on anyway. With this commit, the error diagnostic will change from ... $ /usr/bin/test -N STR /usr/bin/test: extra argument '-N' $ /usr/bin/test -o STR /usr/bin/test: extra argument '-o' ... to ... $ src/test -N STR src/test: '-N': unary operator expected $ src/test -o STR src/test: '-o': unary operator expected * src/test.c (test_unop): Remove. (unary_operator): Fail with test_syntax_error in the default case. (term): Directly call unary_operator. (two_arguments): Likewise. * tests/misc/test-diag.pl: Adjust error diagnostic.
-rw-r--r--src/test.c34
-rwxr-xr-xtests/misc/test-diag.pl4
2 files changed, 5 insertions, 33 deletions
diff --git a/src/test.c b/src/test.c
index 339a84075..9005b1962 100644
--- a/src/test.c
+++ b/src/test.c
@@ -72,7 +72,6 @@ static int pos; /* The offset of the current argument in ARGV. */
static int argc; /* The number of arguments present in ARGV. */
static char **argv; /* The argument list. */
-static bool test_unop (char const *s);
static bool unary_operator (void);
static bool binary_operator (bool);
static bool two_arguments (void);
@@ -258,12 +257,7 @@ term (void)
/* It might be a switch type argument. */
else if (argv[pos][0] == '-' && argv[pos][1] && argv[pos][2] == '\0')
- {
- if (test_unop (argv[pos]))
- value = unary_operator ();
- else
- test_syntax_error (_("%s: unary operator expected"), quote (argv[pos]));
- }
+ value = unary_operator ();
else
{
value = (argv[pos][0] != '\0');
@@ -399,6 +393,7 @@ unary_operator (void)
switch (argv[pos][1])
{
default:
+ test_syntax_error (_("%s: unary operator expected"), quote (argv[pos]));
return false;
/* All of the following unary operators use unary_advance (), which
@@ -576,26 +571,6 @@ expr (void)
return or (); /* Same with this. */
}
-/* Return true if OP is one of the test command's unary operators. */
-static bool
-test_unop (char const *op)
-{
- if (op[0] != '-')
- return false;
-
- switch (op[1])
- {
- case 'b': case 'c': case 'd': case 'e':
- case 'f': case 'g': case 'h': case 'k': case 'n':
- case 'o': case 'p': case 'r': case 's': case 't':
- case 'u': case 'w': case 'x': case 'z':
- case 'G': case 'L': case 'O': case 'S': case 'N':
- return true;
- default:
- return false;
- }
-}
-
static bool
one_argument (void)
{
@@ -616,10 +591,7 @@ two_arguments (void)
&& argv[pos][1] != '\0'
&& argv[pos][2] == '\0')
{
- if (test_unop (argv[pos]))
- value = unary_operator ();
- else
- test_syntax_error (_("%s: unary operator expected"), quote (argv[pos]));
+ value = unary_operator ();
}
else
beyond ();
diff --git a/tests/misc/test-diag.pl b/tests/misc/test-diag.pl
index 91356ef56..f543f9f09 100755
--- a/tests/misc/test-diag.pl
+++ b/tests/misc/test-diag.pl
@@ -26,8 +26,8 @@ use strict;
my @Tests =
(
# In coreutils-5.93, this diagnostic lacked the newline.
- ['o', '-o arg', {ERR => "test: extra argument '-o'\n"},
- {ERR_SUBST => 's!^.*:!test:!'},
+ ['o', '-o arg', {ERR => "test: '-o': unary operator expected\n"},
+ {ERR_SUBST => 's!^.*test:!test:!'},
{EXIT => 2}],
);