1#! perl
2# Copyright (C) 2007,2014, Parrot Foundation.
3# 007-verbose_two.t
4
5use strict;
6use warnings;
7
8use Test::More tests => 11;
9use Carp;
10use lib qw( lib t/configure/testlib );
11use Parrot::Configure;
12use Parrot::Configure::Options qw( process_options );
13use Parrot::Configure::Utils qw | capture |;
14
15$| = 1;
16is( $|, 1, "output autoflush is set" );
17
18my ($args, $step_list_ref) = process_options(
19    {
20        argv => [q{--verbose=2}],
21        mode => q{configure},
22    }
23);
24ok( defined $args, "process_options returned successfully" );
25my %args = %$args;
26
27my $conf = Parrot::Configure->new;
28ok( defined $conf, "Parrot::Configure->new() returned okay" );
29
30my $step        = q{init::foobar};
31my $description = 'Determining if your computer does foobar';
32
33$conf->add_steps($step);
34my @confsteps = @{ $conf->steps };
35isnt( scalar @confsteps, 0,
36    "Parrot::Configure object 'steps' key holds non-empty array reference" );
37is( scalar @confsteps, 1, "Parrot::Configure object 'steps' key holds ref to 1-element array" );
38my $nontaskcount = 0;
39foreach my $k (@confsteps) {
40    $nontaskcount++ unless $k->isa("Parrot::Configure::Task");
41}
42is( $nontaskcount, 0, "Each step is a Parrot::Configure::Task object" );
43is( $confsteps[0]->step, $step, "'step' element of Parrot::Configure::Task struct identified" );
44ok( !ref( $confsteps[0]->object ),
45    "'object' element of Parrot::Configure::Task struct is not yet a ref" );
46
47$conf->options->set(%args);
48
49{
50    my $rv;
51    my ( $stdout );
52    capture ( sub {$rv = $conf->runsteps}, \$stdout );
53    ok( $rv, "runsteps successfully ran $step" );
54    like(
55        $stdout,
56        qr/$description\.\.\..*Setting Configuration Data.*verbose.*2.*done/s,
57        "Got message expected upon running $step"
58    );
59}
60
61pass("Completed all tests in $0");
62
63################### DOCUMENTATION ###################
64
65=head1 NAME
66
67007-verbose_two.t - test bad step failure case in Parrot::Configure
68
69=head1 SYNOPSIS
70
71    % prove t/configure/007-verbose_two.t
72
73=head1 DESCRIPTION
74
75The files in this directory test functionality used by F<Configure.pl>.
76
77The tests in this file examine what happens when you configure with the
78<--verbose> option set to C<2>.
79
80(Since I am testing with only the first step, C<init::manifest>, and since that
81step has nothing to say when C<--verbose=1>, I have to advance to
82C<--verbose=2>.)
83
84=head1 AUTHOR
85
86James E Keenan
87
88=head1 SEE ALSO
89
90Parrot::Configure, F<Configure.pl>.
91
92=cut
93
94# Local Variables:
95#   mode: cperl
96#   cperl-indent-level: 4
97#   fill-column: 100
98# End:
99# vim: expandtab shiftwidth=4:
100