2
# improve printf.c test coverage
4
# Copyright (C) 2008-2011 Free Software Foundation, Inc.
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
my $try = "Try \`$prog --help' for more information.\n";
25
# Turn off localization of executable's output.
26
@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
30
['no-args', {EXIT=>1}, {ERR=>"$prog: missing operand\n$try"}],
31
['no-arg2', '--', {EXIT=>1}, {ERR=>"$prog: missing operand\n$try"}],
32
['escape-1', q('\a\b\f\n\r\t\v\z\c'), {OUT=>"\a\b\f\n\r\t\x0b\\z"}],
33
['hex-ucX', '%X 999', {OUT=>"3E7"}],
34
['hex-ucXw', '%4X 999', {OUT=>" 3E7"}],
35
['hex-ucXp', '%.4X 999', {OUT=>"03E7"}],
36
['hex-ucXwp', '%5.4X 999', {OUT=>" 03E7"}],
37
['hex-vw', '%*X 4 42', {OUT=>" 2A"}],
38
['hex-vp', '%.*X 4 42', {OUT=>"002A"}],
39
['hex-vwvp', '%*.*X 3 2 15', {OUT=>" 0F"}],
40
['b', q('nl\ntab\tx'), {OUT=>"nl\ntab\tx"}],
41
['c1', '%c 123', {OUT=>"1"}],
42
['cw', '%\*c 3 123', {OUT=>" 1"}],
43
['d-ucXwp', '%5.4d 999', {OUT=>" 0999"}],
44
['d-vw', '%*d 4 42', {OUT=>" 42"}],
45
['d-vp', '%.*d 4 42', {OUT=>"0042"}],
46
['d-vwvp', '%*.*d 3 2 15', {OUT=>" 15"}],
47
['d-neg-prec', '%.*d -3 15', {OUT=>"15"}],
48
['d-big-prec', "%.*d $pow_2_31 15", # INT_MAX
49
{EXIT=>1}, {ERR=>"$prog: invalid precision: $pow_2_31\n"}],
50
['d-big-fwidth', "%*d $pow_2_31 15", # INT_MAX
51
{EXIT=>1}, {ERR=>"$prog: invalid field width: $pow_2_31\n"}],
52
['F', '%F 1', {OUT=>"1.000000"}],
53
['LF', '%LF 1', {OUT=>"1.000000"}],
54
['E', '%E 2', {OUT=>"2.000000E+00"}],
55
['LE', '%LE 2', {OUT=>"2.000000E+00"}],
56
['s', '%s x', {OUT=>"x"}],
57
['sw', '%\*s 2 x', {OUT=>" x"}],
58
['sp', '%.\*s 2 abcd', {OUT=>"ab"}],
59
['swp', '%\*.\*s 2 2 abcd', {OUT=>"ab"}],
60
['sw-no-args', '%\*s'],
61
['sw-no-args2', '%.\*s'],
62
['G-ucXwp', '%5.4G 3', {OUT=>" 3"}],
63
['G-vw', '%*G 4 42', {OUT=>" 42"}],
64
['G-vp', '%.*G 4 42', {OUT=>"42"}],
65
['G-vwvp', '%*.*G 5 3 15', {OUT=>" 15"}],
66
['esc', q('\xaa\0377'), {OUT=>"\xaa\0377"}],
67
['esc-bad-hex', q('\x'), {EXIT=>1},
68
{ERR=>"$prog: missing hexadecimal number in escape\n"}],
69
# ['u4', q('\u09ac'), {OUT=>"\xe0a6ac"}],
70
['u-invalid', q('\u0000'), {EXIT=>1},
71
{ERR=>"$prog: invalid universal character name \\u0000\n"}],
72
['u-missing', q('\u'), {EXIT=>1},
73
{ERR=>"$prog: missing hexadecimal number in escape\n"}],
74
['d-invalid', '%d no-num', {OUT=>'0'}, {EXIT=>1},
75
# Depending on the strtol implementation we expect one of these:
76
# no-num: Invalid argument (FreeBSD6)
77
# no-num: expected a numeric value (glibc, Solaris 10)
78
{ERR_SUBST => 's/Invalid argument$/expected a numeric value/'},
79
{ERR=>"$prog: no-num: expected a numeric value\n"}],
80
['d-bad-suffix', '%d 9z', {OUT=>'9'}, {EXIT=>1},
81
{ERR=>"$prog: 9z: value not completely converted\n"}],
82
['d-out-of-range', '%d '.('9'x30), {EXIT=>1},
83
{OUT=>"inaccurate"}, {OUT_SUBST => 's/\d+/inaccurate/'},
84
{ERR=>"$prog: 9...9\n"}, {ERR_SUBST => 's/9+.*/9...9/'}],
85
['excess', 'B 1', {OUT=>'B'},
86
{ERR=>"$prog: warning: ignoring excess arguments, starting with `1'\n"}],
87
['percent', '%%', {OUT=>'%'}],
88
['d-sp', q('% d' 33), {OUT=>' 33'}],
89
['d-plus', q('%+d' 33), {OUT=>'+33'}],
90
['d-minus', q('%-d' 33), {OUT=> '33'}],
91
['d-zero', q('%02d' 1), {OUT=> '01'}],
92
['d-quote', q("%'d" 3333), {OUT=> '3333'}, {OUT_SUBST => 'tr/3//c'}],
93
['d-hash', q("%#d" 3333), {EXIT=>1},
94
{ERR=>"$prog: %#d: invalid conversion specification\n"}],
97
my $save_temps = $ENV{DEBUG};
98
my $verbose = $ENV{VERBOSE};
100
my $fail = run_tests ($prog, \$prog, \@Tests, $save_temps, $verbose);