summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/00-load.t7
-rw-r--r--t/000-report-versions-tiny.t86
-rw-r--r--t/app.t132
-rw-r--r--t/config-file.t108
-rw-r--r--t/filter.t157
5 files changed, 490 insertions, 0 deletions
diff --git a/t/00-load.t b/t/00-load.t
new file mode 100644
index 0000000..8a560de
--- /dev/null
+++ b/t/00-load.t
@@ -0,0 +1,7 @@
+#!perl
+
+use Test::More tests => 1;
+
+use_ok( 'CPAN::Mini' );
+
+diag( "Testing CPAN::Mini $CPAN::Mini::VERSION" );
diff --git a/t/000-report-versions-tiny.t b/t/000-report-versions-tiny.t
new file mode 100644
index 0000000..e25334d
--- /dev/null
+++ b/t/000-report-versions-tiny.t
@@ -0,0 +1,86 @@
+use strict;
+use warnings;
+use Test::More 0.88;
+# This is a relatively nice way to avoid Test::NoWarnings breaking our
+# expectations by adding extra tests, without using no_plan. It also helps
+# avoid any other test module that feels introducing random tests, or even
+# test plans, is a nice idea.
+our $success = 0;
+END { $success && done_testing; }
+
+# List our own version used to generate this
+my $v = "\nGenerated by Dist::Zilla::Plugin::ReportVersions::Tiny v1.10\n";
+
+eval { # no excuses!
+ # report our Perl details
+ my $want = '5.006';
+ $v .= "perl: $] (wanted $want) on $^O from $^X\n\n";
+};
+defined($@) and diag("$@");
+
+# Now, our module version dependencies:
+sub pmver {
+ my ($module, $wanted) = @_;
+ $wanted = " (want $wanted)";
+ my $pmver;
+ eval "require $module;";
+ if ($@) {
+ if ($@ =~ m/Can't locate .* in \@INC/) {
+ $pmver = 'module not found.';
+ } else {
+ diag("${module}: $@");
+ $pmver = 'died during require.';
+ }
+ } else {
+ my $version;
+ eval { $version = $module->VERSION; };
+ if ($@) {
+ diag("${module}: $@");
+ $pmver = 'died during VERSION check.';
+ } elsif (defined $version) {
+ $pmver = "$version";
+ } else {
+ $pmver = '<undef>';
+ }
+ }
+
+ # So, we should be good, right?
+ return sprintf('%-45s => %-10s%-15s%s', $module, $pmver, $wanted, "\n");
+}
+
+eval { $v .= pmver('Carp','any version') };
+eval { $v .= pmver('Compress::Zlib','1.20') };
+eval { $v .= pmver('ExtUtils::MakeMaker','any version') };
+eval { $v .= pmver('File::Basename','any version') };
+eval { $v .= pmver('File::Copy','any version') };
+eval { $v .= pmver('File::Find','any version') };
+eval { $v .= pmver('File::HomeDir','0.57') };
+eval { $v .= pmver('File::Path','2.04') };
+eval { $v .= pmver('File::Spec','any version') };
+eval { $v .= pmver('File::Temp','any version') };
+eval { $v .= pmver('Getopt::Long','any version') };
+eval { $v .= pmver('LWP::UserAgent','5') };
+eval { $v .= pmver('Pod::Usage','1.00') };
+eval { $v .= pmver('Test::More','0.96') };
+eval { $v .= pmver('URI','1') };
+eval { $v .= pmver('strict','any version') };
+eval { $v .= pmver('warnings','any version') };
+
+
+# All done.
+$v .= <<'EOT';
+
+Thanks for using my code. I hope it works for you.
+If not, please try and include this output in the bug report.
+That will help me reproduce the issue and solve your problem.
+
+EOT
+
+diag($v);
+ok(1, "we really didn't test anything, just reporting data");
+$success = 1;
+
+# Work around another nasty module on CPAN. :/
+no warnings 'once';
+$Template::Test::NO_FLUSH = 1;
+exit 0;
diff --git a/t/app.t b/t/app.t
new file mode 100644
index 0000000..8b278ac
--- /dev/null
+++ b/t/app.t
@@ -0,0 +1,132 @@
+use strict;
+use warnings;
+use Test::More;
+
+use CPAN::Mini::App;
+use File::Spec;
+use File::Temp qw(tempdir);
+
+my $TARGET = tempdir(CLEANUP => 1);
+my @LR_ARGS = (qw(--offline -r http://example.tld/cpan -l), $TARGET);
+
+delete $ENV{CPAN_MINI_CONFIG};
+
+{
+ no warnings 'redefine';
+ *File::HomeDir::my_home = sub { $ENV{HOME} };
+}
+
+sub config_dir {
+ my ($config) = @_;
+
+ my $tempdir = tempdir(CLEANUP => 1);
+
+ return $tempdir unless defined $config;
+
+ my $filename = File::Spec->catfile($tempdir, '.minicpanrc');
+ open my $config_fh, '>', $filename or die "can't write to $filename: $!";
+
+ for my $key (keys %$config) {
+ print {$config_fh} "$key: $config->{$key}\n";
+ }
+
+ close $config_fh or die "error closing $filename: $!";
+
+ return $tempdir;
+}
+
+subtest "defaults" => sub {
+ local $ENV{HOME} = config_dir;
+ local @ARGV = @LR_ARGS;
+
+ my $minicpan = CPAN::Mini::App->initialize_minicpan;
+ isa_ok($minicpan, 'CPAN::Mini');
+
+ is($minicpan->log_level, 'info', "default log level is info");
+};
+
+subtest "--debug" => sub {
+ local $ENV{HOME} = config_dir;
+ local @ARGV = (qw(--debug), @LR_ARGS);
+
+ my $minicpan = CPAN::Mini::App->initialize_minicpan;
+ isa_ok($minicpan, 'CPAN::Mini');
+
+ is($minicpan->log_level, 'debug', "--debug to get log level debug");
+};
+
+subtest "config: log_level" => sub {
+ local $ENV{HOME} = config_dir({ log_level => 'debug' });
+ local @ARGV = @LR_ARGS;
+
+ my $minicpan = CPAN::Mini::App->initialize_minicpan;
+ isa_ok($minicpan, 'CPAN::Mini');
+
+ is($minicpan->log_level, 'debug', "debug from config file");
+};
+
+subtest "--debug overrides config" => sub {
+ local $ENV{HOME} = config_dir({ log_level => 'fatal' });
+ local @ARGV = (qw(--debug), @LR_ARGS);
+
+ my $minicpan = CPAN::Mini::App->initialize_minicpan;
+ isa_ok($minicpan, 'CPAN::Mini');
+
+ is($minicpan->log_level, 'debug', "--debug overrides config file");
+};
+
+subtest "--log-level" => sub {
+ local $ENV{HOME} = config_dir;
+ local @ARGV = (qw(--log-level debug), @LR_ARGS);
+
+ my $minicpan = CPAN::Mini::App->initialize_minicpan;
+ isa_ok($minicpan, 'CPAN::Mini');
+
+ is($minicpan->log_level, 'debug', "--debug to get log level debug");
+};
+
+subtest "only one log-level-like switch allowed" => sub {
+ for my $combo (
+ [ qw(--debug -q) ],
+ [ qw(--debug --log-level debug) ],
+ ) {
+ local $ENV{HOME} = config_dir;
+ local @ARGV = (@$combo, @LR_ARGS);
+
+ my $minicpan = eval { CPAN::Mini::App->initialize_minicpan };
+ like($@, qr/can't mix/, "can't use @$combo together");
+ };
+};
+
+for my $switch (qw(-qq --qq)) {
+ subtest "extra quiet with $switch" => sub {
+ local $ENV{HOME} = config_dir;
+ local @ARGV = ($switch, @LR_ARGS);
+
+ my $minicpan = CPAN::Mini::App->initialize_minicpan;
+ isa_ok($minicpan, 'CPAN::Mini');
+
+ is($minicpan->log_level, 'fatal', "$switch gets us log level 'fatal'");
+ };
+}
+
+
+subtest "-perl switch" => sub {
+
+ local $ENV{HOME} = config_dir;
+ local @ARGV = @LR_ARGS;
+
+ my $minicpan = CPAN::Mini::App->initialize_minicpan;
+ isa_ok($minicpan, 'CPAN::Mini');
+ is($minicpan->{skip_perl}, 1, "'skip_perl' is true without -perl switch");
+
+
+ local @ARGV = ('-perl', @LR_ARGS);
+ $minicpan = CPAN::Mini::App->initialize_minicpan;
+ isa_ok($minicpan, 'CPAN::Mini');
+ is($minicpan->{skip_perl}, q{}, "'skip_perl' is false with -perl switch");
+};
+
+done_testing;
+
+1;
diff --git a/t/config-file.t b/t/config-file.t
new file mode 100644
index 0000000..4d476a6
--- /dev/null
+++ b/t/config-file.t
@@ -0,0 +1,108 @@
+#!perl
+
+use warnings;
+use strict;
+
+use Test::More tests => 18;
+
+use File::Basename;
+
+my $class = 'CPAN::Mini';
+
+use_ok($class);
+can_ok($class, 'config_file');
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# command line option case
+{
+ my $filename = 'Changes';
+ ok(-e $filename, "file name [$filename] exists");
+
+ local $ENV{CPAN_MINI_CONFIG} = 'Buster';
+ my $options = { config_file => $filename, };
+
+ is($class->config_file($options),
+ $filename, 'selects config file name from command line');
+}
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# environment variable case
+{
+ my $filename = $0;
+ ok(-e $filename, "file name [$filename] exists");
+
+ local $ENV{CPAN_MINI_CONFIG} = $filename;
+
+ is($class->config_file, $filename,
+ 'selects config file name from environment with no args');
+ is($class->config_file({}),
+ $filename, 'selects config file name from environment with empty hash ref');
+ is($class->config_file('trash'),
+ $filename, 'selects config file name from environment with non-ref arg');
+}
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# default case
+# this is the case where there is a ~/.minicpanrc
+{
+
+ my $filename = 'Changes';
+ ok(-e $filename, "file name [$filename] exists");
+
+ {
+ no strict 'refs';
+ no warnings 'redefine';
+
+ *{"${class}::__homedir_configfile"} = sub { $filename };
+ is($class->__homedir_configfile,
+ $filename, "__homedir_configfile returns mocked name");
+ }
+
+ local $ENV{CPAN_MINI_CONFIG} = undef;
+
+ is($class->config_file, $filename, 'selects default config file name');
+}
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# last ditch case
+# this is the case wehre there is no ~/.minicpanrc
+{
+ local $ENV{CPAN_MINI_CONFIG} = undef;
+ my $is_there_filename = 'Changes';
+ ok(-e $is_there_filename, "file name [$is_there_filename] does exist");
+
+ {
+ no strict 'refs';
+ no warnings 'redefine';
+
+ *{"${class}::__homedir_configfile"} = sub { undef };
+ is($class->__homedir_configfile,
+ undef, "__homedir_configfile returns mocked name");
+ *{"${class}::__default_configfile"} = sub { $is_there_filename };
+ is($class->__default_configfile,
+ $is_there_filename, "__default_configfile returns mocked name");
+ }
+
+ is($class->config_file, $is_there_filename,
+ 'selects default config file name');
+}
+
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# everything failed case
+{
+ local $ENV{CPAN_MINI_CONFIG} = undef;
+
+ {
+ no strict 'refs';
+ no warnings 'redefine';
+
+ *{"${class}::__homedir_configfile"} = sub { undef };
+ is($class->__homedir_configfile,
+ undef, "__homedir_configfile returns mocked name");
+ *{"${class}::__default_configfile"} = sub { undef };
+ is($class->__default_configfile,
+ undef, "__default_configfile returns mocked name");
+ }
+
+ is($class->config_file, undef, 'returns undef when no config file is found');
+}
diff --git a/t/filter.t b/t/filter.t
new file mode 100644
index 0000000..46333fa
--- /dev/null
+++ b/t/filter.t
@@ -0,0 +1,157 @@
+#!perl
+
+use warnings;
+use strict;
+
+use Test::More tests => 19;
+
+use CPAN::Mini;
+
+my $self = {
+ changes_made => 1,
+ force => 1,
+};
+
+bless $self, "CPAN::Mini";
+################################################
+# skip_perl
+
+$self->{skip_perl} = 1;
+
+ok($self->_filter_module({
+ module => 'perl',
+ version => '0.01',
+ path => '/perl-0.01.tar.gz',
+}), "perl distro skip check");
+
+ok($self->_filter_module({
+ module => 'bioperl',
+ version => '0.01',
+ path => '/bioperl-0.01.tar.gz',
+}), "bioperl distro skip check");
+
+ok($self->_filter_module({
+ module => 'embperl',
+ version => '0.01',
+ path => '/embperl-0.01.tar.gz',
+}), "embperl distro skip check");
+
+ok(!$self->_filter_module({
+ module => 'notperl',
+ version => '0.01',
+ path => '/POE-0.01.tar.gz',
+}), "POE distro not-skip check");
+
+ok($self->_filter_module({
+ module => 'ponie',
+ version => '0.01',
+ path => '/ponie-0.01.tar.gz',
+}), "ponie distro skip check");
+
+ok($self->_filter_module({
+ module => 'parrot',
+ version => '0.01',
+ path => '/parrot-0.01.tar.gz',
+}), "parrot distro skip check");
+
+delete $self->{skip_perl};
+
+ok(!$self->_filter_module({
+ module => 'perl',
+ version => '0.01',
+ path => '/perl-0.01.tar.gz',
+}), "perl distro no-skip check");
+
+################################################
+# path_filters
+
+$self->{path_filters} = qr/skipme/;
+
+ok($self->_filter_module({
+ module => 'skipme',
+ version => '0.01',
+ path => '/skipme-0.01.tar.gz',
+}), "path_filters skip check skipme 1");
+
+ok(!$self->_filter_module({
+ module => 'noskip',
+ version => '0.01',
+ path => '/noskip-0.01.tar.gz',
+}), "path_filters no-skip check");
+
+$self->{path_filters} = [
+ qr/skipme/,
+ qr/burnme/,
+ sub { return $_[0] =~ /subskip/ }
+];
+
+ok($self->_filter_module({
+ module => 'skipme',
+ version => '0.01',
+ path => '/skipme-0.01.tar.gz',
+}), "path_filters skip check skipme 2");
+
+ok($self->_filter_module({
+ module => 'burnme',
+ version => '0.01',
+ path => '/burnme-0.01.tar.gz',
+}), "path_filters skip check burnme");
+
+ok($self->_filter_module({
+ module => 'submod',
+ version => '0.01',
+ path => '/subskip-0.01.tar.gz',
+}), "path_filters skip check (by sub)");
+
+ok(!$self->_filter_module({
+ module => 'noskip',
+ version => '0.01',
+ path => '/noskip-0.01.tar.gz',
+}), "path_filters no-skip check");
+
+################################################
+# module_filters
+
+$self->{module_filters} = qr/skipme/;
+
+ok($self->_filter_module({
+ module => 'skipme',
+ version => '0.01',
+ path => '/skipme-0.01.tar.gz',
+}), "module_filters skip check skipme 1");
+
+ok(!$self->_filter_module({
+ module => 'noskip',
+ version => '0.01',
+ path => '/noskip-0.01.tar.gz',
+}), "module_filters no-skip check");
+
+$self->{module_filters} = [
+ qr/skipme/,
+ qr/burnme/,
+ sub { $_[0] =~ /submod/ }
+];
+
+ok($self->_filter_module({
+ module => 'skipme',
+ version => '0.01',
+ path => '/skipme-0.01.tar.gz',
+}), "module_filters skip check skipme 2");
+
+ok($self->_filter_module({
+ module => 'burnme',
+ version => '0.01',
+ path => '/burnme-0.01.tar.gz',
+}), "module_filters skip check burnme");
+
+ok($self->_filter_module({
+ module => 'submod',
+ version => '0.01',
+ path => '/subskip-0.01.tar.gz',
+}), "module_filters skip check (by sub)");
+
+ok(!$self->_filter_module({
+ module => 'noskip',
+ version => '0.01',
+ path => '/noskip-0.01.tar.gz',
+}), "module_filters no-skip check");