1# -*- mode: perl; -*-
2
3use strict;
4use warnings;
5
6# Test 2 levels of upgrade classes. This used to cause a segv.
7
8use Test::More tests => 9;
9
10use Math::BigInt upgrade => 'Math::BigFloat';
11use Math::BigFloat upgrade => 'Math::BigMouse';
12
13no warnings 'once';
14@Math::BigMouse::ISA = 'Math::BigFloat';
15sub Math::BigMouse::bsqrt {};
16
17() = sqrt Math::BigInt->new(2);
18pass('sqrt on a big int does not segv if there are 2 upgrade levels');
19
20# Math::BigRat inherits from Math::BigFloat, which inherits from Math::BigInt.
21# Typically, methods call the upgrade version if upgrading is defined and the
22# argument is an unknown type. This will call infinite recursion for methods
23# that are not implemented in the upgrade class.
24
25use Math::BigRat;
26
27Math::BigFloat -> upgrade("Math::BigRat");
28Math::BigFloat -> downgrade(undef);
29
30Math::BigRat   -> upgrade(undef);
31Math::BigRat   -> downgrade(undef);
32
33# Input is a scalar.
34
35note 'Math::BigRat -> babs("2");';
36()  = Math::BigRat -> babs("2");
37pass(qq|no 'Deep recursion on subroutine ...'|);
38
39note 'Math::BigRat -> bsgn("2");';
40()  = Math::BigRat -> bsgn("2");
41pass(qq|no 'Deep recursion on subroutine ...'|);
42
43# Input is a Math::BigInt.
44
45note 'Math::BigRat -> babs(Math::BigInt -> new("2"));';
46()  = Math::BigRat -> babs(Math::BigInt -> new("2"));
47pass(qq|no 'Deep recursion on subroutine ...'|);
48
49note 'Math::BigRat -> bsgn(Math::BigInt -> new("2"));';
50()  = Math::BigRat -> bsgn(Math::BigInt -> new("2"));
51pass(qq|no 'Deep recursion on subroutine ...'|);
52
53# Input is a Math::BigFloat.
54
55note 'Math::BigRat -> babs(Math::BigFloat -> new("2"));';
56()  = Math::BigRat -> babs(Math::BigFloat -> new("2"));
57pass(qq|no 'Deep recursion on subroutine ...'|);
58
59note 'Math::BigRat -> bsgn(Math::BigFloat -> new("2"));';
60()  = Math::BigRat -> bsgn(Math::BigFloat -> new("2"));
61pass(qq|no 'Deep recursion on subroutine ...'|);
62
63# Input is a Math::BigRat.
64
65note 'Math::BigRat -> babs(Math::BigRat -> new("2"));';
66()  = Math::BigRat -> babs(Math::BigRat -> new("2"));
67pass(qq|no 'Deep recursion on subroutine ...'|);
68
69note 'Math::BigRat -> bsgn(Math::BigRat -> new("2"));';
70()  = Math::BigRat -> bsgn(Math::BigRat -> new("2"));
71pass(qq|no 'Deep recursion on subroutine ...'|);
72