xref: /openbsd/gnu/usr.bin/perl/cpan/parent/t/parent.t (revision 274d7c50)
1#!/usr/bin/perl -w
2
3BEGIN {
4   if( $ENV{PERL_CORE} ) {
5        chdir 't' if -d 't';
6        chdir '../lib/parent';
7        @INC = '..';
8    }
9}
10
11use strict;
12use Test::More tests => 9;
13
14use_ok('parent');
15
16
17package No::Version;
18
19use vars qw($Foo);
20sub VERSION { 42 }
21
22package Test::Version;
23
24use parent -norequire, 'No::Version';
25::is( $No::Version::VERSION, undef,          '$VERSION gets left alone' );
26
27# Test Inverse: parent.pm should not clobber existing $VERSION
28package Has::Version;
29
30BEGIN { $Has::Version::VERSION = '42' };
31
32package Test::Version2;
33
34use parent -norequire, 'Has::Version';
35::is( $Has::Version::VERSION, 42 );
36
37package main;
38
39my $eval1 = q{
40  {
41    package Eval1;
42    {
43      package Eval2;
44      use parent -norequire, 'Eval1';
45      $Eval2::VERSION = "1.02";
46    }
47    $Eval1::VERSION = "1.01";
48  }
49};
50
51eval $eval1;
52is( $@, '' );
53
54# String comparisons, just to be safe from floating-point errors
55is( $Eval1::VERSION, '1.01' );
56
57is( $Eval2::VERSION, '1.02' );
58
59my $expected= q{/^Can't locate reallyReAlLyNotexists.pm in \@INC \(\@INC contains:/};
60$expected= q{/^Can't locate reallyReAlLyNotexists.pm in \@INC \(you may need to install the reallyReAlLyNotexists module\) \(\@INC contains:/}
61    if 5.017005 <= $];
62
63eval q{use parent 'reallyReAlLyNotexists'};
64like( $@, $expected, 'baseclass that does not exist');
65
66eval q{use parent 'reallyReAlLyNotexists'};
67like( $@, $expected, '  still failing on 2nd load');
68
69{
70    BEGIN { $Has::Version_0::VERSION = 0 }
71
72    package Test::Version3;
73
74    use parent -norequire, 'Has::Version_0';
75    ::is( $Has::Version_0::VERSION, 0, '$VERSION==0 preserved' );
76}
77
78