2 # Before `make install' is performed this script should be runnable with
3 # `make test'. After `make install' it should work as `perl test.pl'
5 #########################
7 use Test::More qw/no_plan/;
8 use File::Temp qw/tempfile/;
11 (my $coretests = $0) =~ s'[^/]+\.t'coretests.pm';
13 use_ok("version", 0.9902);
14 # If we made it this far, we are ok.
21 sub new { my($self,$n)=@_; bless \$n, $self }
23 # Bad subclass for SemVer failures seen with pure Perl version.pm only
24 package version::Bad2;
27 my ($class, $val) = @_;
28 die 'Invalid version string format' unless version::is_strict($val);
29 my $self = $class->SUPER::new($val);
33 my ($class, $val) = @_;
34 my $self = $class->SUPER::declare($val);
41 local $SIG{__WARN__} = sub { $warning = $_[0] };
42 # dummy up a legal module for testing RT#19017
43 my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1);
44 (my $package = basename($filename)) =~ s/\.pm$//;
46 # This is an empty subclass
55 delete $main::INC{'$package'};
56 undef &qv; undef *::qv; # avoid 'used once' warning
57 undef &declare; undef *::declare; # avoid 'used once' warning
60 diag "Tests with empty derived class" unless $ENV{PERL_CORE};
62 use_ok($package, 0.001);
63 my $testobj = $package->new(1.002_003);
64 isa_ok( $testobj, $package );
65 ok( $testobj->numify == 1.002003, "Numified correctly" );
66 ok( $testobj->stringify eq "1.002003", "Stringified correctly" );
67 ok( $testobj->normal eq "v1.2.3", "Normalified correctly" );
69 my $verobj = version::->new("1.2.4");
70 ok( $verobj > $testobj, "Comparison vs parent class" );
72 BaseTests($package, "new", "qv");
74 use_ok($package, 0.001, "declare");
75 BaseTests($package, "new", "declare");
77 use_ok($package, 0.001);
78 BaseTests($package, "parse", "qv");
80 use_ok($package, 0.001, "declare");
81 BaseTests($package, "parse", "declare");
83 diag "tests with bad subclass" unless $ENV{PERL_CORE};
84 $testobj = version::Bad->new(1.002_003);
85 isa_ok( $testobj, "version::Bad" );
86 eval { my $string = $testobj->numify };
87 like($@, qr/Invalid version object/,
88 "Bad subclass numify");
89 eval { my $string = $testobj->normal };
90 like($@, qr/Invalid version object/,
91 "Bad subclass normal");
92 eval { my $string = $testobj->stringify };
93 like($@, qr/Invalid version object/,
94 "Bad subclass stringify");
95 eval { my $test = ($testobj > 1.0) };
96 like($@, qr/Invalid version object/,
99 # Bad subclassing for SemVer with pure Perl version.pm only
100 eval { my $test = version::Bad2->new("01.1.2") };
101 like($@, qr/Invalid version string format/,
102 "Correctly found invalid version");
104 eval { my $test = version::Bad2->declare("01.1.2") };
105 unlike($@, qr/Invalid version string format/,
106 "Correctly ignored invalid version");