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