du: --apparent counts only symlinks and regular
[coreutils.git] / src / test.c
blob103a72ad3a0d56786d94611695f473e2edc770e5
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 "quote.h"
48 #include "stat-time.h"
49 #include "strnumcmp.h"
51 #include <stdarg.h>
52 #include "verror.h"
54 #if HAVE_SYS_PARAM_H
55 # include <sys/param.h>
56 #endif
58 /* Exit status for syntax errors, etc. */
59 enum { TEST_TRUE, TEST_FALSE, TEST_FAILURE };
61 #if defined TEST_STANDALONE
62 # define test_exit(val) exit (val)
63 # define test_main_return(val) return val
64 #else
65 static jmp_buf test_exit_buf;
66 static int test_error_return = 0;
67 # define test_exit(val) test_error_return = val, longjmp (test_exit_buf, 1)
68 # define test_main_return(val) test_exit (val)
69 #endif /* !TEST_STANDALONE */
71 static int pos; /* The offset of the current argument in ARGV. */
72 static int argc; /* The number of arguments present in ARGV. */
73 static char **argv; /* The argument list. */
75 static bool unary_operator (void);
76 static bool binary_operator (bool);
77 static bool two_arguments (void);
78 static bool three_arguments (void);
79 static bool posixtest (int);
81 static bool expr (void);
82 static bool term (void);
83 static bool and (void);
84 static bool or (void);
86 static void beyond (void);
88 ATTRIBUTE_FORMAT ((printf, 1, 2))
89 static _Noreturn void
90 test_syntax_error (char const *format, ...)
92 va_list ap;
93 va_start (ap, format);
94 verror (0, 0, format, ap);
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 if (ok)
172 *mtime = get_stat_mtime (&finfo);
173 return ok;
176 /* Return true if S is one of the test command's binary operators. */
177 static bool
178 binop (char const *s)
180 return ((STREQ (s, "=")) || (STREQ (s, "!=")) || (STREQ (s, "==")) ||
181 (STREQ (s, "-nt")) ||
182 (STREQ (s, "-ot")) || (STREQ (s, "-ef")) || (STREQ (s, "-eq")) ||
183 (STREQ (s, "-ne")) || (STREQ (s, "-lt")) || (STREQ (s, "-le")) ||
184 (STREQ (s, "-gt")) || (STREQ (s, "-ge")));
188 * term - parse a term and return 1 or 0 depending on whether the term
189 * evaluates to true or false, respectively.
191 * term ::=
192 * '-'('h'|'d'|'f'|'r'|'s'|'w'|'c'|'b'|'p'|'u'|'g'|'k') filename
193 * '-'('L'|'x') filename
194 * '-t' int
195 * '-'('z'|'n') string
196 * string
197 * string ('!='|'=') string
198 * <int> '-'(eq|ne|le|lt|ge|gt) <int>
199 * file '-'(nt|ot|ef) file
200 * '(' <expr> ')'
201 * int ::=
202 * '-l' string
203 * positive and negative integers
205 static bool
206 term (void)
208 bool value;
209 bool negated = false;
211 /* Deal with leading 'not's. */
212 while (pos < argc && argv[pos][0] == '!' && argv[pos][1] == '\0')
214 advance (true);
215 negated = !negated;
218 if (pos >= argc)
219 beyond ();
221 /* A paren-bracketed argument. */
222 if (argv[pos][0] == '(' && argv[pos][1] == '\0')
224 int nargs;
226 advance (true);
228 for (nargs = 1;
229 pos + nargs < argc && ! STREQ (argv[pos + nargs], ")");
230 nargs++)
231 if (nargs == 4)
233 nargs = argc - pos;
234 break;
237 value = posixtest (nargs);
238 if (argv[pos] == 0)
239 test_syntax_error (_("%s expected"), quote (")"));
240 else
241 if (argv[pos][0] != ')' || argv[pos][1])
242 test_syntax_error (_("%s expected, found %s"),
243 quote_n (0, ")"), quote_n (1, argv[pos]));
244 advance (false);
247 /* Are there enough arguments left that this could be dyadic? */
248 else if (4 <= argc - pos && STREQ (argv[pos], "-l") && binop (argv[pos + 2]))
249 value = binary_operator (true);
250 else if (3 <= argc - pos && binop (argv[pos + 1]))
251 value = binary_operator (false);
253 /* It might be a switch type argument. */
254 else if (argv[pos][0] == '-' && argv[pos][1] && argv[pos][2] == '\0')
255 value = unary_operator ();
256 else
258 value = (argv[pos][0] != '\0');
259 advance (false);
262 return negated ^ value;
265 static bool
266 binary_operator (bool l_is_l)
268 int op;
269 struct stat stat_buf, stat_spare;
270 /* Is the right integer expression of the form '-l string'? */
271 bool r_is_l;
273 if (l_is_l)
274 advance (false);
275 op = pos + 1;
277 if ((op < argc - 2) && STREQ (argv[op + 1], "-l"))
279 r_is_l = true;
280 advance (false);
282 else
283 r_is_l = false;
285 if (argv[op][0] == '-')
287 /* check for eq, nt, and stuff */
288 if ((((argv[op][1] == 'l' || argv[op][1] == 'g')
289 && (argv[op][2] == 'e' || argv[op][2] == 't'))
290 || (argv[op][1] == 'e' && argv[op][2] == 'q')
291 || (argv[op][1] == 'n' && argv[op][2] == 'e'))
292 && !argv[op][3])
294 char lbuf[INT_BUFSIZE_BOUND (uintmax_t)];
295 char rbuf[INT_BUFSIZE_BOUND (uintmax_t)];
296 char const *l = (l_is_l
297 ? umaxtostr (strlen (argv[op - 1]), lbuf)
298 : find_int (argv[op - 1]));
299 char const *r = (r_is_l
300 ? umaxtostr (strlen (argv[op + 2]), rbuf)
301 : find_int (argv[op + 1]));
302 int cmp = strintcmp (l, r);
303 bool xe_operator = (argv[op][2] == 'e');
304 pos += 3;
305 return (argv[op][1] == 'l' ? cmp < xe_operator
306 : argv[op][1] == 'g' ? cmp > - xe_operator
307 : (cmp != 0) == xe_operator);
310 switch (argv[op][1])
312 default:
313 break;
315 case 'n':
316 if (argv[op][2] == 't' && !argv[op][3])
318 /* nt - newer than */
319 struct timespec lt, rt;
320 bool le, re;
321 pos += 3;
322 if (l_is_l || r_is_l)
323 test_syntax_error (_("-nt does not accept -l"));
324 le = get_mtime (argv[op - 1], &lt);
325 re = get_mtime (argv[op + 1], &rt);
326 return le && (!re || timespec_cmp (lt, rt) > 0);
328 break;
330 case 'e':
331 if (argv[op][2] == 'f' && !argv[op][3])
333 /* ef - hard link? */
334 pos += 3;
335 if (l_is_l || r_is_l)
336 test_syntax_error (_("-ef does not accept -l"));
337 return (stat (argv[op - 1], &stat_buf) == 0
338 && stat (argv[op + 1], &stat_spare) == 0
339 && stat_buf.st_dev == stat_spare.st_dev
340 && stat_buf.st_ino == stat_spare.st_ino);
342 break;
344 case 'o':
345 if ('t' == argv[op][2] && '\000' == argv[op][3])
347 /* ot - older than */
348 struct timespec lt, rt;
349 bool le, re;
350 pos += 3;
351 if (l_is_l || r_is_l)
352 test_syntax_error (_("-ot does not accept -l"));
353 le = get_mtime (argv[op - 1], &lt);
354 re = get_mtime (argv[op + 1], &rt);
355 return re && (!le || timespec_cmp (lt, rt) < 0);
357 break;
360 /* FIXME: is this dead code? */
361 test_syntax_error (_("%s: unknown binary operator"), quote (argv[op]));
364 if (argv[op][0] == '='
365 && (!argv[op][1] || ((argv[op][1] == '=') && !argv[op][2])))
367 bool value = STREQ (argv[pos], argv[pos + 2]);
368 pos += 3;
369 return value;
372 if (STREQ (argv[op], "!="))
374 bool value = !STREQ (argv[pos], argv[pos + 2]);
375 pos += 3;
376 return value;
379 /* Not reached. */
380 abort ();
383 static bool
384 unary_operator (void)
386 struct stat stat_buf;
388 switch (argv[pos][1])
390 default:
391 test_syntax_error (_("%s: unary operator expected"), quote (argv[pos]));
392 return false;
394 /* All of the following unary operators use unary_advance (), which
395 checks to make sure that there is an argument, and then advances
396 pos right past it. This means that pos - 1 is the location of the
397 argument. */
399 case 'e': /* file exists in the file system? */
400 unary_advance ();
401 return stat (argv[pos - 1], &stat_buf) == 0;
403 case 'r': /* file is readable? */
404 unary_advance ();
405 return euidaccess (argv[pos - 1], R_OK) == 0;
407 case 'w': /* File is writable? */
408 unary_advance ();
409 return euidaccess (argv[pos - 1], W_OK) == 0;
411 case 'x': /* File is executable? */
412 unary_advance ();
413 return euidaccess (argv[pos - 1], X_OK) == 0;
415 case 'N': /* File exists and has been modified since it was last read? */
417 unary_advance ();
418 if (stat (argv[pos - 1], &stat_buf) != 0)
419 return false;
420 struct timespec atime = get_stat_atime (&stat_buf);
421 struct timespec mtime = get_stat_mtime (&stat_buf);
422 return (timespec_cmp (mtime, atime) > 0);
425 case 'O': /* File is owned by you? */
427 unary_advance ();
428 if (stat (argv[pos - 1], &stat_buf) != 0)
429 return false;
430 errno = 0;
431 uid_t euid = geteuid ();
432 uid_t NO_UID = -1;
433 return ! (euid == NO_UID && errno) && euid == stat_buf.st_uid;
436 case 'G': /* File is owned by your group? */
438 unary_advance ();
439 if (stat (argv[pos - 1], &stat_buf) != 0)
440 return false;
441 errno = 0;
442 gid_t egid = getegid ();
443 gid_t NO_GID = -1;
444 return ! (egid == NO_GID && errno) && egid == stat_buf.st_gid;
447 case 'f': /* File is a file? */
448 unary_advance ();
449 /* Under POSIX, -f is true if the given file exists
450 and is a regular file. */
451 return (stat (argv[pos - 1], &stat_buf) == 0
452 && S_ISREG (stat_buf.st_mode));
454 case 'd': /* File is a directory? */
455 unary_advance ();
456 return (stat (argv[pos - 1], &stat_buf) == 0
457 && S_ISDIR (stat_buf.st_mode));
459 case 's': /* File has something in it? */
460 unary_advance ();
461 return (stat (argv[pos - 1], &stat_buf) == 0
462 && 0 < stat_buf.st_size);
464 case 'S': /* File is a socket? */
465 unary_advance ();
466 return (stat (argv[pos - 1], &stat_buf) == 0
467 && S_ISSOCK (stat_buf.st_mode));
469 case 'c': /* File is character special? */
470 unary_advance ();
471 return (stat (argv[pos - 1], &stat_buf) == 0
472 && S_ISCHR (stat_buf.st_mode));
474 case 'b': /* File is block special? */
475 unary_advance ();
476 return (stat (argv[pos - 1], &stat_buf) == 0
477 && S_ISBLK (stat_buf.st_mode));
479 case 'p': /* File is a named pipe? */
480 unary_advance ();
481 return (stat (argv[pos - 1], &stat_buf) == 0
482 && S_ISFIFO (stat_buf.st_mode));
484 case 'L': /* Same as -h */
485 /*FALLTHROUGH*/
487 case 'h': /* File is a symbolic link? */
488 unary_advance ();
489 return (lstat (argv[pos - 1], &stat_buf) == 0
490 && S_ISLNK (stat_buf.st_mode));
492 case 'u': /* File is setuid? */
493 unary_advance ();
494 return (stat (argv[pos - 1], &stat_buf) == 0
495 && (stat_buf.st_mode & S_ISUID));
497 case 'g': /* File is setgid? */
498 unary_advance ();
499 return (stat (argv[pos - 1], &stat_buf) == 0
500 && (stat_buf.st_mode & S_ISGID));
502 case 'k': /* File has sticky bit set? */
503 unary_advance ();
504 return (stat (argv[pos - 1], &stat_buf) == 0
505 && (stat_buf.st_mode & S_ISVTX));
507 case 't': /* File (fd) is a terminal? */
509 long int fd;
510 char const *arg;
511 unary_advance ();
512 arg = find_int (argv[pos - 1]);
513 errno = 0;
514 fd = strtol (arg, NULL, 10);
515 return (errno != ERANGE && 0 <= fd && fd <= INT_MAX && isatty (fd));
518 case 'n': /* True if arg has some length. */
519 unary_advance ();
520 return argv[pos - 1][0] != 0;
522 case 'z': /* True if arg has no length. */
523 unary_advance ();
524 return argv[pos - 1][0] == '\0';
529 * and:
530 * term
531 * term '-a' and
533 static bool
534 and (void)
536 bool value = true;
538 while (true)
540 value &= term ();
541 if (! (pos < argc && STREQ (argv[pos], "-a")))
542 return value;
543 advance (false);
548 * or:
549 * and
550 * and '-o' or
552 static bool
553 or (void)
555 bool value = false;
557 while (true)
559 value |= and ();
560 if (! (pos < argc && STREQ (argv[pos], "-o")))
561 return value;
562 advance (false);
567 * expr:
568 * or
570 static bool
571 expr (void)
573 if (pos >= argc)
574 beyond ();
576 return or (); /* Same with this. */
579 static bool
580 one_argument (void)
582 return argv[pos++][0] != '\0';
585 static bool
586 two_arguments (void)
588 bool value;
590 if (STREQ (argv[pos], "!"))
592 advance (false);
593 value = ! one_argument ();
595 else if (argv[pos][0] == '-'
596 && argv[pos][1] != '\0'
597 && argv[pos][2] == '\0')
599 value = unary_operator ();
601 else
602 beyond ();
603 return (value);
606 static bool
607 three_arguments (void)
609 bool value;
611 if (binop (argv[pos + 1]))
612 value = binary_operator (false);
613 else if (STREQ (argv[pos], "!"))
615 advance (true);
616 value = !two_arguments ();
618 else if (STREQ (argv[pos], "(") && STREQ (argv[pos + 2], ")"))
620 advance (false);
621 value = one_argument ();
622 advance (false);
624 else if (STREQ (argv[pos + 1], "-a") || STREQ (argv[pos + 1], "-o"))
625 value = expr ();
626 else
627 test_syntax_error (_("%s: binary operator expected"),
628 quote (argv[pos + 1]));
629 return (value);
632 /* This is an implementation of a Posix.2 proposal by David Korn. */
633 static bool
634 posixtest (int nargs)
636 bool value;
638 switch (nargs)
640 case 1:
641 value = one_argument ();
642 break;
644 case 2:
645 value = two_arguments ();
646 break;
648 case 3:
649 value = three_arguments ();
650 break;
652 case 4:
653 if (STREQ (argv[pos], "!"))
655 advance (true);
656 value = !three_arguments ();
657 break;
659 if (STREQ (argv[pos], "(") && STREQ (argv[pos + 3], ")"))
661 advance (false);
662 value = two_arguments ();
663 advance (false);
664 break;
666 FALLTHROUGH;
667 case 5:
668 default:
669 if (nargs <= 0)
670 abort ();
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 *) NULL);
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);