3 # test calling conventions, and :constant overloading
11 # to locate the testing files
12 my $location = $0; $location =~ s/calling.t//i;
15 # testing with the core distribution
20 unshift @INC, '../lib';
26 unshift @INC, File::Spec->catdir(File::Spec->updir, $location);
30 unshift @INC, $location;
32 print "# INC = @INC\n";
36 for (1..141) { skip (1,'Not supported on older Perls'); }
41 package Math::BigInt::Test;
45 @ISA = qw/Math::BigInt/; # child of MBI
48 package Math::BigFloat::Test;
52 @ISA = qw/Math::BigFloat/; # child of MBI
61 my $version = '1.46'; # adjust manually to match latest release
63 ###############################################################################
64 # check whether op's accept normal strings, even when inherited by subclasses
66 # do one positive and one negative test to avoid false positives by "accident"
68 my ($func,@args,$ans,$rc,$class,$try);
72 next if /^#/; # skip comments
79 @args = split(/:/,$_,99);
82 Math::BigInt Math::BigFloat Math::BigInt::Test Math::BigFloat::Test/)
84 $try = "'$args[0]'"; # quote it
85 $try = $args[0] if $args[0] =~ /'/; # already quoted
86 $try = '' if $args[0] eq ''; # undef, no argument
87 $try = "$class\->$func($try);";
89 print "# Tried: '$try'\n" if !ok ($rc, $ans);
95 $class = 'Math::BigInt';
97 # test whether use Math::BigInt qw/version/ works
98 $try = "use $class ($version.'1');";
99 $try .= ' $x = $class->new(123); $x = "$x";';
101 ok_undef ( $_ ); # should result in error!
103 # test whether fallback to calc works
104 $try = "use $class ($version,'lib','foo, bar , ');";
105 $try .= "$class\->config()->{lib};";
107 ok ( $ans, "Math::BigInt::Calc");
109 # test whether constant works or not, also test for qw($version)
110 # bgcd() is present in subclass, too
111 $try = "use Math::BigInt ($version,'bgcd',':constant');";
112 $try .= ' $x = 2**150; bgcd($x); $x = "$x";';
114 ok ( $ans, "1427247692705959881058285969449495136382746624");
116 # test wether Math::BigInt::Scalar via use works (w/ dff. spellings of calc)
117 $try = "use $class ($version,'lib','Scalar');";
118 $try .= ' $x = 2**10; $x = "$x";';
119 $ans = eval $try; ok ( $ans, "1024");
120 $try = "use $class ($version,'LiB','$class\::Scalar');";
121 $try .= ' $x = 2**10; $x = "$x";';
122 $ans = eval $try; ok ( $ans, "1024");
124 # test wether calc => undef (array element not existing) works
125 # no longer supported
126 #$try = "use $class ($version,'LIB');";
127 #$try = "require $class; $class\::import($version,'CALC');";
128 #$try .= " \$x = $class\->new(2)**10; \$x = ".'"$x";';
130 #$ans = eval $try; ok ( $ans, 1024);
134 ###############################################################################
135 # Perl 5.005 does not like ok ($x,undef)
141 ok (1,1) and return if !defined $x;