2 # Copyright (C) 2007, Parrot Foundation.
9 use Test::More tests => 19;
11 use lib qw( lib t/configure/testlib );
12 use Parrot::Configure;
13 use Parrot::Configure::Options qw( process_options );
14 use IO::CaptureOutput qw | capture |;
17 is( $|, 1, "output autoflush is set" );
19 ##### designate one step as --fatal-step; step fails #####
21 my ($args, $step_list_ref) = process_options(
23 argv => [ qw( --fatal-step=init::zeta ) ],
27 ok( defined $args, "process_options returned successfully" );
30 my $conf = Parrot::Configure->new;
31 ok( defined $conf, "Parrot::Configure->new() returned okay" );
32 my $serialized = $conf->pcfreeze();
34 my $step = q{init::zeta};
35 my $description = 'Determining if your computer does zeta';
37 $conf->add_steps($step);
38 my @confsteps = @{ $conf->steps };
39 isnt( scalar @confsteps, 0,
40 "Parrot::Configure object 'steps' key holds non-empty array reference" );
41 is( scalar @confsteps, 1, "Parrot::Configure object 'steps' key holds ref to 1-element array" );
43 foreach my $k (@confsteps) {
44 $nontaskcount++ unless $k->isa("Parrot::Configure::Task");
46 is( $nontaskcount, 0, "Each step is a Parrot::Configure::Task object" );
47 is( $confsteps[0]->step, $step, "'step' element of Parrot::Configure::Task struct identified" );
48 ok( !ref( $confsteps[0]->object ),
49 "'object' element of Parrot::Configure::Task struct is not yet a ref" );
51 $conf->options->set(%args);
52 is( $conf->options->{c}->{debugging},
53 1, "command-line option '--debugging' has been stored in object" );
57 my ($stdout, $stderr);
58 capture ( sub {$rv = $conf->runsteps}, \$stdout, \$stderr );
59 ok(! defined $rv, 'runsteps() returned undef');
62 qr/$description\.\.\./s,
63 "Got STDOUT message expected upon running $step");
65 qr/step $step failed:/s,
66 "Got STDERR message expected upon running $step");
69 $conf->replenish($serialized);
71 ##### designate multiple steps as --fatal-step; one of them fails #####
73 ($args, $step_list_ref) = process_options(
75 argv => [ q{--fatal-step=init::zeta,init::manifest} ],
80 $step = q{init::zeta};
81 $conf->add_steps($step);
82 $conf->options->set( %{$args} );
85 my ($stdout, $stderr);
86 capture ( sub {$rv = $conf->runsteps}, \$stdout, \$stderr );
87 ok(! defined $rv, 'runsteps() returned undef');
90 qr/$description\.\.\./s,
91 "Got STDOUT message expected upon running $step");
93 qr/step $step failed:/s,
94 "Got STDERR message expected upon running $step");
97 $conf->replenish($serialized);
99 ##### misspecified value for --fatal-step #####
101 ($args, $step_list_ref) = process_options(
103 argv => [ qw( --fatal-step=foo::zeta ) ],
104 mode => q{configure},
107 $step = q{foo::zeta};
108 $conf->add_steps($step);
109 $conf->options->set( %{$args} );
111 eval { $rv = $conf->runsteps; };
112 like($@, qr/^Argument to fatal-step option/,
113 "Got expected error message when value to --fatal-step option was misspecified");
115 $conf->replenish($serialized);
119 ($args, $step_list_ref) = process_options(
121 argv => [ qw( --fatal-step=init::alpha ) ],
122 mode => q{configure},
125 $step = q{init::kappa};
126 $description = 'Determining if your computer does kappa';
127 $conf->add_steps($step);
128 $conf->options->set( %{$args} );
132 capture ( sub {$rv = $conf->runsteps}, \$stdout);
133 ok($rv, "runsteps() returned true value");
135 qr/$description\.\.\./s,
136 "Got STDOUT message expected upon running $step");
140 pass("Completed all tests in $0");
142 ################### DOCUMENTATION ###################
146 051-fatal_step.t - test bad step failure case in Parrot::Configure
150 % prove t/configure/051-fatal_step.t
154 The files in this directory test functionality used by F<Configure.pl>.
156 The tests in this file examine various cases involving use of the
157 C<--fatal-step> option.
165 Parrot::Configure, F<Configure.pl>.
171 # cperl-indent-level: 4
174 # vim: expandtab shiftwidth=4: