build: update gnulib submodule to latest
[coreutils.git] / src / test.c
blob65226c535a4b19acba4c03d490b5acbba2cc5ec9
1 /* GNU test program (ksb and mjb) */
3 /* Modified to run with the GNU shell by bfox. */
5 /* Copyright (C) 1987-2015 Free Software Foundation, Inc.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Define TEST_STANDALONE to get the /bin/test version. Otherwise, you get
21 the shell builtin version. */
23 /* Without this pragma, gcc 4.6.2 20111027 mistakenly suggests that
24 the advance function might be candidate for attribute 'pure'. */
25 #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
26 # pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
27 #endif
29 #include <config.h>
30 #include <stdio.h>
31 #include <sys/types.h>
33 #define TEST_STANDALONE 1
35 #ifndef LBRACKET
36 # define LBRACKET 0
37 #endif
39 /* The official name of this program (e.g., no 'g' prefix). */
40 #if LBRACKET
41 # define PROGRAM_NAME "["
42 #else
43 # define PROGRAM_NAME "test"
44 #endif
46 #include "system.h"
47 #include "quote.h"
48 #include "stat-time.h"
49 #include "strnumcmp.h"
51 #if HAVE_SYS_PARAM_H
52 # include <sys/param.h>
53 #endif
55 /* Exit status for syntax errors, etc. */
56 enum { TEST_TRUE, TEST_FALSE, TEST_FAILURE };
58 #if defined TEST_STANDALONE
59 # define test_exit(val) exit (val)
60 # define test_main_return(val) return val
61 #else
62 static jmp_buf test_exit_buf;
63 static int test_error_return = 0;
64 # define test_exit(val) test_error_return = val, longjmp (test_exit_buf, 1)
65 # define test_main_return(val) test_exit (val)
66 #endif /* !TEST_STANDALONE */
68 static int pos; /* The offset of the current argument in ARGV. */
69 static int argc; /* The number of arguments present in ARGV. */
70 static char **argv; /* The argument list. */
72 static bool test_unop (char const *s);
73 static bool unary_operator (void);
74 static bool binary_operator (bool);
75 static bool two_arguments (void);
76 static bool three_arguments (void);
77 static bool posixtest (int);
79 static bool expr (void);
80 static bool term (void);
81 static bool and (void);
82 static bool or (void);
84 static void test_syntax_error (char const *format, char const *arg)
85 ATTRIBUTE_NORETURN;
86 static void beyond (void) ATTRIBUTE_NORETURN;
88 static void
89 test_syntax_error (char const *format, char const *arg)
91 fprintf (stderr, "%s: ", argv[0]);
92 fprintf (stderr, format, arg);
93 fputc ('\n', stderr);
94 fflush (stderr);
95 test_exit (TEST_FAILURE);
98 /* Increment our position in the argument list. Check that we're not
99 past the end of the argument list. This check is suppressed if the
100 argument is false. */
102 static void
103 advance (bool f)
105 ++pos;
107 if (f && pos >= argc)
108 beyond ();
111 static void
112 unary_advance (void)
114 advance (true);
115 ++pos;
119 * beyond - call when we're beyond the end of the argument list (an
120 * error condition)
122 static void
123 beyond (void)
125 test_syntax_error (_("missing argument after %s"), quote (argv[argc - 1]));
128 /* If the characters pointed to by STRING constitute a valid number,
129 return a pointer to the start of the number, skipping any blanks or
130 leading '+'. Otherwise, report an error and exit. */
131 static char const *
132 find_int (char const *string)
134 char const *p;
135 char const *number_start;
137 for (p = string; isblank (to_uchar (*p)); p++)
138 continue;
140 if (*p == '+')
142 p++;
143 number_start = p;
145 else
147 number_start = p;
148 p += (*p == '-');
151 if (ISDIGIT (*p++))
153 while (ISDIGIT (*p))
154 p++;
155 while (isblank (to_uchar (*p)))
156 p++;
157 if (!*p)
158 return number_start;
161 test_syntax_error (_("invalid integer %s"), quote (string));
164 /* Find the modification time of FILE, and stuff it into *MTIME.
165 Return true if successful. */
166 static bool
167 get_mtime (char const *filename, struct timespec *mtime)
169 struct stat finfo;
170 bool ok = (stat (filename, &finfo) == 0);
171 #ifdef lint
172 static struct timespec const zero;
173 *mtime = zero;
174 #endif
175 if (ok)
176 *mtime = get_stat_mtime (&finfo);
177 return ok;
180 /* Return true if S is one of the test command's binary operators. */
181 static bool
182 binop (char const *s)
184 return ((STREQ (s, "=")) || (STREQ (s, "!=")) || (STREQ (s, "==")) ||
185 (STREQ (s, "-nt")) ||
186 (STREQ (s, "-ot")) || (STREQ (s, "-ef")) || (STREQ (s, "-eq")) ||
187 (STREQ (s, "-ne")) || (STREQ (s, "-lt")) || (STREQ (s, "-le")) ||
188 (STREQ (s, "-gt")) || (STREQ (s, "-ge")));
192 * term - parse a term and return 1 or 0 depending on whether the term
193 * evaluates to true or false, respectively.
195 * term ::=
196 * '-'('h'|'d'|'f'|'r'|'s'|'w'|'c'|'b'|'p'|'u'|'g'|'k') filename
197 * '-'('L'|'x') filename
198 * '-t' int
199 * '-'('z'|'n') string
200 * string
201 * string ('!='|'=') string
202 * <int> '-'(eq|ne|le|lt|ge|gt) <int>
203 * file '-'(nt|ot|ef) file
204 * '(' <expr> ')'
205 * int ::=
206 * '-l' string
207 * positive and negative integers
209 static bool
210 term (void)
212 bool value;
213 bool negated = false;
215 /* Deal with leading 'not's. */
216 while (pos < argc && argv[pos][0] == '!' && argv[pos][1] == '\0')
218 advance (true);
219 negated = !negated;
222 if (pos >= argc)
223 beyond ();
225 /* A paren-bracketed argument. */
226 if (argv[pos][0] == '(' && argv[pos][1] == '\0')
228 int nargs;
230 advance (true);
232 for (nargs = 1;
233 pos + nargs < argc && ! STREQ (argv[pos + nargs], ")");
234 nargs++)
235 if (nargs == 4)
237 nargs = argc - pos;
238 break;
241 value = posixtest (nargs);
242 if (argv[pos] == 0)
243 test_syntax_error (_("')' expected"), NULL);
244 else
245 if (argv[pos][0] != ')' || argv[pos][1])
246 test_syntax_error (_("')' expected, found %s"), quote (argv[pos]));
247 advance (false);
250 /* Are there enough arguments left that this could be dyadic? */
251 else if (4 <= argc - pos && STREQ (argv[pos], "-l") && binop (argv[pos + 2]))
252 value = binary_operator (true);
253 else if (3 <= argc - pos && binop (argv[pos + 1]))
254 value = binary_operator (false);
256 /* It might be a switch type argument. */
257 else if (argv[pos][0] == '-' && argv[pos][1] && argv[pos][2] == '\0')
259 if (test_unop (argv[pos]))
260 value = unary_operator ();
261 else
262 test_syntax_error (_("%s: unary operator expected"), quote (argv[pos]));
264 else
266 value = (argv[pos][0] != '\0');
267 advance (false);
270 return negated ^ value;
273 static bool
274 binary_operator (bool l_is_l)
276 int op;
277 struct stat stat_buf, stat_spare;
278 /* Is the right integer expression of the form '-l string'? */
279 bool r_is_l;
281 if (l_is_l)
282 advance (false);
283 op = pos + 1;
285 if ((op < argc - 2) && STREQ (argv[op + 1], "-l"))
287 r_is_l = true;
288 advance (false);
290 else
291 r_is_l = false;
293 if (argv[op][0] == '-')
295 /* check for eq, nt, and stuff */
296 if ((((argv[op][1] == 'l' || argv[op][1] == 'g')
297 && (argv[op][2] == 'e' || argv[op][2] == 't'))
298 || (argv[op][1] == 'e' && argv[op][2] == 'q')
299 || (argv[op][1] == 'n' && argv[op][2] == 'e'))
300 && !argv[op][3])
302 char lbuf[INT_BUFSIZE_BOUND (uintmax_t)];
303 char rbuf[INT_BUFSIZE_BOUND (uintmax_t)];
304 char const *l = (l_is_l
305 ? umaxtostr (strlen (argv[op - 1]), lbuf)
306 : find_int (argv[op - 1]));
307 char const *r = (r_is_l
308 ? umaxtostr (strlen (argv[op + 2]), rbuf)
309 : find_int (argv[op + 1]));
310 int cmp = strintcmp (l, r);
311 bool xe_operator = (argv[op][2] == 'e');
312 pos += 3;
313 return (argv[op][1] == 'l' ? cmp < xe_operator
314 : argv[op][1] == 'g' ? cmp > - xe_operator
315 : (cmp != 0) == xe_operator);
318 switch (argv[op][1])
320 default:
321 break;
323 case 'n':
324 if (argv[op][2] == 't' && !argv[op][3])
326 /* nt - newer than */
327 struct timespec lt, rt;
328 bool le, re;
329 pos += 3;
330 if (l_is_l || r_is_l)
331 test_syntax_error (_("-nt does not accept -l"), NULL);
332 le = get_mtime (argv[op - 1], &lt);
333 re = get_mtime (argv[op + 1], &rt);
334 return le && (!re || timespec_cmp (lt, rt) > 0);
336 break;
338 case 'e':
339 if (argv[op][2] == 'f' && !argv[op][3])
341 /* ef - hard link? */
342 pos += 3;
343 if (l_is_l || r_is_l)
344 test_syntax_error (_("-ef does not accept -l"), NULL);
345 return (stat (argv[op - 1], &stat_buf) == 0
346 && stat (argv[op + 1], &stat_spare) == 0
347 && stat_buf.st_dev == stat_spare.st_dev
348 && stat_buf.st_ino == stat_spare.st_ino);
350 break;
352 case 'o':
353 if ('t' == argv[op][2] && '\000' == argv[op][3])
355 /* ot - older than */
356 struct timespec lt, rt;
357 bool le, re;
358 pos += 3;
359 if (l_is_l || r_is_l)
360 test_syntax_error (_("-ot does not accept -l"), NULL);
361 le = get_mtime (argv[op - 1], &lt);
362 re = get_mtime (argv[op + 1], &rt);
363 return re && (!le || timespec_cmp (lt, rt) < 0);
365 break;
368 /* FIXME: is this dead code? */
369 test_syntax_error (_("%s: unknown binary operator"), quote (argv[op]));
372 if (argv[op][0] == '='
373 && (!argv[op][1] || ((argv[op][1] == '=') && !argv[op][2])))
375 bool value = STREQ (argv[pos], argv[pos + 2]);
376 pos += 3;
377 return value;
380 if (STREQ (argv[op], "!="))
382 bool value = !STREQ (argv[pos], argv[pos + 2]);
383 pos += 3;
384 return value;
387 /* Not reached. */
388 abort ();
391 static bool
392 unary_operator (void)
394 struct stat stat_buf;
396 switch (argv[pos][1])
398 default:
399 return false;
401 /* All of the following unary operators use unary_advance (), which
402 checks to make sure that there is an argument, and then advances
403 pos right past it. This means that pos - 1 is the location of the
404 argument. */
406 case 'a': /* file exists in the file system? */
407 case 'e':
408 unary_advance ();
409 return stat (argv[pos - 1], &stat_buf) == 0;
411 case 'r': /* file is readable? */
412 unary_advance ();
413 return euidaccess (argv[pos - 1], R_OK) == 0;
415 case 'w': /* File is writable? */
416 unary_advance ();
417 return euidaccess (argv[pos - 1], W_OK) == 0;
419 case 'x': /* File is executable? */
420 unary_advance ();
421 return euidaccess (argv[pos - 1], X_OK) == 0;
423 case 'O': /* File is owned by you? */
425 unary_advance ();
426 if (stat (argv[pos - 1], &stat_buf) != 0)
427 return false;
428 errno = 0;
429 uid_t euid = geteuid ();
430 uid_t NO_UID = -1;
431 return ! (euid == NO_UID && errno) && euid == stat_buf.st_uid;
434 case 'G': /* File is owned by your group? */
436 unary_advance ();
437 if (stat (argv[pos - 1], &stat_buf) != 0)
438 return false;
439 errno = 0;
440 gid_t egid = getegid ();
441 gid_t NO_GID = -1;
442 return ! (egid == NO_GID && errno) && egid == stat_buf.st_gid;
445 case 'f': /* File is a file? */
446 unary_advance ();
447 /* Under POSIX, -f is true if the given file exists
448 and is a regular file. */
449 return (stat (argv[pos - 1], &stat_buf) == 0
450 && S_ISREG (stat_buf.st_mode));
452 case 'd': /* File is a directory? */
453 unary_advance ();
454 return (stat (argv[pos - 1], &stat_buf) == 0
455 && S_ISDIR (stat_buf.st_mode));
457 case 's': /* File has something in it? */
458 unary_advance ();
459 return (stat (argv[pos - 1], &stat_buf) == 0
460 && 0 < stat_buf.st_size);
462 case 'S': /* File is a socket? */
463 unary_advance ();
464 return (stat (argv[pos - 1], &stat_buf) == 0
465 && S_ISSOCK (stat_buf.st_mode));
467 case 'c': /* File is character special? */
468 unary_advance ();
469 return (stat (argv[pos - 1], &stat_buf) == 0
470 && S_ISCHR (stat_buf.st_mode));
472 case 'b': /* File is block special? */
473 unary_advance ();
474 return (stat (argv[pos - 1], &stat_buf) == 0
475 && S_ISBLK (stat_buf.st_mode));
477 case 'p': /* File is a named pipe? */
478 unary_advance ();
479 return (stat (argv[pos - 1], &stat_buf) == 0
480 && S_ISFIFO (stat_buf.st_mode));
482 case 'L': /* Same as -h */
483 /*FALLTHROUGH*/
485 case 'h': /* File is a symbolic link? */
486 unary_advance ();
487 return (lstat (argv[pos - 1], &stat_buf) == 0
488 && S_ISLNK (stat_buf.st_mode));
490 case 'u': /* File is setuid? */
491 unary_advance ();
492 return (stat (argv[pos - 1], &stat_buf) == 0
493 && (stat_buf.st_mode & S_ISUID));
495 case 'g': /* File is setgid? */
496 unary_advance ();
497 return (stat (argv[pos - 1], &stat_buf) == 0
498 && (stat_buf.st_mode & S_ISGID));
500 case 'k': /* File has sticky bit set? */
501 unary_advance ();
502 return (stat (argv[pos - 1], &stat_buf) == 0
503 && (stat_buf.st_mode & S_ISVTX));
505 case 't': /* File (fd) is a terminal? */
507 long int fd;
508 char const *arg;
509 unary_advance ();
510 arg = find_int (argv[pos - 1]);
511 errno = 0;
512 fd = strtol (arg, NULL, 10);
513 return (errno != ERANGE && 0 <= fd && fd <= INT_MAX && isatty (fd));
516 case 'n': /* True if arg has some length. */
517 unary_advance ();
518 return argv[pos - 1][0] != 0;
520 case 'z': /* True if arg has no length. */
521 unary_advance ();
522 return argv[pos - 1][0] == '\0';
527 * and:
528 * term
529 * term '-a' and
531 static bool
532 and (void)
534 bool value = true;
536 while (true)
538 value &= term ();
539 if (! (pos < argc && STREQ (argv[pos], "-a")))
540 return value;
541 advance (false);
546 * or:
547 * and
548 * and '-o' or
550 static bool
551 or (void)
553 bool value = false;
555 while (true)
557 value |= and ();
558 if (! (pos < argc && STREQ (argv[pos], "-o")))
559 return value;
560 advance (false);
565 * expr:
566 * or
568 static bool
569 expr (void)
571 if (pos >= argc)
572 beyond ();
574 return or (); /* Same with this. */
577 /* Return true if OP is one of the test command's unary operators. */
578 static bool
579 test_unop (char const *op)
581 if (op[0] != '-')
582 return false;
584 switch (op[1])
586 case 'a': case 'b': case 'c': case 'd': case 'e':
587 case 'f': case 'g': case 'h': case 'k': case 'n':
588 case 'o': case 'p': case 'r': case 's': case 't':
589 case 'u': case 'w': case 'x': case 'z':
590 case 'G': case 'L': case 'O': case 'S': case 'N':
591 return true;
592 default:
593 return false;
597 static bool
598 one_argument (void)
600 return argv[pos++][0] != '\0';
603 static bool
604 two_arguments (void)
606 bool value;
608 if (STREQ (argv[pos], "!"))
610 advance (false);
611 value = ! one_argument ();
613 else if (argv[pos][0] == '-'
614 && argv[pos][1] != '\0'
615 && argv[pos][2] == '\0')
617 if (test_unop (argv[pos]))
618 value = unary_operator ();
619 else
620 test_syntax_error (_("%s: unary operator expected"), quote (argv[pos]));
622 else
623 beyond ();
624 return (value);
627 static bool
628 three_arguments (void)
630 bool value;
632 if (binop (argv[pos + 1]))
633 value = binary_operator (false);
634 else if (STREQ (argv[pos], "!"))
636 advance (true);
637 value = !two_arguments ();
639 else if (STREQ (argv[pos], "(") && STREQ (argv[pos + 2], ")"))
641 advance (false);
642 value = one_argument ();
643 advance (false);
645 else if (STREQ (argv[pos + 1], "-a") || STREQ (argv[pos + 1], "-o"))
646 value = expr ();
647 else
648 test_syntax_error (_("%s: binary operator expected"), quote (argv[pos+1]));
649 return (value);
652 /* This is an implementation of a Posix.2 proposal by David Korn. */
653 static bool
654 posixtest (int nargs)
656 bool value;
658 switch (nargs)
660 case 1:
661 value = one_argument ();
662 break;
664 case 2:
665 value = two_arguments ();
666 break;
668 case 3:
669 value = three_arguments ();
670 break;
672 case 4:
673 if (STREQ (argv[pos], "!"))
675 advance (true);
676 value = !three_arguments ();
677 break;
679 if (STREQ (argv[pos], "(") && STREQ (argv[pos + 3], ")"))
681 advance (false);
682 value = two_arguments ();
683 advance (false);
684 break;
686 /* FALLTHROUGH */
687 case 5:
688 default:
689 if (nargs <= 0)
690 abort ();
691 value = expr ();
694 return (value);
697 #if defined TEST_STANDALONE
699 void
700 usage (int status)
702 if (status != EXIT_SUCCESS)
703 emit_try_help ();
704 else
706 fputs (_("\
707 Usage: test EXPRESSION\n\
708 or: test\n\
709 or: [ EXPRESSION ]\n\
710 or: [ ]\n\
711 or: [ OPTION\n\
712 "), stdout);
713 fputs (_("\
714 Exit with the status determined by EXPRESSION.\n\
716 "), stdout);
717 fputs (HELP_OPTION_DESCRIPTION, stdout);
718 fputs (VERSION_OPTION_DESCRIPTION, stdout);
719 fputs (_("\
721 An omitted EXPRESSION defaults to false. Otherwise,\n\
722 EXPRESSION is true or false and sets exit status. It is one of:\n\
723 "), stdout);
724 fputs (_("\
726 ( EXPRESSION ) EXPRESSION is true\n\
727 ! EXPRESSION EXPRESSION is false\n\
728 EXPRESSION1 -a EXPRESSION2 both EXPRESSION1 and EXPRESSION2 are true\n\
729 EXPRESSION1 -o EXPRESSION2 either EXPRESSION1 or EXPRESSION2 is true\n\
730 "), stdout);
731 fputs (_("\
733 -n STRING the length of STRING is nonzero\n\
734 STRING equivalent to -n STRING\n\
735 -z STRING the length of STRING is zero\n\
736 STRING1 = STRING2 the strings are equal\n\
737 STRING1 != STRING2 the strings are not equal\n\
738 "), stdout);
739 fputs (_("\
741 INTEGER1 -eq INTEGER2 INTEGER1 is equal to INTEGER2\n\
742 INTEGER1 -ge INTEGER2 INTEGER1 is greater than or equal to INTEGER2\n\
743 INTEGER1 -gt INTEGER2 INTEGER1 is greater than INTEGER2\n\
744 INTEGER1 -le INTEGER2 INTEGER1 is less than or equal to INTEGER2\n\
745 INTEGER1 -lt INTEGER2 INTEGER1 is less than INTEGER2\n\
746 INTEGER1 -ne INTEGER2 INTEGER1 is not equal to INTEGER2\n\
747 "), stdout);
748 fputs (_("\
750 FILE1 -ef FILE2 FILE1 and FILE2 have the same device and inode numbers\n\
751 FILE1 -nt FILE2 FILE1 is newer (modification date) than FILE2\n\
752 FILE1 -ot FILE2 FILE1 is older than FILE2\n\
753 "), stdout);
754 fputs (_("\
756 -b FILE FILE exists and is block special\n\
757 -c FILE FILE exists and is character special\n\
758 -d FILE FILE exists and is a directory\n\
759 -e FILE FILE exists\n\
760 "), stdout);
761 fputs (_("\
762 -f FILE FILE exists and is a regular file\n\
763 -g FILE FILE exists and is set-group-ID\n\
764 -G FILE FILE exists and is owned by the effective group ID\n\
765 -h FILE FILE exists and is a symbolic link (same as -L)\n\
766 -k FILE FILE exists and has its sticky bit set\n\
767 "), stdout);
768 fputs (_("\
769 -L FILE FILE exists and is a symbolic link (same as -h)\n\
770 -O FILE FILE exists and is owned by the effective user ID\n\
771 -p FILE FILE exists and is a named pipe\n\
772 -r FILE FILE exists and read permission is granted\n\
773 -s FILE FILE exists and has a size greater than zero\n\
774 "), stdout);
775 fputs (_("\
776 -S FILE FILE exists and is a socket\n\
777 -t FD file descriptor FD is opened on a terminal\n\
778 -u FILE FILE exists and its set-user-ID bit is set\n\
779 -w FILE FILE exists and write permission is granted\n\
780 -x FILE FILE exists and execute (or search) permission is granted\n\
781 "), stdout);
782 fputs (_("\
784 Except for -h and -L, all FILE-related tests dereference symbolic links.\n\
785 Beware that parentheses need to be escaped (e.g., by backslashes) for shells.\n\
786 INTEGER may also be -l STRING, which evaluates to the length of STRING.\n\
787 "), stdout);
788 fputs (_("\
790 NOTE: [ honors the --help and --version options, but test does not.\n\
791 test treats each of those as it treats any other nonempty STRING.\n\
792 "), stdout);
793 printf (USAGE_BUILTIN_WARNING, _("test and/or ["));
794 emit_ancillary_info (PROGRAM_NAME);
796 exit (status);
798 #endif /* TEST_STANDALONE */
800 #if !defined TEST_STANDALONE
801 # define main test_command
802 #endif
804 #define AUTHORS \
805 proper_name ("Kevin Braunsdorf"), \
806 proper_name ("Matthew Bradburn")
809 * [:
810 * '[' expr ']'
811 * test:
812 * test expr
815 main (int margc, char **margv)
817 bool value;
819 #if !defined TEST_STANDALONE
820 int code;
822 code = setjmp (test_exit_buf);
824 if (code)
825 return (test_error_return);
826 #else /* TEST_STANDALONE */
827 initialize_main (&margc, &margv);
828 set_program_name (margv[0]);
829 setlocale (LC_ALL, "");
830 bindtextdomain (PACKAGE, LOCALEDIR);
831 textdomain (PACKAGE);
833 initialize_exit_failure (TEST_FAILURE);
834 atexit (close_stdout);
835 #endif /* TEST_STANDALONE */
837 argv = margv;
839 if (LBRACKET)
841 /* Recognize --help or --version, but only when invoked in the
842 "[" form, when the last argument is not "]". Use direct
843 parsing, rather than parse_long_options, to avoid accepting
844 abbreviations. POSIX allows "[ --help" and "[ --version" to
845 have the usual GNU behavior, but it requires "test --help"
846 and "test --version" to exit silently with status 0. */
847 if (margc == 2)
849 if (STREQ (margv[1], "--help"))
850 usage (EXIT_SUCCESS);
852 if (STREQ (margv[1], "--version"))
854 version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
855 (char *) NULL);
856 test_main_return (EXIT_SUCCESS);
859 if (margc < 2 || !STREQ (margv[margc - 1], "]"))
860 test_syntax_error (_("missing ']'"), NULL);
862 --margc;
865 argc = margc;
866 pos = 1;
868 if (pos >= argc)
869 test_main_return (TEST_FALSE);
871 value = posixtest (argc - 1);
873 if (pos != argc)
874 test_syntax_error (_("extra argument %s"), quote (argv[pos]));
876 test_main_return (value ? TEST_TRUE : TEST_FALSE);