Skip to content

Instantly share code, notes, and snippets.

@dagolden
Created November 30, 2009 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dagolden/245765 to your computer and use it in GitHub Desktop.
Save dagolden/245765 to your computer and use it in GitHub Desktop.
use 5.011002;
use strict;
use warnings;
use Module::Build::ModuleInfo;
use Test::More;
my @cases = (
'0.23',
'1.23',
'v0.1.2',
'v1.2.3',
'v1.2.3_4',
'v01.02.03',
'v01.0002.0003',
'01.23',
'0666',
'1.23_01',
'1_000',
'v1.2_3',
'v1.1000.2345',
);
plan tests => 7 * @cases;
my $pm = "Foo.pm";
for my $c ( @cases ) {
my $version = $c;
diag "*** version '$c' ***";
my $pnv = "package Foo $version;";
my $fh = IO::File->new($pm, "w");
ok( (print {$fh} "$pnv\n1;\n"), "Writing $pm file with '$pnv'" );
close $fh;
my $info = Module::Build::ModuleInfo->new_from_file($pm);
is( $info->version, $version, "M::B::ModuleInfo finds version $version" );
eval "use Foo $version";
ok( ! $@, qq{Eval "use Foo $version" should succeed} );
is( Foo->VERSION, $version, qq{Foo->VERSION eq $version} );
# TODO: {
# local $TODO = "Eventually ->VERSION should give version objects";
# isa_ok( Foo->VERSION, 'version'); # XXX eventually
# }
my $vobj;
ok( eval { $vobj = version->new($version); 1 }, "version->new(\$version) lives" );
is( $vobj, $version, "version object equals $version" );
unlink $pm;
undef $Foo::VERSION;
delete $INC{$pm};
ok( ! -e $pm && !defined( $INC{$pm} ) && !defined( $Foo::VERSION ),
"Cleaned up $pm, \$INC{$pm} and \$Foo::VERSION"
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment