3 # test that config ( trap_nan => 1, trap_inf => 1) really works/dies
12 unshift @INC, '../lib'; # for running manually
19 my $mbi = 'Math::BigInt'; my $mbf = 'Math::BigFloat';
22 foreach my $class ($mbi, $mbf)
24 # can do and defaults are okay?
25 ok ($class->can('config'));
26 ok ($class->config()->{trap_nan}, 0);
27 ok ($class->config()->{trap_inf}, 0);
30 $cfg = $class->config( trap_nan => 1 ); ok ($cfg->{trap_nan},1);
32 # also test that new() still works normally
33 eval ("\$x = \$class->new('42'); \$x->bnan();");
34 ok ($@ =~/^Tried to set/, 1);
35 ok ($x,42); # after new() never modified
38 $cfg = $class->config( trap_nan => 0 ); ok ($cfg->{trap_nan},0);
41 $cfg = $class->config( trap_inf => 1 ); ok ($cfg->{trap_inf},1);
42 eval ("\$x = \$class->new('4711'); \$x->binf();");
43 ok ($@ =~/^Tried to set/, 1);
44 ok ($x,4711); # after new() never modified
47 eval ("\$x = \$class->new('4711'); \$x->bdiv(0);");
48 ok ($@ =~/^Tried to set/, 1);
49 ok ($x,4711); # after new() never modified
52 eval ("\$x = \$class->new('-0815'); \$x->bdiv(0);");
53 ok ($@ =~/^Tried to set/, 1);
54 ok ($x,-815); # after new() never modified
56 $cfg = $class->config( trap_nan => 1 );
58 eval ("\$x = \$class->new('0'); \$x->bdiv(0);");
59 ok ($@ =~/^Tried to set/, 1);
60 ok ($x,0); # after new() never modified
63 ##############################################################################
66 $x = Math::BigInt->new(2);
67 eval ("\$x = \$mbi->new('0.1');");
68 ok ($x,2); # never modified since it dies
69 eval ("\$x = \$mbi->new('0a.1');");
70 ok ($x,2); # never modified since it dies
73 ##############################################################################
76 $x = Math::BigFloat->new(2);
77 eval ("\$x = \$mbf->new('0.1a');");
78 ok ($x,2); # never modified since it dies