2 # Copyright (C) 2007, Parrot Foundation.
9 use Test::More tests => 21;
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 my ($args, $step_list_ref) = process_options(
25 ok( defined $args, "process_options returned successfully" );
28 my $conf = Parrot::Configure->new;
29 ok( defined $conf, "Parrot::Configure->new() returned okay" );
31 my $newconf = Parrot::Configure->new;
32 ok( defined $newconf, "Parrot::Configure->new() returned okay" );
33 is( $conf, $newconf, "Parrot::Configure object is a singleton" );
35 # Since these tests peek into the Parrot::Configure object, they will break if
36 # the structure of that object changes. We retain them for now to delineate
37 # our progress in testing the object.
38 foreach my $k (qw| steps options data |) {
39 ok( defined $conf->$k, "Parrot::Configure object has $k key" );
41 is( ref( $conf->steps ), q{ARRAY}, "Parrot::Configure object 'steps' key is array reference" );
42 is( scalar @{ $conf->steps },
43 0, "Parrot::Configure object 'steps' key holds empty array reference" );
44 foreach my $k (qw| options data |) {
45 isa_ok( $conf->$k, "Parrot::Configure::Data" );
48 my $step = q{init::foobar};
49 my $description = 'Determining if your computer does foobar';
51 $conf->add_steps($step);
52 my @confsteps = @{ $conf->steps };
53 isnt( scalar @confsteps, 0,
54 "Parrot::Configure object 'steps' key holds non-empty array reference" );
55 is( scalar @confsteps, 1, "Parrot::Configure object 'steps' key holds ref to 1-element array" );
57 foreach my $k (@confsteps) {
58 $nontaskcount++ unless $k->isa("Parrot::Configure::Task");
60 is( $nontaskcount, 0, "Each step is a Parrot::Configure::Task object" );
61 is( $confsteps[0]->step, $step, "'step' element of Parrot::Configure::Task struct identified" );
62 ok( !ref( $confsteps[0]->object ),
63 "'object' element of Parrot::Configure::Task struct is not yet a ref" );
65 $conf->options->set(%args);
66 is( $conf->options->{c}->{debugging},
67 1, "command-line option '--debugging' has been stored in object" );
71 my ($stdout, $stderr);
72 capture( sub {$rv = $conf->runsteps }, \$stdout, \$stderr );
73 ok( $rv, "runsteps successfully ran $step" );
74 like( $stdout, qr/$description/, "Got message expected upon running $step" );
77 pass("Completed all tests in $0");
79 ################### DOCUMENTATION ###################
83 005-run_one_step.t - test Parrot::Configure by running one step
87 % prove t/configure/005-run_one_step.t
91 The files in this directory test functionality used by F<Configure.pl>.
93 The tests in this file test those Parrot::Configure methods regularly called
94 by F<Configure.pl> up to C<Parrot::Configure::runsteps()> but providing only
95 one step instead of the regular full set.
103 Parrot::Configure, F<Configure.pl>.
109 # cperl-indent-level: 4
112 # vim: expandtab shiftwidth=4: