This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #24942] fields::inherit doesn't bless derived
[perl5.git] / lib / base / t / base.t
CommitLineData
864f8ab4
JH
1#!/usr/bin/perl -w
2
3use strict;
4use Test::More tests => 10;
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');
58
59BEGIN { $Has::Version_0::VERSION = 0 }
60
61package Test::Version3;
62
63use base qw(Has::Version_0);
64::is( $Has::Version_0::VERSION, 0, '$VERSION==0 preserved' );
65
66
67package Test::SIGDIE;
68
69{
70 local $SIG{__DIE__} = sub {
71 ::fail('sigdie not caught, this test should not run')
72 };
73 eval {
74 'base'->import(qw(Huh::Boo));
75 };
76
77 ::like($@, qr/^Base class package "Huh::Boo" is empty/,
78 'Base class empty error message');
79
80}