1use Test::More tests => 11; 2 3BEGIN { use_ok('XS::APItest') }; 4 5######################### 6 7my $ldok = have_long_double(); 8 9# first some IO redirection 10ok open(my $oldout, ">&STDOUT"), "saving STDOUT"; 11ok open(STDOUT, '>', "foo.out"),"redirecting STDOUT"; 12 13# Allow for it to be removed 14END { unlink "foo.out"; }; 15 16select STDOUT; $| = 1; # make unbuffered 17 18# Run the printf tests 19print_double(5); 20print_int(3); 21print_long(4); 22print_float(4); 23print_long_double() if $ldok; # val=7 hardwired 24 25print_flush(); 26 27# Now redirect STDOUT and read from the file 28ok open(STDOUT, ">&", $oldout), "restore STDOUT"; 29ok open(my $foo, "<foo.out"), "open foo.out"; 30#print "# Test output by reading from file\n"; 31# now test the output 32my @output = map { chomp; $_ } <$foo>; 33close $foo; 34ok @output >= 4, "captured at least four output lines"; 35 36is($output[0], "5.000", "print_double"); 37is($output[1], "3", "print_int"); 38is($output[2], "4", "print_long"); 39is($output[3], "4.000", "print_float"); 40 41SKIP: { 42 skip "No long doubles", 1 unless $ldok; 43 is($output[4], "7.000", "print_long_double"); 44} 45 46