Commit Graph

139 Commits

Author SHA1 Message Date
Jilles Tjoelker
17fffb23f6 printf: Add test for width and precision in %b format
PR:		229641
Submitted by:	pfg
2018-08-13 21:54:27 +00:00
Jilles Tjoelker
051c7fdd5c printf: Fix \c in %b in printf builtin exiting the shell after r337458
SVN r337458 erroneously partially reverted r265885.

This is immediately visible when running the Kyua/ATF tests for
usr.bin/printf, which actually test sh's printf builtin.

PR:		229641
2018-08-11 11:13:34 +00:00
Pedro F. Giffuni
702da35288 Fix printf(1) ignores width and precision in %b format.
The precision with the conversion specifier b is specified by POSIX: see
point 7 in the reference documentation.

This corrects previous wrong log in r337440.

Reference: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/printf.html

PR:	229641
Reported by:	Rudolf Cejka
Submitted by:	Garrett D'Amore (illumos)
MFC after:	1 week
2018-08-08 15:25:01 +00:00
Pedro F. Giffuni
94e460157d Revert r337440: the log message is wrong. 2018-08-08 15:12:32 +00:00
Pedro F. Giffuni
e21ce9d742 Fix printf(1) ignores width and precision in %b format.
The precision with behavior is "unspecified" by POSIX (as of 2018), but
most implementations seem to have taken it to be treated the same as for
"s"; applied after the unescaping.
Adopt the same treatment on our printf.

PR:	229641
Submitted by:	Garrett D'Amore (illumos)
2018-08-07 23:03:50 +00:00
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Bryan Drewery
ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Enji Cooper
d511b20a69 Add HAS_TESTS to all Makefiles that are currently using the
`SUBDIR.${MK_TESTS}+= tests` idiom.

This is a follow up to r321912.
2017-08-02 08:50:42 +00:00
Enji Cooper
4b330699f8 Convert traditional ${MK_TESTS} conditional idiom for including test
directories to SUBDIR.${MK_TESTS} idiom

This is being done to pave the way for future work (and homogenity) in
^/projects/make-check-sandbox .

No functional change intended.

MFC after:	1 weeks
2017-08-02 08:35:51 +00:00
Jilles Tjoelker
342b089bca printf: Output formatted data directly, instead of via asprintf.
Long ago, sh used to have its own optimized and restricted string formatting
implementation, which the printf builtin had to bypass via asprintf() to a
temporary buffer. Since sh has used libc's string formatting implementation
for a long time, remove the workaround.

Add a check to keep  printf %c ''  working the same way (output nothing);
POSIX allows both outputting nothing and outputting a NUL byte.

Also, this change avoids silently discarding format directives for whose
output asprintf() cannot allocate memory.
2017-04-29 21:48:11 +00:00
Warner Losh
fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00
Enji Cooper
430f7286a5 Merge ^/user/ngie/release-pkg-fix-tests to unbreak how test files are installed
after r298107

Summary of changes:

- Replace all instances of FILES/TESTS with ${PACKAGE}FILES. This ensures that
  namespacing is kept with FILES appropriately, and that this shouldn't need
  to be repeated if the namespace changes -- only the definition of PACKAGE
  needs to be changed
- Allow PACKAGE to be overridden by callers instead of forcing it to always be
  `tests`. In the event we get to the point where things can be split up
  enough in the base system, it would make more sense to group the tests
  with the blocks they're a part of, e.g. byacc with byacc-tests, etc
- Remove PACKAGE definitions where possible, i.e. where FILES wasn't used
  previously.
- Remove unnecessary TESTSPACKAGE definitions; this has been elided into
  bsd.tests.mk
- Remove unnecessary BINDIRs used previously with ${PACKAGE}FILES;
  ${PACKAGE}FILESDIR is now automatically defined in bsd.test.mk.
- Fix installation of files under data/ subdirectories in lib/libc/tests/hash
  and lib/libc/tests/net/getaddrinfo
- Remove unnecessary .include <bsd.own.mk>s (some opportunistic cleanup)

Document the proposed changes in share/examples/tests/tests/... via examples
so it's clear that ${PACKAGES}FILES is the suggested way forward in terms of
replacing FILES. share/mk/bsd.README didn't seem like the appropriate method
of communicating that info.

MFC after: never probably
X-MFC with: r298107
PR: 209114
Relnotes: yes
Tested with: buildworld, installworld, checkworld; buildworld, packageworld
Sponsored by: EMC / Isilon Storage Division
2016-05-04 23:20:53 +00:00
Glen Barber
7d536dc855 MFH
Sponsored by:	The FreeBSD Foundation
2016-03-10 21:16:01 +00:00
Bryan Drewery
15c433351f DIRDEPS_BUILD: Connect MK_TESTS.
Sponsored by:	EMC / Isilon Storage Division
2016-03-09 22:46:01 +00:00
Glen Barber
43faedc133 First pass to fix the 'tests' packages.
Sponsored by:	The FreeBSD Foundation
2016-02-02 22:26:49 +00:00
Enji Cooper
b2d48be1bc Refactor the test/ Makefiles after recent changes to bsd.test.mk (r289158) and
netbsd-tests.test.mk (r289151)

- Eliminate explicit OBJTOP/SRCTOP setting
- Convert all ad hoc NetBSD test integration over to netbsd-tests.test.mk
- Remove unnecessary TESTSDIR setting
- Use SRCTOP where possible for clarity

MFC after: 2 weeks
Sponsored by: EMC / Isilon Storage Divison
2015-10-12 08:16:03 +00:00
Simon J. Gerraty
ccfb965433 Add META_MODE support.
Off by default, build behaves normally.
WITH_META_MODE we get auto objdir creation, the ability to
start build from anywhere in the tree.

Still need to add real targets under targets/ to build packages.

Differential Revision:       D2796
Reviewed by: brooks imp
2015-06-13 19:20:56 +00:00
Simon J. Gerraty
44d314f704 dirdeps.mk now sets DEP_RELDIR 2015-06-08 23:35:17 +00:00
Simon J. Gerraty
98e0ffaefb Merge sync of head 2015-05-27 01:19:58 +00:00
Jilles Tjoelker
22ea47ec90 sh: Fix compiler warnings related to duplicate or missing declarations. 2015-03-01 21:46:55 +00:00
Simon J. Gerraty
ee7b0571c2 Merge head from 7/28 2014-08-19 06:50:54 +00:00
Jilles Tjoelker
fd1e753fbc printf: Install tests/regress.missingpos1.out, fixing tests. 2014-06-01 13:33:22 +00:00
Pedro F. Giffuni
cacacde774 Fix m2 regression test.
This is not really a good test as the behaviour for /c is unspecified.

For the record, ksh93 returns:

$ printf "abc\n\cdef"
abc
ef$

Discussed with:	Garret D'Amore (Illumos)
2014-05-31 00:54:21 +00:00
Pedro F. Giffuni
583d27945d Update number of tests.
Suggested by:	jmmv
2014-05-29 19:48:18 +00:00
Pedro F. Giffuni
ea1a630ade Minor style knit. 2014-05-29 19:43:43 +00:00
Pedro F. Giffuni
f764fa47f0 printf(1): add tests for warn about incomplete uses n$
Submitted by:	jilles
MFC after:	2 weeks
2014-05-26 15:08:39 +00:00
Pedro F. Giffuni
4aa1792423 printf(1): warn about incomplete uses n$
Reviewed by:	jilles
Obtained from:	Illumos
MFC after:	2 weeks
2014-05-26 14:57:47 +00:00
Simon J. Gerraty
fae50821ae Updated dependencies 2014-05-16 14:09:51 +00:00
Jilles Tjoelker
4e4d980265 printf: Fix missing arguments for %u/%o/%x/%X after r265592.
If a numeric argument is missing, zero should be assumed, for signed as well
as unsigned conversions.

This fixes the 'zero' regression tests.

r265592 erroneously reverted r244407.
2014-05-13 21:24:55 +00:00
Pedro F. Giffuni
30238f4963 printf: fix regression after illumos merges.
The "bltin/bltin.h" wrappers do not support exit() and attempting
to call it will exit sh completely.

Note that errx() is acceptable but will always return with status 2.

Reported by:	jilles (and the testing framework)
Fix by:		jilles
Pointyhat:	pfg
2014-05-11 17:28:57 +00:00
Pedro F. Giffuni
76f66be6bf prinf: replace use of alloca with variable length array.
Use of alloca(3) is discouraged in FreeBSD. Using a VLA
is simple and should be more portable.

Requested by:	jilles
2014-05-10 22:27:01 +00:00
Simon J. Gerraty
76b28ad6ab Updated dependencies 2014-05-10 05:16:28 +00:00
Simon J. Gerraty
cc3f4b9965 Merge from head 2014-05-08 23:54:15 +00:00
Pedro F. Giffuni
437bce620f Fix the incorrect handling of %b and \c in printf(1)
This is required for POSIX compliance.

Obtained from:	Garrett D'Amore (Illumos)
MFC after:	4 days
2014-05-08 20:20:59 +00:00
Pedro F. Giffuni
f8a6c905bf Add width and precision specifiers to printf(1) %n$.
This actually completes r264743 so that width and precision
specifiers work properly with %n$. These keeps consistency
with  ksh93 and zsh.

Requested by:	jilles
Obtained from:	Garrett D'Amore (Illumos)
MFC after:	4 days
2014-05-07 19:30:28 +00:00
Warner Losh
c6063d0da8 Use src.opts.mk in preference to bsd.own.mk except where we need stuff
from the latter.
2014-05-06 04:22:01 +00:00
Simon J. Gerraty
3b8f084595 Merge head 2014-04-28 07:50:45 +00:00
Pedro F. Giffuni
b0620803d5 Add parameterized position handling to printf(1).
Add a new %n$ option to change the order of the parameters as
done in the ksh93 builtin printf (among others).

For example:
%printf '%2$1d %1$s\n' one 2 three 4
2 one
4 three

The feature was written by Garret D'Amore under a
BSD license for Nexenta/illumos.

Reference:
http://garrett.damore.org/2010/10/new-implementation-of-printf.html

PR:		bin/152934
Obtained from:	Illumos
MFC after:	2 weeks
2014-04-21 22:47:18 +00:00
Pedro F. Giffuni
f77d666207 Minor style(9) cleanups
#define should be followed by a tab.

MFC after:	3 days
2014-04-17 01:43:15 +00:00
Julio Merino
3a92d97ff0 Migrate most of tools/regression/usr.bin/ to the new tests layout.
I'm starting with the easy cases.  The leftovers need to be looked at a
bit more closely.

Note that this change _does_ modify the code of the old tests.  This is
required in order to allow the code to locate the data files in the
source directory instead of the current directory, because Kyua
automatically changes the latter to a temporary directory.

Also note that at least one test is known to be broken here.  Actually,
the test is not really broken: it's marked as a TODO but unfortunately
Kyua's TAP parser currently does not understand that.  Will have to be
fixed separately.
2014-03-16 08:04:06 +00:00
Simon J. Gerraty
7cf3a1c6b2 Updated dependencies 2013-03-11 17:21:52 +00:00
Simon J. Gerraty
f5f7c05209 Updated dependencies 2013-02-16 01:23:54 +00:00
David E. O'Brien
d9a447559b Sync with HEAD. 2013-02-08 16:10:16 +00:00
Eitan Adler
2f01c791e9 POSIX requires that non-existent or null arguments be treated as if a
zero argument were supplied.

Add a regression test to catch this case as well.

PR:		bin/174521
Submitted by:	Daniel Shahaf <danielsh@elego.de> (pr)
Submitted by:	Mark Johnston <markjdb@gmail.com> (initial patch)
Reviewed by:	jilles
Approved by:	cperciva (implicit)
MFC after:	3 weeks
2012-12-18 21:02:38 +00:00
Simon J. Gerraty
23090366f7 Sync from head 2012-11-04 02:52:03 +00:00
Jilles Tjoelker
7cbda73825 sh: Prefer internal nextopt() to libc getopt().
This reduces code duplication and code size.

/usr/bin/printf is not affected.

Side effect: different error messages when certain builtins are passed
invalid options.
2012-09-15 21:56:30 +00:00
Marcel Moolenaar
7750ad47a9 Sync FreeBSD's bmake branch with Juniper's internal bmake branch.
Requested by: Simon Gerraty <sjg@juniper.net>
2012-08-22 19:25:57 +00:00
Eitan Adler
50d675f7a9 Remove trailing whitespace per mdoc lint warning
Disussed with:	gavin
No objection from:	doc
Approved by:	joel
MFC after:	3 days
2012-03-29 05:02:12 +00:00
Pedro F. Giffuni
ab71f27172 Style cleanups for printf.
PR:		bin/152934
Approved by:	jhb (mentor)
Obtained from:	Illumos
MFC after:	2 weeks
2012-01-12 20:30:20 +00:00
Jilles Tjoelker
27a43b2e51 printf(1): Document that %c and precision for %b/%s use bytes, not chars.
This means these features do not work as expected with multibyte characters.

This perhaps less than ideal behaviour matches printf(3) and is specified by
POSIX.
2011-05-28 14:32:47 +00:00