numfmt: prefer signed types
[coreutils.git] / src / test.c
blob445eba08b92e1e0a03042d1beb3f437c85600eaa
1 /* GNU test program (ksb and mjb) */
3 /* Modified to run with the GNU shell by bfox. */
5 /* Copyright (C) 1987-2023 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 <https://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 "assure.h"
48 #include "quote.h"
49 #include "stat-time.h"
50 #include "strnumcmp.h"
52 #include <stdarg.h>
53 #include "verror.h"
55 #if HAVE_SYS_PARAM_H
56 # include <sys/param.h>
57 #endif
59 /* Exit status for syntax errors, etc. */
60 enum { TEST_TRUE, TEST_FALSE, TEST_FAILURE };
62 #if defined TEST_STANDALONE
63 # define test_exit(val) exit (val)
64 # define test_main_return(val) return val
65 #else
66 static jmp_buf test_exit_buf;
67 static int test_error_return = 0;
68 # define test_exit(val) test_error_return = val, longjmp (test_exit_buf, 1)
69 # define test_main_return(val) test_exit (val)
70 #endif /* !TEST_STANDALONE */
72 static int pos; /* The offset of the current argument in ARGV. */
73 static int argc; /* The number of arguments present in ARGV. */
74 static char **argv; /* The argument list. */
76 static bool unary_operator (void);
77 static bool binary_operator (bool);
78 static bool two_arguments (void);
79 static bool three_arguments (void);
80 static bool posixtest (int);
82 static bool expr (void);
83 static bool term (void);
84 static bool and (void);
85 static bool or (void);
87 static void beyond (void);
89 ATTRIBUTE_FORMAT ((printf, 1, 2))
90 static _Noreturn void
91 test_syntax_error (char const *format, ...)
93 va_list ap;
94 va_start (ap, format);
95 verror (0, 0, format, ap);
96 test_exit (TEST_FAILURE);
99 /* Increment our position in the argument list. Check that we're not
100 past the end of the argument list. This check is suppressed if the
101 argument is false. */
103 static void
104 advance (bool f)
106 ++pos;
108 if (f && pos >= argc)
109 beyond ();
112 static void
113 unary_advance (void)
115 advance (true);
116 ++pos;
120 * beyond - call when we're beyond the end of the argument list (an
121 * error condition)
123 static _Noreturn void
124 beyond (void)
126 test_syntax_error (_("missing argument after %s"), quote (argv[argc - 1]));
129 /* If the characters pointed to by STRING constitute a valid number,
130 return a pointer to the start of the number, skipping any blanks or
131 leading '+'. Otherwise, report an error and exit. */
132 static char const *
133 find_int (char const *string)
135 char const *p;
136 char const *number_start;
138 for (p = string; isblank (to_uchar (*p)); p++)
139 continue;
141 if (*p == '+')
143 p++;
144 number_start = p;
146 else
148 number_start = p;
149 p += (*p == '-');
152 if (ISDIGIT (*p++))
154 while (ISDIGIT (*p))
155 p++;
156 while (isblank (to_uchar (*p)))
157 p++;
158 if (!*p)
159 return number_start;
162 test_syntax_error (_("invalid integer %s"), quote (string));
165 /* Find the modification time of FILE, and stuff it into *MTIME.
166 Return true if successful. */
167 static bool
168 get_mtime (char const *filename, struct timespec *mtime)
170 struct stat finfo;
171 bool ok = (stat (filename, &finfo) == 0);
172 if (ok)
173 *mtime = get_stat_mtime (&finfo);
174 return ok;
177 /* Return true if S is one of the test command's binary operators. */
178 static bool
179 binop (char const *s)
181 return ((STREQ (s, "=")) || (STREQ (s, "!=")) || (STREQ (s, "==")) ||
182 (STREQ (s, "-nt")) ||
183 (STREQ (s, "-ot")) || (STREQ (s, "-ef")) || (STREQ (s, "-eq")) ||
184 (STREQ (s, "-ne")) || (STREQ (s, "-lt")) || (STREQ (s, "-le")) ||
185 (STREQ (s, "-gt")) || (STREQ (s, "-ge")));
189 * term - parse a term and return 1 or 0 depending on whether the term
190 * evaluates to true or false, respectively.
192 * term ::=
193 * '-'('h'|'d'|'f'|'r'|'s'|'w'|'c'|'b'|'p'|'u'|'g'|'k') filename
194 * '-'('L'|'x') filename
195 * '-t' int
196 * '-'('z'|'n') string
197 * string
198 * string ('!='|'=') string
199 * <int> '-'(eq|ne|le|lt|ge|gt) <int>
200 * file '-'(nt|ot|ef) file
201 * '(' <expr> ')'
202 * int ::=
203 * '-l' string
204 * positive and negative integers
206 static bool
207 term (void)
209 bool value;
210 bool negated = false;
212 /* Deal with leading 'not's. */
213 while (pos < argc && argv[pos][0] == '!' && argv[pos][1] == '\0')
215 advance (true);
216 negated = !negated;
219 if (pos >= argc)
220 beyond ();
222 /* A paren-bracketed argument. */
223 if (argv[pos][0] == '(' && argv[pos][1] == '\0')
225 int nargs;
227 advance (true);
229 for (nargs = 1;
230 pos + nargs < argc && ! STREQ (argv[pos + nargs], ")");
231 nargs++)
232 if (nargs == 4)
234 nargs = argc - pos;
235 break;
238 value = posixtest (nargs);
239 if (argv[pos] == 0)
240 test_syntax_error (_("%s expected"), quote (")"));
241 else
242 if (argv[pos][0] != ')' || argv[pos][1])
243 test_syntax_error (_("%s expected, found %s"),
244 quote_n (0, ")"), quote_n (1, argv[pos]));
245 advance (false);
248 /* Are there enough arguments left that this could be dyadic? */
249 else if (4 <= argc - pos && STREQ (argv[pos], "-l") && binop (argv[pos + 2]))
250 value = binary_operator (true);
251 else if (3 <= argc - pos && binop (argv[pos + 1]))
252 value = binary_operator (false);
254 /* It might be a switch type argument. */
255 else if (argv[pos][0] == '-' && argv[pos][1] && argv[pos][2] == '\0')
256 value = unary_operator ();
257 else
259 value = (argv[pos][0] != '\0');
260 advance (false);
263 return negated ^ value;
266 static bool
267 binary_operator (bool l_is_l)
269 int op;
270 struct stat stat_buf, stat_spare;
271 /* Is the right integer expression of the form '-l string'? */
272 bool r_is_l;
274 if (l_is_l)
275 advance (false);
276 op = pos + 1;
278 if ((op < argc - 2) && STREQ (argv[op + 1], "-l"))
280 r_is_l = true;
281 advance (false);
283 else
284 r_is_l = false;
286 if (argv[op][0] == '-')
288 /* check for eq, nt, and stuff */
289 if ((((argv[op][1] == 'l' || argv[op][1] == 'g')
290 && (argv[op][2] == 'e' || argv[op][2] == 't'))
291 || (argv[op][1] == 'e' && argv[op][2] == 'q')
292 || (argv[op][1] == 'n' && argv[op][2] == 'e'))
293 && !argv[op][3])
295 char lbuf[INT_BUFSIZE_BOUND (uintmax_t)];
296 char rbuf[INT_BUFSIZE_BOUND (uintmax_t)];
297 char const *l = (l_is_l
298 ? umaxtostr (strlen (argv[op - 1]), lbuf)
299 : find_int (argv[op - 1]));
300 char const *r = (r_is_l
301 ? umaxtostr (strlen (argv[op + 2]), rbuf)
302 : find_int (argv[op + 1]));
303 int cmp = strintcmp (l, r);
304 bool xe_operator = (argv[op][2] == 'e');
305 pos += 3;
306 return (argv[op][1] == 'l' ? cmp < xe_operator
307 : argv[op][1] == 'g' ? cmp > - xe_operator
308 : (cmp != 0) == xe_operator);
311 switch (argv[op][1])
313 default:
314 break;
316 case 'n':
317 if (argv[op][2] == 't' && !argv[op][3])
319 /* nt - newer than */
320 struct timespec lt, rt;
321 bool le, re;
322 pos += 3;
323 if (l_is_l || r_is_l)
324 test_syntax_error (_("-nt does not accept -l"));
325 le = get_mtime (argv[op - 1], &lt);
326 re = get_mtime (argv[op + 1], &rt);
327 return le && (!re || timespec_cmp (lt, rt) > 0);
329 break;
331 case 'e':
332 if (argv[op][2] == 'f' && !argv[op][3])
334 /* ef - hard link? */
335 pos += 3;
336 if (l_is_l || r_is_l)
337 test_syntax_error (_("-ef does not accept -l"));
338 return (stat (argv[op - 1], &stat_buf) == 0
339 && stat (argv[op + 1], &stat_spare) == 0
340 && stat_buf.st_dev == stat_spare.st_dev
341 && stat_buf.st_ino == stat_spare.st_ino);
343 break;
345 case 'o':
346 if ('t' == argv[op][2] && '\000' == argv[op][3])
348 /* ot - older than */
349 struct timespec lt, rt;
350 bool le, re;
351 pos += 3;
352 if (l_is_l || r_is_l)
353 test_syntax_error (_("-ot does not accept -l"));
354 le = get_mtime (argv[op - 1], &lt);
355 re = get_mtime (argv[op + 1], &rt);
356 return re && (!le || timespec_cmp (lt, rt) < 0);
358 break;
361 /* FIXME: is this dead code? */
362 test_syntax_error (_("%s: unknown binary operator"), quote (argv[op]));
365 if (argv[op][0] == '='
366 && (!argv[op][1] || ((argv[op][1] == '=') && !argv[op][2])))
368 bool value = STREQ (argv[pos], argv[pos + 2]);
369 pos += 3;
370 return value;
373 if (STREQ (argv[op], "!="))
375 bool value = !STREQ (argv[pos], argv[pos + 2]);
376 pos += 3;
377 return value;
380 /* Not reached. */
381 affirm (false);
384 static bool
385 unary_operator (void)
387 struct stat stat_buf;
389 switch (argv[pos][1])
391 default:
392 test_syntax_error (_("%s: unary operator expected"), quote (argv[pos]));
393 return false;
395 /* All of the following unary operators use unary_advance (), which
396 checks to make sure that there is an argument, and then advances
397 pos right past it. This means that pos - 1 is the location of the
398 argument. */
400 case 'e': /* file exists in the file system? */
401 unary_advance ();
402 return stat (argv[pos - 1], &stat_buf) == 0;
404 case 'r': /* file is readable? */
405 unary_advance ();
406 return euidaccess (argv[pos - 1], R_OK) == 0;
408 case 'w': /* File is writable? */
409 unary_advance ();
410 return euidaccess (argv[pos - 1], W_OK) == 0;
412 case 'x': /* File is executable? */
413 unary_advance ();
414 return euidaccess (argv[pos - 1], X_OK) == 0;
416 case 'N': /* File exists and has been modified since it was last read? */
418 unary_advance ();
419 if (stat (argv[pos - 1], &stat_buf) != 0)
420 return false;
421 struct timespec atime = get_stat_atime (&stat_buf);
422 struct timespec mtime = get_stat_mtime (&stat_buf);
423 return (timespec_cmp (mtime, atime) > 0);
426 case 'O': /* File is owned by you? */
428 unary_advance ();
429 if (stat (argv[pos - 1], &stat_buf) != 0)
430 return false;
431 errno = 0;
432 uid_t euid = geteuid ();
433 uid_t NO_UID = -1;
434 return ! (euid == NO_UID && errno) && euid == stat_buf.st_uid;
437 case 'G': /* File is owned by your group? */
439 unary_advance ();
440 if (stat (argv[pos - 1], &stat_buf) != 0)
441 return false;
442 errno = 0;
443 gid_t egid = getegid ();
444 gid_t NO_GID = -1;
445 return ! (egid == NO_GID && errno) && egid == stat_buf.st_gid;
448 case 'f': /* File is a file? */
449 unary_advance ();
450 /* Under POSIX, -f is true if the given file exists
451 and is a regular file. */
452 return (stat (argv[pos - 1], &stat_buf) == 0
453 && S_ISREG (stat_buf.st_mode));
455 case 'd': /* File is a directory? */
456 unary_advance ();
457 return (stat (argv[pos - 1], &stat_buf) == 0
458 && S_ISDIR (stat_buf.st_mode));
460 case 's': /* File has something in it? */
461 unary_advance ();
462 return (stat (argv[pos - 1], &stat_buf) == 0
463 && 0 < stat_buf.st_size);
465 case 'S': /* File is a socket? */
466 unary_advance ();
467 return (stat (argv[pos - 1], &stat_buf) == 0
468 && S_ISSOCK (stat_buf.st_mode));
470 case 'c': /* File is character special? */
471 unary_advance ();
472 return (stat (argv[pos - 1], &stat_buf) == 0
473 && S_ISCHR (stat_buf.st_mode));
475 case 'b': /* File is block special? */
476 unary_advance ();
477 return (stat (argv[pos - 1], &stat_buf) == 0
478 && S_ISBLK (stat_buf.st_mode));
480 case 'p': /* File is a named pipe? */
481 unary_advance ();
482 return (stat (argv[pos - 1], &stat_buf) == 0
483 && S_ISFIFO (stat_buf.st_mode));
485 case 'L': /* Same as -h */
486 /*FALLTHROUGH*/
488 case 'h': /* File is a symbolic link? */
489 unary_advance ();
490 return (lstat (argv[pos - 1], &stat_buf) == 0
491 && S_ISLNK (stat_buf.st_mode));
493 case 'u': /* File is setuid? */
494 unary_advance ();
495 return (stat (argv[pos - 1], &stat_buf) == 0
496 && (stat_buf.st_mode & S_ISUID));
498 case 'g': /* File is setgid? */
499 unary_advance ();
500 return (stat (argv[pos - 1], &stat_buf) == 0
501 && (stat_buf.st_mode & S_ISGID));
503 case 'k': /* File has sticky bit set? */
504 unary_advance ();
505 return (stat (argv[pos - 1], &stat_buf) == 0
506 && (stat_buf.st_mode & S_ISVTX));
508 case 't': /* File (fd) is a terminal? */
510 long int fd;
511 char const *arg;
512 unary_advance ();
513 arg = find_int (argv[pos - 1]);
514 errno = 0;
515 fd = strtol (arg, nullptr, 10);
516 return (errno != ERANGE && 0 <= fd && fd <= INT_MAX && isatty (fd));
519 case 'n': /* True if arg has some length. */
520 unary_advance ();
521 return argv[pos - 1][0] != 0;
523 case 'z': /* True if arg has no length. */
524 unary_advance ();
525 return argv[pos - 1][0] == '\0';
530 * and:
531 * term
532 * term '-a' and
534 static bool
535 and (void)
537 bool value = true;
539 while (true)
541 value &= term ();
542 if (! (pos < argc && STREQ (argv[pos], "-a")))
543 return value;
544 advance (false);
549 * or:
550 * and
551 * and '-o' or
553 static bool
554 or (void)
556 bool value = false;
558 while (true)
560 value |= and ();
561 if (! (pos < argc && STREQ (argv[pos], "-o")))
562 return value;
563 advance (false);
568 * expr:
569 * or
571 static bool
572 expr (void)
574 if (pos >= argc)
575 beyond ();
577 return or (); /* Same with this. */
580 static bool
581 one_argument (void)
583 return argv[pos++][0] != '\0';
586 static bool
587 two_arguments (void)
589 bool value;
591 if (STREQ (argv[pos], "!"))
593 advance (false);
594 value = ! one_argument ();
596 else if (argv[pos][0] == '-'
597 && argv[pos][1] != '\0'
598 && argv[pos][2] == '\0')
600 value = unary_operator ();
602 else
603 beyond ();
604 return (value);
607 static bool
608 three_arguments (void)
610 bool value;
612 if (binop (argv[pos + 1]))
613 value = binary_operator (false);
614 else if (STREQ (argv[pos], "!"))
616 advance (true);
617 value = !two_arguments ();
619 else if (STREQ (argv[pos], "(") && STREQ (argv[pos + 2], ")"))
621 advance (false);
622 value = one_argument ();
623 advance (false);
625 else if (STREQ (argv[pos + 1], "-a") || STREQ (argv[pos + 1], "-o"))
626 value = expr ();
627 else
628 test_syntax_error (_("%s: binary operator expected"),
629 quote (argv[pos + 1]));
630 return (value);
633 /* This is an implementation of a Posix.2 proposal by David Korn. */
634 static bool
635 posixtest (int nargs)
637 bool value;
639 switch (nargs)
641 case 1:
642 value = one_argument ();
643 break;
645 case 2:
646 value = two_arguments ();
647 break;
649 case 3:
650 value = three_arguments ();
651 break;
653 case 4:
654 if (STREQ (argv[pos], "!"))
656 advance (true);
657 value = !three_arguments ();
658 break;
660 if (STREQ (argv[pos], "(") && STREQ (argv[pos + 3], ")"))
662 advance (false);
663 value = two_arguments ();
664 advance (false);
665 break;
667 FALLTHROUGH;
668 case 5:
669 default:
670 affirm (0 < nargs);
671 value = expr ();
674 return (value);
677 #if defined TEST_STANDALONE
679 void
680 usage (int status)
682 if (status != EXIT_SUCCESS)
683 emit_try_help ();
684 else
686 fputs (_("\
687 Usage: test EXPRESSION\n\
688 or: test\n\
689 or: [ EXPRESSION ]\n\
690 or: [ ]\n\
691 or: [ OPTION\n\
692 "), stdout);
693 fputs (_("\
694 Exit with the status determined by EXPRESSION.\n\
696 "), stdout);
697 fputs (HELP_OPTION_DESCRIPTION, stdout);
698 fputs (VERSION_OPTION_DESCRIPTION, stdout);
699 fputs (_("\
701 An omitted EXPRESSION defaults to false. Otherwise,\n\
702 EXPRESSION is true or false and sets exit status. It is one of:\n\
703 "), stdout);
704 fputs (_("\
706 ( EXPRESSION ) EXPRESSION is true\n\
707 ! EXPRESSION EXPRESSION is false\n\
708 EXPRESSION1 -a EXPRESSION2 both EXPRESSION1 and EXPRESSION2 are true\n\
709 EXPRESSION1 -o EXPRESSION2 either EXPRESSION1 or EXPRESSION2 is true\n\
710 "), stdout);
711 fputs (_("\
713 -n STRING the length of STRING is nonzero\n\
714 STRING equivalent to -n STRING\n\
715 -z STRING the length of STRING is zero\n\
716 STRING1 = STRING2 the strings are equal\n\
717 STRING1 != STRING2 the strings are not equal\n\
718 "), stdout);
719 fputs (_("\
721 INTEGER1 -eq INTEGER2 INTEGER1 is equal to INTEGER2\n\
722 INTEGER1 -ge INTEGER2 INTEGER1 is greater than or equal to INTEGER2\n\
723 INTEGER1 -gt INTEGER2 INTEGER1 is greater than INTEGER2\n\
724 INTEGER1 -le INTEGER2 INTEGER1 is less than or equal to INTEGER2\n\
725 INTEGER1 -lt INTEGER2 INTEGER1 is less than INTEGER2\n\
726 INTEGER1 -ne INTEGER2 INTEGER1 is not equal to INTEGER2\n\
727 "), stdout);
728 fputs (_("\
730 FILE1 -ef FILE2 FILE1 and FILE2 have the same device and inode numbers\n\
731 FILE1 -nt FILE2 FILE1 is newer (modification date) than FILE2\n\
732 FILE1 -ot FILE2 FILE1 is older than FILE2\n\
733 "), stdout);
734 fputs (_("\
736 -b FILE FILE exists and is block special\n\
737 -c FILE FILE exists and is character special\n\
738 -d FILE FILE exists and is a directory\n\
739 -e FILE FILE exists\n\
740 "), stdout);
741 fputs (_("\
742 -f FILE FILE exists and is a regular file\n\
743 -g FILE FILE exists and is set-group-ID\n\
744 -G FILE FILE exists and is owned by the effective group ID\n\
745 -h FILE FILE exists and is a symbolic link (same as -L)\n\
746 -k FILE FILE exists and has its sticky bit set\n\
747 "), stdout);
748 fputs (_("\
749 -L FILE FILE exists and is a symbolic link (same as -h)\n\
750 -N FILE FILE exists and has been modified since it was last read\n\
751 -O FILE FILE exists and is owned by the effective user ID\n\
752 -p FILE FILE exists and is a named pipe\n\
753 -r FILE FILE exists and the user has read access\n\
754 -s FILE FILE exists and has a size greater than zero\n\
755 "), stdout);
756 fputs (_("\
757 -S FILE FILE exists and is a socket\n\
758 -t FD file descriptor FD is opened on a terminal\n\
759 -u FILE FILE exists and its set-user-ID bit is set\n\
760 -w FILE FILE exists and the user has write access\n\
761 -x FILE FILE exists and the user has execute (or search) access\n\
762 "), stdout);
763 fputs (_("\
765 Except for -h and -L, all FILE-related tests dereference symbolic links.\n\
766 Beware that parentheses need to be escaped (e.g., by backslashes) for shells.\n\
767 INTEGER may also be -l STRING, which evaluates to the length of STRING.\n\
768 "), stdout);
769 fputs (_("\
771 NOTE: Binary -a and -o are inherently ambiguous. Use 'test EXPR1 && test\n\
772 EXPR2' or 'test EXPR1 || test EXPR2' instead.\n\
773 "), stdout);
774 fputs (_("\
776 NOTE: [ honors the --help and --version options, but test does not.\n\
777 test treats each of those as it treats any other nonempty STRING.\n\
778 "), stdout);
779 printf (USAGE_BUILTIN_WARNING, _("test and/or ["));
780 emit_ancillary_info (PROGRAM_NAME);
782 exit (status);
784 #endif /* TEST_STANDALONE */
786 #if !defined TEST_STANDALONE
787 # define main test_command
788 #endif
790 #define AUTHORS \
791 proper_name ("Kevin Braunsdorf"), \
792 proper_name ("Matthew Bradburn")
795 * [:
796 * '[' expr ']'
797 * test:
798 * test expr
801 main (int margc, char **margv)
803 bool value;
805 #if !defined TEST_STANDALONE
806 int code;
808 code = setjmp (test_exit_buf);
810 if (code)
811 return (test_error_return);
812 #else /* TEST_STANDALONE */
813 initialize_main (&margc, &margv);
814 set_program_name (margv[0]);
815 setlocale (LC_ALL, "");
816 bindtextdomain (PACKAGE, LOCALEDIR);
817 textdomain (PACKAGE);
819 initialize_exit_failure (TEST_FAILURE);
820 atexit (close_stdout);
821 #endif /* TEST_STANDALONE */
823 argv = margv;
825 if (LBRACKET)
827 /* Recognize --help or --version, but only when invoked in the
828 "[" form, when the last argument is not "]". Use direct
829 parsing, rather than parse_long_options, to avoid accepting
830 abbreviations. POSIX allows "[ --help" and "[ --version" to
831 have the usual GNU behavior, but it requires "test --help"
832 and "test --version" to exit silently with status 0. */
833 if (margc == 2)
835 if (STREQ (margv[1], "--help"))
836 usage (EXIT_SUCCESS);
838 if (STREQ (margv[1], "--version"))
840 version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
841 (char *) nullptr);
842 test_main_return (EXIT_SUCCESS);
845 if (margc < 2 || !STREQ (margv[margc - 1], "]"))
846 test_syntax_error (_("missing %s"), quote ("]"));
848 --margc;
851 argc = margc;
852 pos = 1;
854 if (pos >= argc)
855 test_main_return (TEST_FALSE);
857 value = posixtest (argc - 1);
859 if (pos != argc)
860 test_syntax_error (_("extra argument %s"), quote (argv[pos]));
862 test_main_return (value ? TEST_TRUE : TEST_FALSE);