| 1 |
use Test::More tests => 13; |
| 2 |
|
| 3 |
BEGIN { use_ok('XS::APItest') }; |
| 4 |
|
| 5 |
######################### |
| 6 |
|
| 7 |
my $ldok = have_long_double(); |
| 8 |
|
| 9 |
# first some IO redirection |
| 10 |
ok open(my $oldout, ">&STDOUT"), "saving STDOUT"; |
| 11 |
ok open(STDOUT, '>', "foo.out"),"redirecting STDOUT"; |
| 12 |
|
| 13 |
# Allow for it to be removed |
| 14 |
END { unlink "foo.out"; }; |
| 15 |
|
| 16 |
select STDOUT; $| = 1; # make unbuffered |
| 17 |
|
| 18 |
# Run the printf tests |
| 19 |
print_double(5); |
| 20 |
print_int(3); |
| 21 |
print_long(4); |
| 22 |
print_float(4); |
| 23 |
print_long_double() if $ldok; # val=7 hardwired |
| 24 |
print_long_doubleL() if $ldok; # val=7 hardwired |
| 25 |
|
| 26 |
print_flush(); |
| 27 |
|
| 28 |
# Now redirect STDOUT and read from the file |
| 29 |
ok open(STDOUT, ">&", $oldout), "restore STDOUT"; |
| 30 |
ok open(my $foo, '<', 'foo.out'), "open foo.out"; |
| 31 |
#print "# Test output by reading from file\n"; |
| 32 |
# now test the output |
| 33 |
my @output = map { chomp; $_ } <$foo>; |
| 34 |
close $foo; |
| 35 |
ok @output >= 4, "captured at least four output lines"; |
| 36 |
|
| 37 |
is($output[0], "5.000", "print_double"); |
| 38 |
is($output[1], "3", "print_int"); |
| 39 |
is($output[2], "4", "print_long"); |
| 40 |
is($output[3], "4.000", "print_float"); |
| 41 |
|
| 42 |
SKIP: { |
| 43 |
skip "No long doubles", 2 unless $ldok; |
| 44 |
is($output[4], "7.000", "print_long_double"); |
| 45 |
is($output[5], "7.000", "print_long_doubleL"); |
| 46 |
} |
| 47 |
|
| 48 |
{ |
| 49 |
# GH #17338 |
| 50 |
# This is unlikely to fail here since int and long are the |
| 51 |
# same size on our usual platforms, but it's less likely to |
| 52 |
# be ignored than the warning that's the real diagnostic |
| 53 |
# for this bug. |
| 54 |
my $uv_max = ~0; |
| 55 |
my $iv_max = $uv_max >> 1; |
| 56 |
my $max_out = "iv $iv_max uv $uv_max"; |
| 57 |
is(test_MAX_types(), $max_out, |
| 58 |
"check types for IV_MAX and UV_MAX match IVdf/UVuf"); |
| 59 |
} |