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
16 @INC = qw(../lib lib);
20 unshift @INC, '../lib';
26 unshift @INC, File::Spec->catdir(File::Spec->updir, $location);
30 unshift @INC, $location;
32 print "# INC = @INC\n";
37 package Math::BigInt::Test;
41 @ISA = qw/Math::BigInt/; # child of MBI
44 package Math::BigFloat::Test;
48 @ISA = qw/Math::BigFloat/; # child of MBI
53 use Math::BigInt try => 'Calc';
57 my $version = '1.76'; # adjust manually to match latest release
59 ###############################################################################
60 # check whether op's accept normal strings, even when inherited by subclasses
62 # do one positive and one negative test to avoid false positives by "accident"
64 my ($func,@args,$ans,$rc,$class,$try);
67 $_ =~ s/[\n\r]//g; # remove newlines
68 next if /^#/; # skip comments
75 @args = split(/:/,$_,99);
78 Math::BigInt Math::BigFloat Math::BigInt::Test Math::BigFloat::Test/)
80 $try = "'$args[0]'"; # quote it
81 $try = $args[0] if $args[0] =~ /'/; # already quoted
82 $try = '' if $args[0] eq ''; # undef, no argument
83 $try = "$class\->$func($try);";
85 print "# Tried: '$try'\n" if !ok ($rc, $ans);
91 $class = 'Math::BigInt';
93 # XXX TODO this test does not work/fail.
94 # test whether use Math::BigInt qw/version/ works
95 #$try = "use $class ($version.'1');";
96 #$try .= ' $x = $class->new(123); $x = "$x";';
98 #ok_undef ( $x ); # should result in error!
100 # test whether fallback to calc works
101 $try = "use $class ($version,'try','foo, bar , ');";
102 $try .= "$class\->config()->{lib};";
104 ok ( $ans =~ /^Math::BigInt::(Fast)?Calc\z/, 1);
106 # test whether constant works or not, also test for qw($version)
107 # bgcd() is present in subclass, too
108 $try = "use Math::BigInt ($version,'bgcd',':constant');";
109 $try .= ' $x = 2**150; bgcd($x); $x = "$x";';
111 ok ( $ans, "1427247692705959881058285969449495136382746624");
113 # test wether Math::BigInt::Scalar via use works (w/ dff. spellings of calc)
114 $try = "use $class ($version,'lib','Scalar');";
115 $try .= ' $x = 2**10; $x = "$x";';
116 $ans = eval $try; ok ( $ans, "1024");
117 $try = "use $class ($version,'lib','$class\::Scalar');";
118 $try .= ' $x = 2**10; $x = "$x";';
119 $ans = eval $try; ok ( $ans, "1024");