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 package Math::BigInt::Test;
40 @ISA = qw/Math::BigInt/; # child of MBI
43 package Math::BigFloat::Test;
47 @ISA = qw/Math::BigFloat/; # child of MBI
56 my $version = '1.46'; # adjust manually to match latest release
58 ###############################################################################
59 # check whether op's accept normal strings, even when inherited by subclasses
61 # do one positive and one negative test to avoid false positives by "accident"
63 my ($func,@args,$ans,$rc,$class,$try);
67 next if /^#/; # skip comments
74 @args = split(/:/,$_,99);
77 Math::BigInt Math::BigFloat Math::BigInt::Test Math::BigFloat::Test/)
79 $try = "'$args[0]'"; # quote it
80 $try = $args[0] if $args[0] =~ /'/; # already quoted
81 $try = '' if $args[0] eq ''; # undef, no argument
82 $try = "$class\->$func($try);";
84 print "# Tried: '$try'\n" if !ok ($rc, $ans);
90 $class = 'Math::BigInt';
92 # test whether use Math::BigInt qw/version/ works
93 $try = "use $class ($version.'1');";
94 $try .= ' $x = $class->new(123); $x = "$x";';
96 ok_undef ( $_ ); # should result in error!
98 # test whether fallback to calc works
99 $try = "use $class ($version,'lib','foo, bar , ');";
100 $try .= "$class\->config()->{lib};";
102 ok ( $ans, "Math::BigInt::Calc");
104 # test whether constant works or not, also test for qw($version)
105 # bgcd() is present in subclass, too
106 $try = "use Math::BigInt ($version,'bgcd',':constant');";
107 $try .= ' $x = 2**150; bgcd($x); $x = "$x";';
109 ok ( $ans, "1427247692705959881058285969449495136382746624");
111 # test wether Math::BigInt::Scalar via use works (w/ dff. spellings of calc)
112 $try = "use $class ($version,'lib','Scalar');";
113 $try .= ' $x = 2**10; $x = "$x";';
114 $ans = eval $try; ok ( $ans, "1024");
115 $try = "use $class ($version,'LiB','$class\::Scalar');";
116 $try .= ' $x = 2**10; $x = "$x";';
117 $ans = eval $try; ok ( $ans, "1024");
119 # test wether calc => undef (array element not existing) works
120 # no longer supported
121 #$try = "use $class ($version,'LIB');";
122 #$try = "require $class; $class\::import($version,'CALC');";
123 #$try .= " \$x = $class\->new(2)**10; \$x = ".'"$x";';
125 #$ans = eval $try; ok ( $ans, 1024);
129 ###############################################################################
130 # Perl 5.005 does not like ok ($x,undef)
136 ok (1,1) and return if !defined $x;