diff options
Diffstat (limited to 't')
-rw-r--r-- | t/Utils.pm | 39 | ||||
-rw-r--r-- | t/feature.t | 87 | ||||
-rw-r--r-- | t/from_prereqs.t | 36 | ||||
-rw-r--r-- | t/merge.t | 65 | ||||
-rw-r--r-- | t/mirror.t | 38 | ||||
-rw-r--r-- | t/parse.t | 74 | ||||
-rw-r--r-- | t/release-pod-syntax.t | 14 | ||||
-rw-r--r-- | t/requirement.t | 81 |
8 files changed, 434 insertions, 0 deletions
diff --git a/t/Utils.pm b/t/Utils.pm new file mode 100644 index 0000000..f59983c --- /dev/null +++ b/t/Utils.pm @@ -0,0 +1,39 @@ +package t::Utils; +use base qw(Exporter); + +our @EXPORT = qw(write_cpanfile write_files); + +sub write_cpanfile { + write_files('cpanfile' => $_[0]); +} + +sub write_files { + my %files = @_; + + my $dir = "t/sample-" . rand(100000); + mkdir $dir; + chdir $dir; + + for my $file (keys %files) { + open my $fh, ">", $file or die $!; + print $fh $files{$file}; + } + + return Remover->new($dir, [ keys %files ]); +} + +package + Remover; +sub new { + bless { dir => $_[1], files => $_[2] }, $_[0]; +} + +sub DESTROY { + my $self = shift; + for my $file (@{$self->{files}}) { + unlink $file; + } + chdir "../.."; + rmdir $self->{dir}; +} + diff --git a/t/feature.t b/t/feature.t new file mode 100644 index 0000000..2600b77 --- /dev/null +++ b/t/feature.t @@ -0,0 +1,87 @@ +use strict; +use Module::CPANfile; +use Test::More; +use t::Utils; + +{ + my $r = write_cpanfile(<<FILE); +on test => sub { + requires 'Test::More', '0.90'; +}; + +feature 'sqlite' => sub { + on runtime => sub { requires 'DBD::SQLite' }, +}; +FILE + my $cpanfile = Module::CPANfile->load; + my @features = $cpanfile->features; + is $features[0]->identifier, 'sqlite'; + is $features[0]->description, 'sqlite'; +} + +{ + my $r = write_cpanfile(<<FILE); +on test => sub { + requires 'Test::More', '0.90'; +}; + +feature 'sqlite', 'SQLite support' => sub { + on runtime => sub { requires 'DBD::SQLite' }, +}; +FILE + my $cpanfile = Module::CPANfile->load; + + my @features = $cpanfile->features; + is @features, 1; + ok $features[0]->isa('CPAN::Meta::Feature'); + is $features[0]->identifier, 'sqlite'; + is $features[0]->description, 'SQLite support'; + ok $features[0]->prereqs; + + is_deeply $features[0]->prereqs->as_string_hash, { runtime => { requires => { 'DBD::SQLite' => '0' } } }; + + { + my $prereqs = $cpanfile->prereqs; + is_deeply $prereqs->as_string_hash, { + test => { requires => { 'Test::More' => '0.90' } }, + }; + } + + { + my $prereqs = $cpanfile->effective_prereqs; + is_deeply $prereqs->as_string_hash, { + test => { requires => { 'Test::More' => '0.90' } }, + }; + } + + { + my $prereqs = $cpanfile->prereqs_with('sqlite'); + is_deeply $prereqs->as_string_hash, { + test => { requires => { 'Test::More' => '0.90' } }, + runtime => { requires => { 'DBD::SQLite' => '0' } }, + }; + } + + { + my $prereqs = $cpanfile->effective_prereqs(['sqlite']); + is_deeply $prereqs->as_string_hash, { + test => { requires => { 'Test::More' => '0.90' } }, + runtime => { requires => { 'DBD::SQLite' => '0' } }, + }; + } + + { + eval { my $prereqs = $cpanfile->prereqs_with('foobar') }; + like $@, qr/Unknown feature 'foobar'/; + } + + { + # no features, it's ok + eval { my $prereqs = $cpanfile->prereqs_with() }; + ok !$@, $@; + } + + like $cpanfile->to_string, qr/feature/; +} + +done_testing; diff --git a/t/from_prereqs.t b/t/from_prereqs.t new file mode 100644 index 0000000..eaaf984 --- /dev/null +++ b/t/from_prereqs.t @@ -0,0 +1,36 @@ +use strict; +use Test::More; + +use Module::CPANfile; +use t::Utils; + +{ + my $r = write_cpanfile(<<FILE); +requires 'perl', '5.008001'; +requires 'DBI'; +requires 'Plack', '1.0001'; +test_requires 'Test::More', '0.90, != 0.91'; +FILE + + my $prereqs = Module::CPANfile->load->prereqs; + my $file = Module::CPANfile->from_prereqs($prereqs->as_string_hash); + + is_deeply $file->prereq_specs, $prereqs->as_string_hash; + + is $file->to_string, <<FILE; +requires 'DBI'; +requires 'Plack', '1.0001'; +requires 'perl', '5.008001'; + +on test => sub { + requires 'Test::More', '>= 0.90, != 0.91'; +}; +FILE + + $file->save('cpanfile'); + + my $content = do { local $/; open my $in, 'cpanfile'; <$in> }; + is $content, $file->to_string; +} + +done_testing; diff --git a/t/merge.t b/t/merge.t new file mode 100644 index 0000000..f082cbd --- /dev/null +++ b/t/merge.t @@ -0,0 +1,65 @@ +use strict; +use Module::CPANfile; +use Test::More; +use t::Utils; + +{ + my $r = write_files(cpanfile => <<CPANFILE, 'META.json' => <<META); +requires 'Plack', '0.9970'; + +on 'test' => sub { + requires 'Test::More', '0.90'; +}; + +on 'develop' => sub { + requires 'Catalyst::Runtime', '> 5.8000, < 5.9'; +}; +CPANFILE +{ + "abstract" : "A format for describing CPAN dependencies of Perl applications", + "author" : [ + "Tatsuhiko Miyagawa" + ], + "dynamic_config" : 0, + "generated_by" : "ExtUtils::MakeMaker version 6.64, CPAN::Meta::Converter version 2.120921", + "meta-spec" : { + "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", + "version" : "2" + }, + "name" : "Module-CPANfile", + "prereqs" : { + "build" : { + "requires" : { + "ExtUtils::MakeMaker" : "0" + } + }, + "configure" : { + "requires" : { + "ExtUtils::MakeMaker" : "6.31" + } + }, + "runtime" : { + "requires" : { + "perl" : "5.008001", + "Plack" : "0.9000" + } + } + }, + "version" : "0.9007" +} +META + + my $file = Module::CPANfile->load; + $file->merge_meta('META.json'); + + my $meta = CPAN::Meta->load_file('META.json'); + is_deeply $meta->prereqs, { + build => { requires => { 'ExtUtils::MakeMaker' => 0 } }, + configure => { requires => { 'ExtUtils::MakeMaker' => '6.31' } }, + runtime => { requires => { 'perl' => '5.008001', 'Plack' => '0.9970' } }, + develop => { requires => { 'Catalyst::Runtime' => '> 5.8000, < 5.9' } }, + test => { requires => { 'Test::More' => '0.90' } }, + }; +} + +done_testing; diff --git a/t/mirror.t b/t/mirror.t new file mode 100644 index 0000000..0aa3a54 --- /dev/null +++ b/t/mirror.t @@ -0,0 +1,38 @@ +use strict; +use Module::CPANfile; +use Test::More; +use t::Utils; + +{ + my $r = write_cpanfile(<<FILE); +mirror 'http://www.cpan.org'; +mirror 'http://backpan.cpan.org'; + +requires 'DBI'; +requires 'Plack', '0.9970'; + +on 'test' => sub { + requires 'Test::More'; +}; +FILE + + my $file = Module::CPANfile->load; + + my $prereq = $file->prereq; + is_deeply $prereq->as_string_hash, { + test => { + requires => { 'Test::More' => 0 }, + }, + runtime => { + requires => { 'Plack' => '0.9970', 'DBI' => 0 }, + }, + }; + + my $mirrors = $file->mirrors; + is_deeply $mirrors, [ 'http://www.cpan.org', 'http://backpan.cpan.org' ]; + + like $file->to_string, qr{mirror 'http://www.cpan.org';}; + like $file->to_string, qr{mirror 'http://backpan.cpan.org';}; +} + +done_testing; diff --git a/t/parse.t b/t/parse.t new file mode 100644 index 0000000..6948d26 --- /dev/null +++ b/t/parse.t @@ -0,0 +1,74 @@ +use strict; +use Module::CPANfile; +use Test::More; +use POSIX qw(locale_h); +use t::Utils; + +{ + # Use the traditional UNIX system locale to check the error message string. + my $old_locale = setlocale(LC_ALL); + setlocale(LC_ALL, 'C'); + eval { + my $file = Module::CPANfile->load('foo'); + }; + like $@, qr/No such file/; + setlocale(LC_ALL, $old_locale); +} + +{ + my $r = write_cpanfile(<<FILE); +foo(); +FILE + eval { Module::CPANfile->load }; + like $@, qr/cpanfile line 1/; +} + +{ + my $r = write_cpanfile("# %4N bug"); + eval { Module::CPANfile->load }; + is $@, ''; +} + +{ + my $r = write_cpanfile(<<FILE); +configure_requires 'ExtUtils::MakeMaker', 5.5; + +requires 'DBI'; +requires 'Plack', '0.9970'; +conflicts 'Moose', '< 0.8'; + +on 'test' => sub { + requires 'Test::More'; +}; + +on 'develop' => sub { + requires 'Catalyst::Runtime', '> 5.8000, < 5.9'; + recommends 'Catalyst::Plugin::Foo'; +}; + +test_requires 'Test::Warn', 0.1; +author_requires 'Module::Install', 0.99; +FILE + + my $file = Module::CPANfile->load; + my $prereq = $file->prereq; + + is_deeply $prereq->as_string_hash, { + configure => { + requires => { 'ExtUtils::MakeMaker' => '5.5' }, + }, + test => { + requires => { 'Test::More' => 0, 'Test::Warn' => '0.1' }, + }, + runtime => { + requires => { 'Plack' => '0.9970', 'DBI' => 0 }, + conflicts => { 'Moose' => '< 0.8' }, + }, + develop => { + requires => { 'Catalyst::Runtime' => '> 5.8000, < 5.9', 'Module::Install' => '0.99' }, + recommends => { 'Catalyst::Plugin::Foo' => 0 }, + } + }; +} + +done_testing; diff --git a/t/release-pod-syntax.t b/t/release-pod-syntax.t new file mode 100644 index 0000000..cdd6a6c --- /dev/null +++ b/t/release-pod-syntax.t @@ -0,0 +1,14 @@ +#!perl + +BEGIN { + unless ($ENV{RELEASE_TESTING}) { + require Test::More; + Test::More::plan(skip_all => 'these tests are for release candidate testing'); + } +} + +# This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. +use Test::More; +use Test::Pod 1.41; + +all_pod_files_ok(); diff --git a/t/requirement.t b/t/requirement.t new file mode 100644 index 0000000..32fd2ee --- /dev/null +++ b/t/requirement.t @@ -0,0 +1,81 @@ +use strict; +use Module::CPANfile; +use Test::More; +use t::Utils; + +subtest 'full set' => sub { + my $r = write_cpanfile(<<FILE); +requires 'Plack', '0.9970', + git => 'git://github.com/plack/Plack.git', ref => '0.9970'; +FILE + + my $file = Module::CPANfile->load; + is_deeply $file->prereq_specs, { + runtime => { + requires => { 'Plack' => '0.9970' }, + }, + }; + + my $req = $file->prereqs->requirements_for(runtime => 'requires'); + is $req->requirements_for_module('Plack'), '0.9970'; + + is_deeply $file->options_for_module('Plack'), { + git => 'git://github.com/plack/Plack.git', + ref => '0.9970', + }; +}; + +subtest 'drop version' => sub { + my $r = write_cpanfile(<<FILE); +requires 'Plack', # drop version + git => 'git://github.com/plack/Plack.git', ref => '0.9970'; +FILE + + my $file = Module::CPANfile->load; + is_deeply $file->prereq_specs, { + runtime => { + requires => { 'Plack' => 0 }, + }, + }; + + is_deeply $file->options_for_module('Plack'), { + git => 'git://github.com/plack/Plack.git', + ref => '0.9970', + }; +}; + +subtest 'no ref' => sub { + my $r = write_cpanfile(<<FILE); +requires 'Plack', '0.9970', git => 'git://github.com/plack/Plack.git'; +FILE + + my $file = Module::CPANfile->load; + is_deeply $file->prereq_specs, { + runtime => { + requires => { 'Plack' => '0.9970' }, + }, + }; + + is_deeply $file->options_for_module('Plack'), { + git => 'git://github.com/plack/Plack.git', + }; +}; + +subtest 'name and git' => sub { + my $r = write_cpanfile(<<FILE); +requires 'Plack', git => 'git://github.com/plack/Plack.git'; +FILE + + my $file = Module::CPANfile->load; + is_deeply $file->prereq_specs, { + runtime => { + requires => { 'Plack' => 0 }, + }, + }; + + is_deeply $file->options_for_module('Plack'), { + git => 'git://github.com/plack/Plack.git', + }; +}; + +done_testing; |