xref: /openbsd-src/gnu/usr.bin/perl/ext/XS-APItest/t/printf.t (revision 4c1e55dc91edd6e69ccc60ce855900fbc12cf34f)
1BEGIN {
2    push @INC, "::lib:$MacPerl::Architecture:" if $^O eq 'MacOS';
3    require Config; import Config;
4    if ($Config{'extensions'} !~ /\bXS\/APItest\b/) {
5        print "1..0 # Skip: XS::APItest was not built\n";
6        exit 0;
7    }
8}
9
10use Test::More tests => 11;
11
12BEGIN { use_ok('XS::APItest') };
13
14#########################
15
16my $ldok = have_long_double();
17
18# first some IO redirection
19ok open(my $oldout, ">&STDOUT"), "saving STDOUT";
20ok open(STDOUT, '>', "foo.out"),"redirecting STDOUT";
21
22# Allow for it to be removed
23END { unlink "foo.out"; };
24
25select STDOUT; $| = 1; # make unbuffered
26
27# Run the printf tests
28print_double(5);
29print_int(3);
30print_long(4);
31print_float(4);
32print_long_double() if $ldok;  # val=7 hardwired
33
34print_flush();
35
36# Now redirect STDOUT and read from the file
37ok open(STDOUT, ">&", $oldout), "restore STDOUT";
38ok open(my $foo, "<foo.out"), "open foo.out";
39#print "# Test output by reading from file\n";
40# now test the output
41my @output = map { chomp; $_ } <$foo>;
42close $foo;
43ok @output >= 4, "captured at least four output lines";
44
45is($output[0], "5.000", "print_double");
46is($output[1], "3", "print_int");
47is($output[2], "4", "print_long");
48is($output[3], "4.000", "print_float");
49
50SKIP: {
51   skip "No long doubles", 1 unless $ldok;
52   is($output[4], "7.000", "print_long_double");
53}
54
55