Commit Graph

80 Commits

Author SHA1 Message Date
kre
df8e475ae0 Allow SMALL (and TINY) builds of test (for SMALL/TINY builds of sh)
which support only the defined modes of operation of test, to allow
the version of sh on small install media be kept as small as possible.
2018-09-13 22:00:58 +00:00
kre
ec9262987a PR standards/34646
Make test(1) always use the POSIX "number of args" evaluation rules
when they apply.

Only fall back to the old expression evaluation when there are more
than 4 args, or when the args given cannot work as a test expression
using the POSIX rules.  That is when the result is unspecified.

Also fix old bug where a string of whitespace is considered to be a
valid number (at least one digit is needed amongst it somewhere...)

XXX pullup -8
2018-09-12 23:33:31 +00:00
wiz
14b00a757c Remove unnecessary Tn. 2017-10-18 18:11:54 +00:00
kre
9bbf3fccba I have seen (way too often) uses of test(1) that are not defined to
actually work (but just happen to, today, and in some cases, even
that trusts to some luck.)

It has been recently pointed out to me that the man page (ie: this
file) doesn't give any real guidance to what is really acceptable,
and what is not.

The CAVEATS section does note that the grammar is ambiguous, but then
just says that test(1) implements what POSIX requires, and refers
readers to the relevant section of the POSIX standard for more details.
That is probably asking too much of the average reader...

So, add some extra information in the CAVEATS with what is defined to work,
and what should be avoided.   Not all of the POSIX rules are here, but this
might hopefully help script authors avoid some of the pitfalls.
2017-10-18 08:54:59 +00:00
wiz
01869ca4d2 Remove workaround for ancient HTML generation code. 2017-07-03 21:28:48 +00:00
sevan
51fe790c4c Drop main() prototype. 2016-09-05 01:00:07 +00:00
sevan
7346e185f5 Document the version test first appeared.
Bump date.
2016-08-12 03:17:41 +00:00
dholland
4142c9b7ca usage nit 2016-05-27 05:50:07 +00:00
uebayasi
02829a8ca7 test(1): Compare timestamp in nsec scale in -nt/-ot. 2013-05-04 06:26:44 +00:00
wiz
dbb168824f - Remove unneeded consecutive argument in `.Nm' macros;
- rename `GRAMMAR AMBIGUITY' section to `CAVEATS', and move it to
  correct location;
- bump date.

From Bug Hunting.
2012-12-16 17:57:49 +00:00
joerg
66dd2755f5 Add __printflike attribution to use vprintf and friends with an argument
as format string.
2012-03-15 02:02:20 +00:00
joerg
5bb1ddccc2 Use __dead 2011-08-29 14:51:17 +00:00
wiz
193ee60c7d Correct usage for parentheses, and mark up "expression" in more places.
From Bug Hunting in PR 42286.
2009-11-10 18:19:46 +00:00
wiz
fc61954d0b Remove leading zero in Dd argument. 2009-05-06 08:26:43 +00:00
jschauma
3ebf4f45cb Note that all file tests with the exception of -h and -L follow symbolic
links and thus evaluate the test for the file pointed at.
2009-05-05 19:04:01 +00:00
joerg
0feb17a4b1 Fix markup. 2009-04-12 13:52:20 +00:00
christos
2e63684c48 bin/39446: Aleksey Cheusov: always produce errors on empty numbers. 2008-09-10 19:00:51 +00:00
christos
afd857d440 make getn return long long to support large numbers on all archs. 2008-06-20 23:29:36 +00:00
christos
9655f5c24c PR/38755: murray armfield: /bin posix programs missing setprogname and/or
setlocale
2008-05-26 14:21:08 +00:00
perry
8b0f9554ff convert __attribute__s to applicable cdefs.h macros 2007-12-15 19:44:37 +00:00
christos
3c769789fa PR/36534: Greg A. Woods: test(1) doesn't do -r and -w quite right
Use stat(2) instead of access(2) per POSIX.
2007-06-24 18:54:58 +00:00
simonb
9a8238c82f Remove a "CFLAGS+=-g" that seems to have snuck in with no good reason. 2007-06-22 03:24:16 +00:00
christos
35d9d3fddf Make sure we don't run over the end of the argument array while scanning
for input. This can happen if we have a unary not without an argument. When
we scan for the argument, we are already at the NULL element of the argument
array. Then when we scan ahead for a -a or -o, we end up testing the next
element after the NULL.
2007-05-24 18:47:08 +00:00
uwe
8e85c1baf1 Use the same wording for '-p' as for other file related tests. 2007-05-15 22:00:51 +00:00
christos
06519c05da PR/36092: B K: algorithmic inefficiency in bin/test/test.c:t_lex
test(1) scans for "operators" linearly in an array using strcmp() to
find a match. Since the list of "operators" is fixed, split them
into one and two character ones, and ones that start with a `-' and
ones they don't. This way we can optimize the compare function to
just check for one or two characters. Sort and use bsearch(3). We
could have used a single sorted array and bsearch(3), to save some
complexity, but I decided to be a bit fancier.
2007-03-28 01:47:25 +00:00
hubertf
7eef11b485 Revert previous (==) - not worth the trouble. 2006-09-24 13:24:08 +00:00
wiz
dff6308718 Bump date for previous. 2006-09-23 11:22:10 +00:00
hubertf
f9278bfbec Allow '==' as synonym to '=', just like our ksh and bash do.
This also affects the sh(1) builtin test command.
2006-09-22 22:15:24 +00:00
dbj
b41feff50f fixes for installing into a case insensitive $DESTDIR
when files may have hard links to a a name that only differs by case
  - change install to unconditionally remove its temporary file
    when installing hard links with -r.  This avoids problems when
    built with posix rename(2) semantics and reinstalling an existing
    hard link.
  - rework hard link targets in bsd.man.mk and bsd.links.mk
    to use makefile constructs instead of shell constructs
  - always reinstall hard links that may have case conflicts, even
    when MKUPDATE=yes, this ensures that they get added to METALOG
  - remove man pages which were hard linked to themselves in libform
  - remove improper hard link command for existing man page in libkrb5
  - fix libl's makefile to include bsd.lib.mk at end
  - remove shell quoting in link target for test's [.1 man page
2006-09-11 22:24:09 +00:00
christos
8c4dec8fa5 don't call get/set progname when we are a shell built-in. 2006-08-04 19:07:55 +00:00
christos
c338573fdf use getprogname() instead of argv[0], because some programs that execv, pass
the full path in argv[0] instead of just the basename. In reality, those
programs should be fixed (hello gdb for example).
2006-08-04 14:38:58 +00:00
simonb
dec70f4a29 KNF, use NULL instead of (type *)0. 2005-02-10 06:56:55 +00:00
agc
b5b2954259 Move UCB-licensed code from 4-clause to 3-clause licence.
Patches provided by Joel Baker in PR 22249, verified by myself.
2003-08-07 09:05:01 +00:00
wiz
14dfaa4b03 New policy: New sentences start on a new line.
Patches by Robert Elz <kre at munnari oz au>, with minimal changes by me.
2002-09-25 15:18:36 +00:00
wiz
10610e5a31 __STDC__ is always defined on NetBSD. 2002-05-25 23:12:16 +00:00
ross
dc5571b22e Generate <>& symbolically. I'm avoiding .../dist/... directories for now. 2002-02-08 01:21:55 +00:00
wiz
3ebcdc5e43 Whitespace nits. 2001-12-20 19:31:48 +00:00
wiz
4b238d257d Properly quote `[' as macro argument. 2001-10-17 21:14:45 +00:00
wiz
d3d81c4e84 Some KNF fixes by Petri Koistinen and me. 2001-09-16 19:03:26 +00:00
wiz
8cfb973b8e ANSIfy and slight KNF. Mostly #13594 by Petri Koistinen. 2001-07-30 10:17:41 +00:00
kleink
2caf6aacdd For commands and utilities, use EXIT STATUS rather than RETURN VALUES as
appropriate (and documented in mdoc(7)).
2000-09-04 07:30:07 +00:00
christos
e2e5d7bd40 - Enable test to be a shell builtin
- KNF
- Fix bug where test without arguments could access invalid memory
2000-04-09 23:24:59 +00:00
abs
98b54453f0 Remove duplicate 'string' / 's1' entry 1999-12-17 13:16:44 +00:00
kleink
900ca60345 Reverse the advice given to (now) prefer -h over -L; the former is defined in
1003.2bD3 and SVID4 and thus supposedly more portable.
1999-08-22 14:06:59 +00:00
kleink
e80c883c9d Operator precedence consistency; from "Andrew_L. Moore" <alm@SlewSys.Org>
in PR bin/7015.
1999-04-05 09:48:38 +00:00
garbled
1e1533cde9 the '[' wasn't being displayed properly as a command. Thanks to Charles
for the fix.
1999-03-09 07:05:33 +00:00
christos
9908eacfd6 char -> unsigned char 1998-11-04 20:12:12 +00:00
mycroft
ee9e50eacb Be more retentive about use of NOTREACHED and noreturn. 1998-07-28 11:41:40 +00:00
mrg
6be07a674c add missing .Nm calls and MLINKS. from spz@serpens.swb.de 1997-11-12 00:47:32 +00:00
mycroft
15de1c9fd2 Use S_IS*(), not S_IF*. 1997-10-19 17:54:18 +00:00