This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Obviously time to get some sleep.
[perl5.git] / ext / XS / APItest / t / printf.t
CommitLineData
3e61d65a
JH
1BEGIN {
2 chdir 't' if -d 't';
3 @INC = '../lib';
4 require Config; import Config;
5 if ($Config{'extensions'} !~ /\bXS\/APItest\b/) {
6 print "1..0 # Skip: XS::APItest was not built\n";
7 exit 0;
8 }
9}
10
11use Test::More tests => 15;
12
13BEGIN { use_ok('XS::APItest') };
14
15#########################
16
17my $ldok = have_long_double();
18
19# first some IO redirection
20ok open(my $oldout, ">&STDOUT"), "saving STDOUT";
21ok open(STDOUT, '>', "foo.out"),"redirecting STDOUT";
22
23# Allow for it to be removed
24END { unlink "foo.out"; };
25
26select STDOUT; $| = 1; # make unbuffered
27
28# Run the printf tests
29print_double(5);
3e61d65a 30print_int(3);
3e61d65a
JH
31print_long(4);
32print_float(4);
33print_long_double() if $ldok; # val=7 hardwired
29e130bc
JH
34print_iv(2);
35print_iv(-2);
36print_uv(3);
37print_nv(6);
3e61d65a
JH
38
39# Now redirect STDOUT and read from the file
40ok open(STDOUT, ">&", $oldout), "restore STDOUT";
41ok open(my $foo, "<foo.out"), "open foo.out";
42print "# Test output by reading from file\n";
43# now test the output
44my @output = map { chomp; $_ } <$foo>;
45close $foo;
46ok @output >= 9, "captured at least nine output lines";
47
48is($output[0], "5.000", "print_double");
29e130bc
JH
49is($output[1], "3", "print_int");
50is($output[2], "4", "print_long");
51is($output[3], "4.000", "print_float");
3e61d65a
JH
52
53SKIP: {
54 skip "No long doubles", 1 unless $ldok;
29e130bc 55 is($output[4], "7.000", "print_long_double");
3e61d65a
JH
56}
57
29e130bc
JH
58SKIP: {
59 skip "No perlio", 4 unless $Config{useperlio};
29b59940
JH
60 is($output[5], "2", "print_iv positive");
61 is($output[6], "-2", "print_iv negative");
62 is($output[7], "3", "print_uv");
63 is($output[8], "6.000", "print_nv");
29e130bc 64}
3e61d65a 65