APItest.xs OUTPUT (was: perl@17206)
[p5sagit/p5-mst-13.2.git] / ext / XS / APItest / t / printf.t
CommitLineData
3e61d65a 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
deec275f 11use Test::More tests => 11;
3e61d65a 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 31print_long(4);
32print_float(4);
33print_long_double() if $ldok; # val=7 hardwired
34
35# Now redirect STDOUT and read from the file
36ok open(STDOUT, ">&", $oldout), "restore STDOUT";
37ok open(my $foo, "<foo.out"), "open foo.out";
38print "# Test output by reading from file\n";
39# now test the output
40my @output = map { chomp; $_ } <$foo>;
41close $foo;
deec275f 42ok @output >= 4, "captured at least four output lines";
3e61d65a 43
44is($output[0], "5.000", "print_double");
29e130bc 45is($output[1], "3", "print_int");
46is($output[2], "4", "print_long");
47is($output[3], "4.000", "print_float");
3e61d65a 48
49SKIP: {
50 skip "No long doubles", 1 unless $ldok;
29e130bc 51 is($output[4], "7.000", "print_long_double");
3e61d65a 52}
53