1#! perl
2# Copyright (C) 2007,2014, Parrot Foundation.
3# 059-silent.t
4
5use strict;
6use warnings;
7
8use Test::More tests => 12;
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{--silent} ],
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" );
29my $serialized = $conf->pcfreeze();
30
31my $step        = q{init::gamma};
32my $description = 'Determining if your computer does gamma';
33
34$conf->add_steps($step);
35my @confsteps = @{ $conf->steps };
36isnt( scalar @confsteps, 0,
37    "Parrot::Configure object 'steps' key holds non-empty array reference" );
38is( scalar @confsteps, 1, "Parrot::Configure object 'steps' key holds ref to 1-element array" );
39my $nontaskcount = 0;
40foreach my $k (@confsteps) {
41    $nontaskcount++ unless $k->isa("Parrot::Configure::Task");
42}
43is( $nontaskcount, 0, "Each step is a Parrot::Configure::Task object" );
44is( $confsteps[0]->step, $step, "'step' element of Parrot::Configure::Task struct identified" );
45ok( !ref( $confsteps[0]->object ),
46    "'object' element of Parrot::Configure::Task struct is not yet a ref" );
47
48$conf->options->set(%args);
49
50my $rv;
51my ($stdout, $stderr);
52capture ( sub { eval { $rv = $conf->runsteps; } }, \$stdout, \$stderr);
53ok(! $stdout, "silent option worked");
54like( $stderr,
55qr/step $step died during execution: Dying gamma just to see what happens/,
56        "Got expected error message despite silent option");
57
58$conf->replenish($serialized);
59
60##### --silent option; valid step #####
61
62($args, $step_list_ref) = process_options(
63    {
64        argv => [ q{--silent} ],
65        mode => q{configure},
66    }
67);
68%args = %$args;
69$step        = q{init::lambda};
70$conf->add_steps($step);
71$conf->options->set(%args);
72{
73    my $rv;
74    my ($stdout);
75    capture ( sub { eval { $rv = $conf->runsteps; } }, \$stdout);
76    ok(! $stdout, "silent option worked");
77}
78
79pass("Completed all tests in $0");
80
81################### DOCUMENTATION ###################
82
83=head1 NAME
84
85059-silent.t - test what happens when the C<--silent> option is set
86
87=head1 SYNOPSIS
88
89    % prove t/configure/059-silent.t
90
91=head1 DESCRIPTION
92
93The files in this directory test functionality used by F<Configure.pl>.
94
95The tests in this file examine various cases occurring while using the
96C<--silent> option.
97
98=head1 AUTHOR
99
100James E Keenan
101
102=head1 SEE ALSO
103
104Parrot::Configure, F<Configure.pl>.
105
106=cut
107
108# Local Variables:
109#   mode: cperl
110#   cperl-indent-level: 4
111#   fill-column: 100
112# End:
113# vim: expandtab shiftwidth=4:
114