File: 06_prompt_text.t

package info (click to toggle)
libcpan-reporter-perl 1.2020-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,752 kB
  • sloc: perl: 5,440; makefile: 2
file content (118 lines) | stat: -rw-r--r-- 3,228 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
111
112
113
114
115
116
117
118
use strict;
BEGIN{ if (not $] < 5.006) { require warnings; warnings->import } }

select(STDERR); $|=1;
select(STDOUT); $|=1;

use Test::More;
use lib 't/lib';
use MockCPANDist;
use Helper;
use Frontend;
use Config;

# For these tests, hide perl_patchlevel so all prompts are tested
use MockPatchlevel;

#--------------------------------------------------------------------------#
# Fixtures
#--------------------------------------------------------------------------#

my $perl = Probe::Perl->find_perl_interpreter();
$perl = qq{"$perl"};
my $make = $Config{make};

my $mock_dist = MockCPANDist->new( 
    pretty_id => "JOHNQP/Bogus-Module-1.23.tar.gz",
    prereq_pm       => {
        requires => { 'File::Spec' => 0 },
    },
    author_id       => "JOHNQP",
    author_fullname => "John Q. Public",
);

my $case = {
    label => "t-Fail",
    name => "t-Fail",
    dist => $mock_dist,
    version => 1.23,
    grade => "fail",
    phase => "test",
    command => "$make test",
    will_send => 1,
};

my %prompts = (
    edit_report => "Do you want to review or edit the test report?",
    send_report => "Do you want to send the report?",
    send_duplicates => "This report is identical to a previous one.  Send it anyway?",
);

my %phase_prompts = (
    PL =>   "Do you want to send the PL report?",
    make => "Do you want to send the make/Build report?",
    test => "Do you want to send the test report?",
);

my %phase_cmd = (
    PL => "$perl Makefile.PL",
    make => "$make",
    test => "$make test",
);

#--------------------------------------------------------------------------#
# plan
#--------------------------------------------------------------------------#

# 7
my $config_plus_dispatch = test_fake_config_plan + test_dispatch_plan;

plan tests => 2 + ( scalar keys %prompts ) + $config_plus_dispatch
    + (1 + $config_plus_dispatch) * (scalar keys %phase_prompts);

#--------------------------------------------------------------------------#
# tests
#--------------------------------------------------------------------------#

require_ok('CPAN::Reporter');
require_ok('CPAN::Reporter::History');

test_fake_config(
        edit_report => "ask/no",
        send_report => "ask/yes",
        send_duplicates => "ask/yes",
);

# create a fake result to force send_duplicates prompt
my $dummy_result = CPAN::Reporter::_init_result(
    "test", $mock_dist, "make test", "fake output", 1
);
$dummy_result->{grade} = "fail";
CPAN::Reporter::History::_record_history( $dummy_result );

# capture dispatch output
my ($stdout, $stderr) = test_dispatch( 
    $case, 
    will_send => $case->{will_send},
);

# check output for prompts
for my $p ( keys %prompts ) {
    like( $stdout, "/" . quotemeta($prompts{$p}) . "/m", "prompt for $p" );
}

# check for per-phase prompts 
for my $p ( keys %phase_prompts ) {
    test_fake_config( "send_$p\_report" => "ask/yes" );
    my $prefix = $p eq 'test' ? 't' : $p;
    $case->{name} = "$prefix-Fail";
    $case->{phase} = $p;
    $case->{command} = $phase_cmd{$p};
    ($stdout, $stderr) = test_dispatch( 
        $case, 
        will_send => $case->{will_send},
    );
    like( $stdout, "/" . $phase_prompts{$p} . "/m", 
        "prompt for send_$p\_report" );
}