1use strict;
2BEGIN{ if (not $] < 5.006) { require warnings; warnings->import } }
3
4select(STDERR); $|=1;
5select(STDOUT); $|=1;
6
7use Test::More;
8use t::MockCPANDist;
9use t::Helper;
10use t::Frontend;
11use IO::CaptureOutput;
12use Config;
13
14# For these tests, hide perl_patchlevel so all prompts are tested
15use t::MockPatchlevel;
16
17#--------------------------------------------------------------------------#
18# Fixtures
19#--------------------------------------------------------------------------#
20
21my $perl = Probe::Perl->find_perl_interpreter();
22$perl = qq{"$perl"};
23my $make = $Config{make};
24
25my $mock_dist = t::MockCPANDist->new(
26    pretty_id => "JOHNQP/Bogus-Module-1.23.tar.gz",
27    prereq_pm       => {
28        requires => { 'File::Spec' => 0 },
29    },
30    author_id       => "JOHNQP",
31    author_fullname => "John Q. Public",
32);
33
34my $case = {
35    label => "t-Fail",
36    name => "t-Fail",
37    dist => $mock_dist,
38    version => 1.23,
39    grade => "fail",
40    phase => "test",
41    command => "$make test",
42    will_send => 1,
43};
44
45my %prompts = (
46    edit_report => "Do you want to review or edit the test report?",
47    send_report => "Do you want to send the report?",
48    send_duplicates => "This report is identical to a previous one.  Send it anyway?",
49);
50
51my %phase_prompts = (
52    PL =>   "Do you want to send the PL report?",
53    make => "Do you want to send the make/Build report?",
54    test => "Do you want to send the test report?",
55);
56
57my %phase_cmd = (
58    PL => "$perl Makefile.PL",
59    make => "$make",
60    test => "$make test",
61);
62
63#--------------------------------------------------------------------------#
64# plan
65#--------------------------------------------------------------------------#
66
67# 7
68my $config_plus_dispatch = test_fake_config_plan + test_dispatch_plan;
69
70plan tests => 2 + ( scalar keys %prompts ) + $config_plus_dispatch
71    + (1 + $config_plus_dispatch) * (scalar keys %phase_prompts);
72
73#--------------------------------------------------------------------------#
74# tests
75#--------------------------------------------------------------------------#
76
77require_ok('CPAN::Reporter');
78require_ok('CPAN::Reporter::History');
79
80test_fake_config(
81        edit_report => "ask/no",
82        send_report => "ask/yes",
83        send_duplicates => "ask/yes",
84);
85
86# create a fake result to force send_duplicates prompt
87my $dummy_result = CPAN::Reporter::_init_result(
88    "test", $mock_dist, "make test", "fake output", 1
89);
90$dummy_result->{grade} = "fail";
91CPAN::Reporter::History::_record_history( $dummy_result );
92
93# capture dispatch output
94my ($stdout, $stderr) = test_dispatch(
95    $case,
96    will_send => $case->{will_send},
97);
98
99# check output for prompts
100for my $p ( keys %prompts ) {
101    like( $stdout, "/" . quotemeta($prompts{$p}) . "/m", "prompt for $p" );
102}
103
104# check for per-phase prompts
105for my $p ( keys %phase_prompts ) {
106    test_fake_config( "send_$p\_report" => "ask/yes" );
107    my $prefix = $p eq 'test' ? 't' : $p;
108    $case->{name} = "$prefix-Fail";
109    $case->{phase} = $p;
110    $case->{command} = $phase_cmd{$p};
111    ($stdout, $stderr) = test_dispatch(
112        $case,
113        will_send => $case->{will_send},
114    );
115    like( $stdout, "/" . $phase_prompts{$p} . "/m",
116        "prompt for send_$p\_report" );
117}
118
119