Skip to content

Commit

Permalink
Add exceptions for inf/nan on Windows
Browse files Browse the repository at this point in the history
On some systems inf and nan seem to be broken ('0'):
uname='Win32 strawberryperl 5.12.2.0 #1 Fri Nov  5 05:17:27 2010 i386'

t/32.cyclic-refs.t dies, add some debugging
  • Loading branch information
perlpunk committed Mar 5, 2019
1 parent 819bc19 commit b4d7d22
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
9 changes: 8 additions & 1 deletion t/31.schema.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ my $inftest1 = 0 + "inf";
my $inftest2 = 0 - "inf";
my $nantest = 0 + "nan";
diag("inf: $inftest1 -inf: $inftest2 nan: $nantest");
my $inf_broken = $inftest1 eq '0';
$inf_broken and diag("inf/nan seem broken, skipping those tests");

my $failsafe = <<"EOM";
# just strings
Expand Down Expand Up @@ -234,7 +236,12 @@ sub test_float {
my ($item) = @_;
my $flags = B::svref_2object(\$item)->FLAGS;
ok(not($flags & B::SVp_POK), sprintf("'%s' does not have string flag", $item));
ok($flags & B::SVp_NOK, sprintf("'%s' has double flag", $item));
if ($inf_broken) {
diag("Skip testing double flag, values for inf and nan seem broken");
}
else {
ok($flags & B::SVp_NOK, sprintf("'%s' has double flag", $item));
}
}

sub test_undef {
Expand Down
13 changes: 13 additions & 0 deletions t/32.cyclic-refs.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use Test::Warn;
use Data::Dumper;
use YAML::PP;

my $win32 = $^O eq 'MSWin32';

my $yaml = <<'EOM';
- &NODEA
name: A
Expand Down Expand Up @@ -36,27 +38,38 @@ my $data = eval {
my $error = $@;
cmp_ok($error, '=~', qr{found cyclic ref}i, "cyclic_refs=fatal");

$win32 and diag("after 'cyclic_refs=fatal'");

warning_like {
$warn->load_string($yaml);
} qr{found cyclic ref}i, "cyclic_refs=warn";
is($data->[0]->{link}->{link}, undef, "cyclic_refs=warn");

$win32 and diag("after 'cyclic_refs=warn'");

$data = $ignore->load_string($yaml);
is($data->[0]->{link}->{link}, undef, "cyclic_refs=ignore");

$win32 and diag("after 'cyclic_refs=ignore'");

$data = $allow->load_string($yaml);
cmp_ok($data->[0]->{link}->{link}->{name}, 'eq', 'A', "cyclic_refs=allow");
$win32 and diag("after 'cyclic_refs=allow'");

$data = $allow2->load_string($yaml);
cmp_ok($data->[0]->{link}->{link}->{name}, 'eq', 'A', "cyclic_refs unset (default=allow)");
$win32 and diag("after 'cyclic_refs=default'");

$data = eval {
$nonsense->load_string($yaml);
};
$error = $@;
cmp_ok($error, '=~', qr{invalid}i, "cyclic_refs=nonsense (invalid parameter)");

$win32 and diag("after 'cyclic_refs=nonsense'");

$data = $fatal->load_string($yaml2);
cmp_ok($data->[0]->{link}->{link}->{bar}, 'eq', 'boo', "cyclic_refs=fatal, no cyclic ref found");
$win32 and diag("after 'cyclic_refs=fatal, no cyclic ref found'");

done_testing;
4 changes: 3 additions & 1 deletion t/33.schema-dump.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ my $inftest1 = 0 + "inf";
my $inftest2 = 0 - "inf";
my $nantest = 0 + "nan";
diag("inf: $inftest1 -inf: $inftest2 nan: $nantest");
my $inf_broken = $inftest1 eq '0';
$inf_broken and diag("inf/nan seem broken, skipping those tests");

my $data_common = [
# quoted
Expand Down Expand Up @@ -150,7 +152,7 @@ my $yaml_core = <<'EOM';
- 'TRUE'
- 'False'
EOM
if ($] >= 5.008009) {
if ($] >= 5.008009 and not $inf_broken) {
push @$data_core, (
0+"inf",
0-"inf",
Expand Down

0 comments on commit b4d7d22

Please sign in to comment.