File: app.t

package info (click to toggle)
libcpan-mini-perl 1.111008-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 188 kB
  • sloc: perl: 717; makefile: 9
file content (110 lines) | stat: -rw-r--r-- 2,771 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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};

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'");
  };
}

done_testing;

1;