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";
37 for (1..$tests) { skip (1,'Not supported on older Perls'); }
42 package Math::BigInt::Test;
46 @ISA = qw/Math::BigInt/; # child of MBI
49 package Math::BigFloat::Test;
53 @ISA = qw/Math::BigFloat/; # child of MBI
62 my $version = '1.61'; # adjust manually to match latest release
64 ###############################################################################
65 # check whether op's accept normal strings, even when inherited by subclasses
67 # do one positive and one negative test to avoid false positives by "accident"
69 my ($func,@args,$ans,$rc,$class,$try);
73 next if /^#/; # skip comments
80 @args = split(/:/,$_,99);
83 Math::BigInt Math::BigFloat Math::BigInt::Test Math::BigFloat::Test/)
85 $try = "'$args[0]'"; # quote it
86 $try = $args[0] if $args[0] =~ /'/; # already quoted
87 $try = '' if $args[0] eq ''; # undef, no argument
88 $try = "$class\->$func($try);";
90 print "# Tried: '$try'\n" if !ok ($rc, $ans);
96 $class = 'Math::BigInt';
98 # test whether use Math::BigInt qw/version/ works
99 $try = "use $class ($version.'1');";
100 $try .= ' $x = $class->new(123); $x = "$x";';
102 ok_undef ( $_ ); # should result in error!
104 # test whether fallback to calc works
105 $try = "use $class ($version,'lib','foo, bar , ');";
106 $try .= "$class\->config()->{lib};";
108 ok ( $ans, "Math::BigInt::Calc");
110 # test whether constant works or not, also test for qw($version)
111 # bgcd() is present in subclass, too
112 $try = "use Math::BigInt ($version,'bgcd',':constant');";
113 $try .= ' $x = 2**150; bgcd($x); $x = "$x";';
115 ok ( $ans, "1427247692705959881058285969449495136382746624");
117 # test wether Math::BigInt::Scalar via use works (w/ dff. spellings of calc)
118 $try = "use $class ($version,'lib','Scalar');";
119 $try .= ' $x = 2**10; $x = "$x";';
120 $ans = eval $try; ok ( $ans, "1024");
121 $try = "use $class ($version,'LiB','$class\::Scalar');";
122 $try .= ' $x = 2**10; $x = "$x";';
123 $ans = eval $try; ok ( $ans, "1024");
125 # test wether calc => undef (array element not existing) works
126 # no longer supported
127 #$try = "use $class ($version,'LIB');";
128 #$try = "require $class; $class\::import($version,'CALC');";
129 #$try .= " \$x = $class\->new(2)**10; \$x = ".'"$x";';
131 #$ans = eval $try; ok ( $ans, 1024);
135 ###############################################################################
136 # Perl 5.005 does not like ok ($x,undef)
142 ok (1,1) and return if !defined $x;