Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add tests

  • Loading branch information...
commit 2647801ffb2dfbf5a2b008138cf5637ad976ebce 1 parent 3336af2
@yappo authored
View
13 t/01_simply.t
@@ -0,0 +1,13 @@
+use strict;
+use warnings;
+use lib 't/lib';
+use Test::More;
+
+eval {
+ require Module::Requires;
+ Module::Requires->import('ClassA');
+};
+is($@, '');
+is(ClassA->package, 'ClassA');
+
+done_testing;
View
40 t/02_version.t
@@ -0,0 +1,40 @@
+use strict;
+use warnings;
+use lib 't/lib';
+use Test::More;
+
+eval {
+ require Module::Requires;
+ Module::Requires->import('ClassA', '0.03');
+};
+like($@, qr/ClassA version 0.03 required--this is only version 0.02/);
+ok(ClassA->can('package'));
+
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ 'ClassA' => '0.03',
+ 'ClassB' => '0.10',
+ 'ClassC' => '0.30',
+ );
+};
+like($@, qr/ClassA version 0.03 required--this is only version 0.02\nClassB version 0.10 required--this is only version 0.08\nClassC version 0.30 required--this is only version 0.12/);
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ 'ClassC' => '0.99',
+ 'ClassA' => '0.10',
+ 'ClassB' => '0.30',
+ );
+};
+like($@, qr/ClassC version 0.99 required--this is only version 0.12\nClassA version 0.10 required--this is only version 0.02\nClassB version 0.30 required--this is only version 0.08/);
+ok(ClassB->can('package'));
+ok(ClassC->can('package'));
+
+eval {
+ require Module::Requires;
+ Module::Requires->import('ClassA', '0.02');
+};
+is($@, '');
+
+done_testing;
View
54 t/03_detail_version.t
@@ -0,0 +1,54 @@
+use strict;
+use warnings;
+use lib 't/lib';
+use Test::More;
+
+eval {
+ require Module::Requires;
+ Module::Requires->import('ClassA', [ '>' => 0.4 ]);
+};
+like($@, qr/ClassA version > 0.04 required--this is only version 0.02/);
+
+ok(ClassA->can('package'));
+
+eval {
+ require Module::Requires;
+ Module::Requires->import('ClassA', [ '<' => 0.2 ]);
+};
+like($@, qr/ClassA version < 0.02 required--this is only version 0.02/);
+
+eval {
+ require Module::Requires;
+ Module::Requires->import('ClassA', [ '<' => 0.2, '>' => 0.02 ]);
+};
+like($@, qr/ClassA version < 0.02 AND > 0.02 required--this is only version 0.02/);
+
+eval {
+ require Module::Requires;
+ Module::Requires->import('ClassA', [ '<=' => 0.1, '>=' => 0.03 ]);
+};
+like($@, qr/ClassA version <= 0.01 AND >= 0.03 required--this is only version 0.02/);
+
+eval {
+ require Module::Requires;
+ Module::Requires->import('ClassA', [ '>' => 0.1, '!=' => 0.02 ]);
+};
+like($@, qr/ClassA version > 0.01 AND != 0.02 required--this is only version 0.02/);
+
+eval {
+ require Module::Requires;
+ Module::Requires->import('ClassA', [ '>' => 0.2, '=' => 0.02 ]);
+};
+like($@, qr/ClassA version check syntax error/);
+
+eval {
+ require Module::Requires;
+ Module::Requires->import('ClassA', [ '>' => 0.2, 'y' ]);
+};
+like($@, qr/ClassA version check syntax error/);
+
+eval {
+ require Module::Requires;
+ Module::Requires->import('ClassA', [ '>' => 0.1, '!=' => 0.03 ]);
+};
+is($@, '');
View
41 t/04_autoload.t
@@ -0,0 +1,41 @@
+use strict;
+use warnings;
+use lib 't/lib';
+use Test::More;
+
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ 'ClassA' => {
+ import => [qw/ foo bar baz /],
+ }
+ );
+};
+like($@, qr/ClassA is unloaded because -autoload an option is lacking./);
+
+ok(ClassA->can('package'));
+
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ 'ClassA' => {
+ import => [qw/ foo bar baz /],
+ },
+ 'ClassC' => {
+ import => [qw/ foo bar baz /],
+ }
+ );
+};
+like($@, qr/ClassA is unloaded because -autoload an option is lacking.\nClassC is unloaded because -autoload an option is lacking./);
+
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ '-autoload',
+ 'ClassA' => {
+ import => [qw/ foo bar baz /],
+ }
+ );
+};
+is($@, '');
+is(ClassA->params, 'ClassA, foo, bar, baz');
View
53 t/05_autoload_version.t
@@ -0,0 +1,53 @@
+use strict;
+use warnings;
+use lib 't/lib';
+use Test::More;
+
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ 'ClassA' => {
+ import => [qw/ foo bar baz /],
+ version => 0.01,
+ }
+ );
+};
+like($@, qr/ClassA is unloaded because -autoload an option is lacking./);
+unlike($@, qr/version/);
+
+ok(ClassA->can('package'));
+is(ClassA->params, '');
+
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ '-autoload',
+ 'ClassA' => {
+ import => [qw/ foo bar baz /],
+ version => 0.03,
+ },
+ 'ClassB' => '0.10',
+ 'ClassC' => {
+ import => [qw/ foo bar baz /],
+ }
+ );
+};
+like($@, qr/ClassA version 0.03 required--this is only version 0.02\nClassB version 0.10 required--this is only version 0.08/);
+unlike($@, qr/ClassC/);
+
+ok(ClassB->can('package'));
+ok(ClassC->can('package'));
+is(ClassA->params, '');
+
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ '-autoload',
+ 'ClassA' => {
+ import => [qw/ foo bar baz /],
+ version => 0.02,
+ }
+ );
+};
+is($@, '');
+is(ClassA->params, 'ClassA, foo, bar, baz');
View
83 t/06_autoload_detail_version.t
@@ -0,0 +1,83 @@
+use strict;
+use warnings;
+use lib 't/lib';
+use Test::More;
+
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ 'ClassA' => {
+ version => [ '>' => 0.1, '!=' => 0.02 ],
+ },
+ );
+};
+like($@, qr/ClassA is unloaded because -autoload an option is lacking./);
+unlike($@, qr/version/);
+is(ClassA->params, '');
+
+
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ '-autoload',
+ 'ClassA' => {
+ import => [qw/ foo bar baz /],
+ version => [ '>' => 0.1, '!=' => 0.02 ],
+ },
+ );
+};
+like($@, qr/ClassA version > 0.01 AND != 0.02 required--this is only version 0.02/);
+is(ClassA->params, '');
+
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ '-autoload',
+ 'ClassA' => {
+ import => [qw/ foo bar baz /],
+ version => [ '>' => 0.1, '!=' => 0.02 ],
+ },
+ 'ClassB' => '0.10',
+ 'ClassC' => {
+ version => [ '>' => 5.8 ],
+ }
+ );
+};
+like($@, qr/ClassA version > 0.01 AND != 0.02 required--this is only version 0.02\nClassB version 0.10 required--this is only version 0.08\nClassC version > 5.8 required--this is only version 0.12/);
+is(ClassA->params, '');
+
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ '-autoload',
+ 'ClassA' => {
+ import => [qw/ foo bar baz /],
+ version => [ '>' => 0.1, '!=' => 0.02 ],
+ },
+ 'ClassB' => '0.02',
+ 'ClassC' => {
+ version => [ '>' => 5.8 ],
+ }
+ );
+};
+like($@, qr/ClassA version > 0.01 AND != 0.02 required--this is only version 0.02\nClassC version > 5.8 required--this is only version 0.12/);
+unlike($@, qr/ClassB/);
+is(ClassA->params, '');
+
+
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ '-autoload',
+ 'ClassA' => {
+ import => [qw/ foo bar baz /],
+ version => [ '>' => 0.1, '!=' => 0.06 ],
+ },
+ 'ClassB' => '0.02',
+ 'ClassC' => {
+ version => [ '>' => 0.08 ],
+ }
+ );
+};
+is($@, '');
+is(ClassA->params, 'ClassA, foo, bar, baz');
View
25 t/07_cant_locate.t
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+use lib 't/lib';
+use Test::More;
+
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ 'ClassD',
+ );
+};
+like($@, qr/Can't locate ClassD.pm/);
+ok(!ClassA->can('package'));
+
+eval {
+ require Module::Requires;
+ Module::Requires->import(
+ 'ClassD',
+ 'ClassA',
+ );
+};
+like($@, qr/Can't locate ClassD.pm/);
+ok(ClassA->can('package'));
+
+done_testing;
View
10 t/lib/ClassA.pm
@@ -0,0 +1,10 @@
+package ClassA;
+use strict;
+use warnings;
+our $VERSION = '0.02';
+
+my @params;
+sub import { @params = @_ }
+sub params { join ', ', @params }
+sub package { __PACKAGE__ }
+1;
View
6 t/lib/ClassB.pm
@@ -0,0 +1,6 @@
+package ClassB;
+use strict;
+use warnings;
+our $VERSION = '0.08';
+sub package { __PACKAGE__ }
+1;
View
6 t/lib/ClassC.pm
@@ -0,0 +1,6 @@
+package Classc;
+use strict;
+use warnings;
+our $VERSION = '0.12';
+sub package { __PACKAGE__ }
+1;
Please sign in to comment.
Something went wrong with that request. Please try again.