CVS commit: src/tests/usr.bin/printf

2021-05-19 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed May 19 22:45:49 UTC 2021

Modified Files:
src/tests/usr.bin/printf: printf.sh

Log Message:
With the (very) recent changes to printf(1), a numeric conversion from data
of the form '+1 (two (or more) characters after the quote) will now generate
an error message, and cause printf(1) to exit(1) when it is done.

Adapt the test cases which use that data form to handle that.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/printf/printf.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/printf/printf.sh
diff -u src/tests/usr.bin/printf/printf.sh:1.7 src/tests/usr.bin/printf/printf.sh:1.8
--- src/tests/usr.bin/printf/printf.sh:1.7	Wed May 19 22:20:34 2021
+++ src/tests/usr.bin/printf/printf.sh	Wed May 19 22:45:49 2021
@@ -1,4 +1,4 @@
-# $NetBSD: printf.sh,v 1.7 2021/05/19 22:20:34 kre Exp $
+# $NetBSD: printf.sh,v 1.8 2021/05/19 22:45:49 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -403,15 +403,15 @@ d_decimal()
 	expect 65		'%d'		"'A"
 	expect 065		'%03d'		"'A"
 	expect 49		'%d'		"'1"
-	expect 45		'%d'		"'-1"
-	expect 43		'%d'		"'+1"
+	expect_fail 45		'%d'		"'-1"
+	expect_fail 43		'%d'		"'+1"
 	expect 00		'%.2d'		"'"
 
 	expect 68		'%d'		'"D'
 	expect 069		'%03d'		'"E'
 	expect 51		'%d'		'"3'
-	expect 45		'%d'		'"-3'
-	expect 43		'%d'		'"+3'
+	expect_fail 45		'%d'		'"-3'
+	expect_fail 43		'%d'		'"+3'
 
 	expect -1		'% d'		-1
 	expect ' 1'		'% d'		1
@@ -527,14 +527,14 @@ u_unsigned()
 	expect 65		'%u'		"'A"
 	expect 065		'%03u'		"'A"
 	expect 49		'%u'		"'1"
-	expect 45		'%u'		"'-1"
-	expect 43		'%u'		"'+1"
+	expect_fail 45		'%u'		"'-1"
+	expect_fail 43		'%u'		"'+1"
 
 	expect 68		'%u'		'"D'
 	expect 069		'%03u'		'"E'
 	expect 51		'%u'		'"3'
-	expect 45		'%u'		'"-3'
-	expect 43		'%u'		'"+3'
+	expect_fail 45		'%u'		'"-3'
+	expect_fail 43		'%u'		'"+3'
 
 	# Note that the ' ' and '+' flags only apply to signed conversions
 	# so they should be simply ignored for '%u'
@@ -604,8 +604,8 @@ o_octal()
 	expect 101		'%o'		"'A"
 	expect 0101		'%04o'		"'A"
 	expect 61		'%o'		"'1"
-	expect 55		'%o'		"'-1"
-	expect 53		'%o'		"'+1"
+	expect_fail 55		'%o'		"'-1"
+	expect_fail 53		'%o'		"'+1"
 
 	expect 01747		'%#o'		999
 	expect '  02'		'%#4o'		2
@@ -613,8 +613,8 @@ o_octal()
 	expect 0101		'%#o'		"'A"
 	expect 0101		'%#04o'		"'A"
 	expect 061		'%#o'		"'1"
-	expect 055		'%#o'		"'-1"
-	expect 053		'%#o'		"'+1"
+	expect_fail 055		'%#o'		"'-1"
+	expect_fail 053		'%#o'		"'+1"
 	expect 063		'%#o'		063
 
 	# negative numbers are allowed, but printed as unsigned.
@@ -652,8 +652,8 @@ x_hex()
 	expect 41		'%x'		"'A"
 	expect 041		'%03x'		"'A"
 	expect 31		'%x'		"'1"
-	expect 2d		'%x'		"'-1"
-	expect 2b		'%x'		"'+1"
+	expect_fail 2d		'%x'		"'-1"
+	expect_fail 2b		'%x'		"'+1"
 
 	expect ' face '		'%5x '		64206
 
@@ -690,8 +690,8 @@ X_hex()
 	# the alpha digits, so just do minimal testing of that...
 
 	expect 3E7		%X		999
-	expect 2D		%X		"'-1"
-	expect 2B		%X		"'+1"
+	expect_fail 2D		%X		"'-1"
+	expect_fail 2B		%X		"'+1"
 	expect ' FACE '		'%5X '		64206
 	expect DEADBEEF		%X		3735928559
 
@@ -1556,8 +1556,8 @@ NetBSD_extensions()
 	expect 6.50e+01	'%e'		"'A"
 	expect 6.5e+01		'%.1e'		"'A"
 	expect 5e+01		'%.0e'		"'1"
-	expect 4.50e+01		'%.2e'		"'-1"
-	expect 4.300e+01	'%.3e'		"'+1"
+	expect_fail 4.50e+01	'%.2e'		"'-1"
+	expect_fail 4.300e+01	'%.3e'		"'+1"
 	expect 99.00	'%f'		'"c'
 	expect 97		'%g'		'"a'
 



CVS commit: src/tests/usr.bin/printf

2021-05-19 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Wed May 19 22:20:34 UTC 2021

Modified Files:
src/tests/usr.bin/printf: printf.sh

Log Message:
Fix a truly embarrassing quoting screwup.   There is an explanation as
to why this didn't cause any failures, but I won't go into it here.
This was detected by the about to be committed printf changes.

While here also correct a couple of minor comment layout issues.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/printf/printf.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/printf/printf.sh
diff -u src/tests/usr.bin/printf/printf.sh:1.6 src/tests/usr.bin/printf/printf.sh:1.7
--- src/tests/usr.bin/printf/printf.sh:1.6	Fri Apr 24 14:29:19 2020
+++ src/tests/usr.bin/printf/printf.sh	Wed May 19 22:20:34 2021
@@ -1,4 +1,4 @@
-# $NetBSD: printf.sh,v 1.6 2020/04/24 14:29:19 kre Exp $
+# $NetBSD: printf.sh,v 1.7 2021/05/19 22:20:34 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -1071,13 +1071,13 @@ g_floats()
 	expect 1.0		%#g	1		# p = 6, x = 0 :  %.5f
 	expect -0.50	%#g	-0.5		# p = 6, x = -1:  %.6f
 
-	expect 0.001234		%#.4g	0.001234	# p= 4, x = -3:  %.6f
+	expect 0.001234		%#.4g	0.001234	# p= 4, x = -3 :  %.6f
 
 	expect .		%#.4g			# p = 4, x = 3 :  %.0f
 	expect .0		%#.5g			# p = 5, x = 3 :  %.1f
 
 	expect 4.4?e+03		%.3g			# p = 3, x = 3 :  %.2e
-	expect 1.2e-05		%.2g	0.12	# p = 2, x = -5:  $.1e
+	expect 1.2e-05		%.2g	0.12	# p = 2, x = -5:  %.1e
 
 	expect 1e+10		%g	100
 	expect 1e+10		%g	1e10
@@ -1558,8 +1558,8 @@ NetBSD_extensions()
 	expect 5e+01		'%.0e'		"'1"
 	expect 4.50e+01		'%.2e'		"'-1"
 	expect 4.300e+01	'%.3e'		"'+1"
-	expect 99.00	'%f'		'"c"
-	expect 97		'%g'		'"a"
+	expect 99.00	'%f'		'"c'
+	expect 97		'%g'		'"a'
 
 	# NetBSD (non-POSIX) format excape extensions
 	expect ''		'\e'



CVS commit: src/tests/usr.bin/printf

2020-04-24 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Apr 24 14:29:19 UTC 2020

Modified Files:
src/tests/usr.bin/printf: printf.sh

Log Message:
ATF runs shell script tests with "sh -e" (WHY???)

Compensate for that by adding an explicit test to a command so
-e will not kill the shell when the command (expectedly) fails.

Previously this was saved by /bin/sh disabling -e in command subs.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/printf/printf.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/printf/printf.sh
diff -u src/tests/usr.bin/printf/printf.sh:1.5 src/tests/usr.bin/printf/printf.sh:1.6
--- src/tests/usr.bin/printf/printf.sh:1.5	Tue Nov 12 18:59:51 2019
+++ src/tests/usr.bin/printf/printf.sh	Fri Apr 24 14:29:19 2020
@@ -1,4 +1,4 @@
-# $NetBSD: printf.sh,v 1.5 2019/11/12 18:59:51 kre Exp $
+# $NetBSD: printf.sh,v 1.6 2020/04/24 14:29:19 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -178,7 +178,7 @@ expect_fail()
 	test -z "${RES}" &&
 		atf_fail "$*  ... failed (${STAT}) without error message"
 
-	RES="$( do_printf "$@" 2>/dev/null ; echo X )"
+	RES="$( do_printf "$@" 2>/dev/null || : ; echo X )"
 	RES=${RES%X}	# hack to defeat \n removal from $() output
 
 	case "${RES}" in



CVS commit: src/tests/usr.bin/printf

2018-09-14 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Sep 14 19:57:57 UTC 2018

Modified Files:
src/tests/usr.bin/printf: printf.sh

Log Message:
Move the tests of character value args to floating conversions
out of the %e test and into the NetBSD specific tests, while POSIX
once (apparently) required (or seemed to require) support for that,
it no longer does (and character value args to float conversions do
not make much sense - char valuse are always integers).

When char conversions are supported, test that \'  (or \" ) (that is,
no character following the quote) works as an arg (should result in zero,
as there's a \0 in the arg after the quote char).

Add some big/small number %g conversion tests.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/printf/printf.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/printf/printf.sh
diff -u src/tests/usr.bin/printf/printf.sh:1.2 src/tests/usr.bin/printf/printf.sh:1.3
--- src/tests/usr.bin/printf/printf.sh:1.2	Mon Sep 10 15:02:11 2018
+++ src/tests/usr.bin/printf/printf.sh	Fri Sep 14 19:57:57 2018
@@ -1,4 +1,4 @@
-# $NetBSD: printf.sh,v 1.2 2018/09/10 15:02:11 kre Exp $
+# $NetBSD: printf.sh,v 1.3 2018/09/14 19:57:57 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -408,6 +408,7 @@ d_decimal()
 	expect 49		'%d'		"'1"
 	expect 45		'%d'		"'-1"
 	expect 43		'%d'		"'+1"
+	expect 00		'%.2d'		"'"
 
 	expect 68		'%d'		'"D'
 	expect 069		'%03d'		'"E'
@@ -476,6 +477,8 @@ i_decimal()
 	expect '02  '		'%-4.2i'	2
 	expect ' +02'		'%+ 4.2i'	2
 
+	expect 0		'%i'		'"'
+
 	expect_fail '0'		%i	x22
 	expect_fail '123'	%i	123Mb
 	expect_fail '15'	%i	0xfooD
@@ -996,12 +999,6 @@ e_floats()
 	expect2 '  nan' 'nan(*)'	%5e		nan
 	expect2 'nan  ' 'nan(*)'	%-5e		NAN
 
-	expect 6.50e+01	'%e'		"'A"
-	expect 6.5e+01		'%.1e'		"'A"
-	expect 5e+01		'%.0e'		"'1"
-	expect 4.50e+01		'%.2e'		"'-1"
-	expect 4.300e+01	'%.3e'		"'+1"
-
 	expect_fail 0.00e+00 '%e'	NOT-E
 	expect_fail 1.20e+00 '%e'	1.2Gb
 
@@ -1085,6 +1082,16 @@ g_floats()
 	expect 4.4?e+03		%.3g			# p = 3, x = 3 :  %.2e
 	expect 1.2e-05		%.2g	0.12	# p = 2, x = -5:  $.1e
 
+	expect 1e+10		%g	100
+	expect 1e+10		%g	1e10
+	expect 1e+10		%g	1e+10
+	expect 1e-10		%g	1e-10
+	expect 100	%.11g	100
+	expect 100.	%#.11g	100
+	expect 1e+99		%g	1e99
+	expect 1e+100		%g	1e100
+	expect 1e-100		%g	1e-100
+
 	expect2 inf infinity	%g	Infinity
 	expect2 -inf -infinity	%g	-INF
 	expect2 nan 'nan(*)'	%g	NaN
@@ -1549,6 +1556,14 @@ NetBSD_extensions()
 		# verify float support, so don't bother...
 	fi
 
+	expect 6.50e+01	'%e'		"'A"
+	expect 6.5e+01		'%.1e'		"'A"
+	expect 5e+01		'%.0e'		"'1"
+	expect 4.50e+01		'%.2e'		"'-1"
+	expect 4.300e+01	'%.3e'		"'+1"
+	expect 99.00	'%f'		'"c"
+	expect 97		'%g'		'"a"
+
 	# NetBSD (non-POSIX) format excape extensions
 	expect ''		'\e'
 	expect ''		'\E'
@@ -1750,7 +1765,7 @@ else
 	Failures=0
 
 	STDERR=$(mktemp ${TMPDIR:-/tmp}/Test-XX)
-	trap 'rm -f "${STDERR}"' EXIT
+	trap "rm -f '${STDERR}'" EXIT
 	exec 3>"${STDERR}"
 
 	case "$#" in



CVS commit: src/tests/usr.bin/printf

2018-09-14 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Fri Sep 14 19:52:23 UTC 2018

Modified Files:
src/tests/usr.bin/printf: t_builtin.sh

Log Message:
When the shell being tested for builtin printf supports "type -t"
use it to test if printf is built in, it is must more reliable that
guessing at the output format and message of "type" (without -t).


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/printf/t_builtin.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/printf/t_builtin.sh
diff -u src/tests/usr.bin/printf/t_builtin.sh:1.3 src/tests/usr.bin/printf/t_builtin.sh:1.4
--- src/tests/usr.bin/printf/t_builtin.sh:1.3	Mon Sep 10 15:02:11 2018
+++ src/tests/usr.bin/printf/t_builtin.sh	Fri Sep 14 19:52:23 2018
@@ -1,4 +1,4 @@
-# $NetBSD: t_builtin.sh,v 1.3 2018/09/10 15:02:11 kre Exp $
+# $NetBSD: t_builtin.sh,v 1.4 2018/09/14 19:52:23 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -98,19 +98,24 @@ Not_builtin()
 
 setup()
 {
-	case "$(unset LANG LC_ALL LC_NUMERIC LC_CTYPE LC_MESSAGES
-	${TEST_SH} -c 'type printf' 2>&1 )" in
-
-	( *[Bb]uiltin* | *[Bb]uilt[-\ ][Ii]n* )
-		# nothing here, it all happens below.
-		;;
+	# If the shell being used for its printf supports "type -t", use it
+	if B=$( ${TEST_SH} -c 'type -t printf' 2>/dev/null )
+	then
+		case "$B" in
+		( builtin )	return 0;;
+		esac
+	else
+		# We get here if type -t is not supported, or it is,
+		# but printf is completely unknown.  No harm trying again.
 
-	(*)	Tests=
-		define Not_builtin 'Dummy test to skip when no printf builtin'
-		return 1
-		;;
-	esac
+		case "$( unset LANG LC_ALL LC_NUMERIC LC_CTYPE LC_MESSAGES
+		${TEST_SH} -c 'type printf' 2>&1 )" in
+		( *[Bb]uiltin* | *[Bb]uilt[-\ ][Ii]n* ) return 0;;
+		esac
+	fi
 
+	Tests=
+	define Not_builtin 'Dummy test to skip when no printf builtin'
 	return 0
 }
 



CVS commit: src/tests/usr.bin/printf

2018-09-10 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Mon Sep 10 15:02:11 UTC 2018

Modified Files:
src/tests/usr.bin/printf: printf.sh t_builtin.sh

Log Message:
Add a test where printf is run twice in the same shell, and the
first invocation uses \c in a %b arg - make sure that 2nd invocation
is not affected by that  (it was until recently, for a very long time).


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/printf/printf.sh
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/printf/t_builtin.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/printf/printf.sh
diff -u src/tests/usr.bin/printf/printf.sh:1.1 src/tests/usr.bin/printf/printf.sh:1.2
--- src/tests/usr.bin/printf/printf.sh:1.1	Wed Sep  5 21:05:40 2018
+++ src/tests/usr.bin/printf/printf.sh	Mon Sep 10 15:02:11 2018
@@ -1,4 +1,4 @@
-# $NetBSD: printf.sh,v 1.1 2018/09/05 21:05:40 kre Exp $
+# $NetBSD: printf.sh,v 1.2 2018/09/10 15:02:11 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -1345,6 +1345,15 @@ b_SysV_echo_backslash_c()
 	# This is undefined, though would be nice if we could rely upon it
 	# expect "abcd"		%.1b		'a\c' 'b\c' 'c\c' 'd\c' '\c' e
 
+	# Check for interference from one instance of execution of
+	# a builtin printf execution to another
+	# (this makes no sense to test for standalone printf, and for which
+	# the tests don't handle ';' magic args, so this would not work)
+	if $BUILTIN_TEST
+	then
+		expect abcdefjklmno   %s%b%s abc 'def\c' ghi ';' %s%s jkl mno
+	fi
+
 	return $RVAL
 }
 define	b_SysV_echo_backslash_c	'Use of \c in arg to %b format'

Index: src/tests/usr.bin/printf/t_builtin.sh
diff -u src/tests/usr.bin/printf/t_builtin.sh:1.2 src/tests/usr.bin/printf/t_builtin.sh:1.3
--- src/tests/usr.bin/printf/t_builtin.sh:1.2	Sat Sep  8 18:24:01 2018
+++ src/tests/usr.bin/printf/t_builtin.sh	Mon Sep 10 15:02:11 2018
@@ -1,4 +1,4 @@
-# $NetBSD: t_builtin.sh,v 1.2 2018/09/08 18:24:01 kre Exp $
+# $NetBSD: t_builtin.sh,v 1.3 2018/09/10 15:02:11 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -63,6 +63,9 @@ do_printf()
 	for ARG
 	do
 		case "${ARG}" in
+		(';')	# Allow multiple commands
+			COMMAND="${COMMAND} ; printf"
+			;;
 		(*\'*)
 			# This is kind of odd, we need a working
 			# printf in order to test printf ...



CVS commit: src/tests/usr.bin/printf

2018-09-08 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Sep  8 18:24:02 UTC 2018

Modified Files:
src/tests/usr.bin/printf: t_builtin.sh

Log Message:
Make sure we're in the standard locale when testing for printf
being built in to the shell, so we don't receive an unrecognisable
(to the script) message from the shell when we ask it.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/printf/t_builtin.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/printf/t_builtin.sh
diff -u src/tests/usr.bin/printf/t_builtin.sh:1.1 src/tests/usr.bin/printf/t_builtin.sh:1.2
--- src/tests/usr.bin/printf/t_builtin.sh:1.1	Wed Sep  5 21:05:40 2018
+++ src/tests/usr.bin/printf/t_builtin.sh	Sat Sep  8 18:24:01 2018
@@ -1,4 +1,4 @@
-# $NetBSD: t_builtin.sh,v 1.1 2018/09/05 21:05:40 kre Exp $
+# $NetBSD: t_builtin.sh,v 1.2 2018/09/08 18:24:01 kre Exp $
 #
 # Copyright (c) 2018 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -95,7 +95,8 @@ Not_builtin()
 
 setup()
 {
-	case "$( ${TEST_SH} -c 'type printf' 2>&1 )" in
+	case "$(unset LANG LC_ALL LC_NUMERIC LC_CTYPE LC_MESSAGES
+	${TEST_SH} -c 'type printf' 2>&1 )" in
 
 	( *[Bb]uiltin* | *[Bb]uilt[-\ ][Ii]n* )
 		# nothing here, it all happens below.