3 # test calling conventions, and :constant overloading
11 # chdir 't' if -d 't';
12 unshift @INC, '../lib'; # for running manually
16 package Math::BigInt::Test;
20 @ISA = qw/Math::BigInt/; # child of MBI
23 package Math::BigFloat::Test;
27 @ISA = qw/Math::BigFloat/; # child of MBI
36 my $version = '1.45'; # adjust manually to match latest release
38 ###############################################################################
39 # check whether op's accept normal strings, even when inherited by subclasses
41 # do one positive and one negative test to avoid false positives by "accident"
43 my ($func,@args,$ans,$rc,$class,$try);
47 next if /^#/; # skip comments
54 @args = split(/:/,$_,99);
57 Math::BigInt Math::BigFloat Math::BigInt::Test Math::BigFloat::Test/)
59 $try = "'$args[0]'"; # quote it
60 $try = $args[0] if $args[0] =~ /'/; # already quoted
61 $try = '' if $args[0] eq ''; # undef, no argument
62 $try = "$class\->$func($try);";
64 print "# Tried: '$try'\n" if !ok ($rc, $ans);
70 $class = 'Math::BigInt';
72 # test whether use Math::BigInt qw/version/ works
73 $try = "use $class ($version.'1');";
74 $try .= ' $x = $class->new(123); $x = "$x";';
76 ok_undef ( $_ ); # should result in error!
78 # test whether fallback to calc works
79 $try = "use $class ($version,'lib','foo, bar , ');";
80 $try .= "$class\->_core_lib();";
82 ok ( $ans, "Math::BigInt::Calc");
84 # test whether constant works or not, also test for qw($version)
85 # bgcd() is present in subclass, too
86 $try = "use Math::BigInt ($version,'bgcd',':constant');";
87 $try .= ' $x = 2**150; bgcd($x); $x = "$x";';
89 ok ( $ans, "1427247692705959881058285969449495136382746624");
91 # test wether Math::BigInt::Scalar via use works (w/ dff. spellings of calc)
92 $try = "use $class ($version,'lib','Scalar');";
93 $try .= ' $x = 2**10; $x = "$x";';
94 $ans = eval $try; ok ( $ans, "1024");
95 $try = "use $class ($version,'LiB','$class\::Scalar');";
96 $try .= ' $x = 2**10; $x = "$x";';
97 $ans = eval $try; ok ( $ans, "1024");
99 # test wether calc => undef (array element not existing) works
100 # no longer supported
101 #$try = "use $class ($version,'LIB');";
102 #$try = "require $class; $class\::import($version,'CALC');";
103 #$try .= " \$x = $class\->new(2)**10; \$x = ".'"$x";';
105 #$ans = eval $try; ok ( $ans, 1024);
109 ###############################################################################
110 # Perl 5.005 does not like ok ($x,undef)
116 ok (1,1) and return if !defined $x;