This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to base and fields 2.12, mostly by Michael G Schwern
[perl5.git] / lib / base / t / base.t
CommitLineData
864f8ab4
JH
1#!/usr/bin/perl -w
2
3use strict;
9e998a43 4use Test::More tests => 11;
864f8ab4
JH
5
6use_ok('base');
7
8
9package No::Version;
10
11use vars qw($Foo);
12sub VERSION { 42 }
13
14package Test::Version;
15
16use base qw(No::Version);
17::ok( $No::Version::VERSION =~ /set by base\.pm/, '$VERSION bug' );
18
19# Test Inverse of $VERSION bug base.pm should not clobber existing $VERSION
20package Has::Version;
21
22BEGIN { $Has::Version::VERSION = '42' };
23
24package Test::Version2;
25
26use base qw(Has::Version);
27::is( $Has::Version::VERSION, 42 );
28
29package main;
30
31my $eval1 = q{
32 {
33 package Eval1;
34 {
35 package Eval2;
36 use base 'Eval1';
37 $Eval2::VERSION = "1.02";
38 }
39 $Eval1::VERSION = "1.01";
40 }
41};
42
43eval $eval1;
44is( $@, '' );
45
46is( $Eval1::VERSION, 1.01 );
47
48is( $Eval2::VERSION, 1.02 );
49
50
51eval q{use base 'reallyReAlLyNotexists'};
52like( $@, qr/^Base class package "reallyReAlLyNotexists" is empty./,
53 'base with empty package');
54
55eval q{use base 'reallyReAlLyNotexists'};
56like( $@, qr/^Base class package "reallyReAlLyNotexists" is empty./,
57 ' still empty on 2nd load');
9b6f3a27
O
58{
59 my $warning;
60 local $SIG{__WARN__} = sub { $warning = shift };
61 eval q{package HomoGenous; use base 'HomoGenous';};
62 like($warning, qr/^Class 'HomoGenous' tried to inherit from itself/,
63 ' self-inheriting');
64}
864f8ab4 65
9e998a43
RGS
66{
67 BEGIN { $Has::Version_0::VERSION = 0 }
864f8ab4 68
9e998a43 69 package Test::Version3;
864f8ab4 70
9e998a43
RGS
71 use base qw(Has::Version_0);
72 ::is( $Has::Version_0::VERSION, 0, '$VERSION==0 preserved' );
73}
864f8ab4 74
864f8ab4 75
9e998a43
RGS
76{
77 package Schlozhauer;
78 use constant FIELDS => 6;
864f8ab4 79
9e998a43
RGS
80 package Basilisco;
81 eval q{ use base 'Schlozhauer' };
82 ::is( $@, '', 'Can coexist with a FIELDS constant' );
864f8ab4 83}