[cage] Fix pgegrep, which was merely an innocent bystander in the Great Namespace...
[parrot.git] / t / configure / 004-configure.t
blob48c28382b76afa48ce67a1ee48801bb9b1ad09f4
1 #! perl
2 # Copyright (C) 2007, Parrot Foundation.
3 # $Id$
4 # 004-configure.t
6 use strict;
7 use warnings;
9 use Test::More tests => 29;
10 use Carp;
11 use lib qw( lib );
12 use Parrot::Configure;
13 use Parrot::Configure::Options qw( process_options );
14 use Parrot::Configure::Step::List qw| get_steps_list |;
16 $| = 1;
17 is( $|, 1, "output autoflush is set" );
19 my $CC        = "/usr/bin/gcc-3.3";
20 my $localargv = [ qq{--cc=$CC}, ];
21 my ($args, $step_list_ref) = process_options(
22     {
23         mode => q{configure},
24         argv => $localargv,
25     }
27 ok( defined $args, "process_options returned successfully" );
28 my %args = %$args;
30 my $conf = Parrot::Configure->new;
31 ok( defined $conf, "Parrot::Configure->new() returned okay" );
32 isa_ok( $conf, "Parrot::Configure" );
34 my $newconf = Parrot::Configure->new;
35 ok( defined $newconf, "Parrot::Configure->new() returned okay" );
36 isa_ok( $newconf, "Parrot::Configure" );
37 is( $conf, $newconf, "Parrot::Configure object is a singleton" );
39 # Since these tests peek into the Parrot::Configure object, they will break if
40 # the structure of that object changes.  We retain them for now to delineate
41 # our progress in testing the object.
42 foreach my $k (qw| steps options data |) {
43     ok( defined $conf->$k, "Parrot::Configure object has $k key" );
45 is( ref( $conf->steps ), q{ARRAY}, "Parrot::Configure object 'steps' key is array reference" );
46 is( scalar @{ $conf->steps },
47     0, "Parrot::Configure object 'steps' key holds empty array reference" );
48 foreach my $k (qw| options data |) {
49     isa_ok( $conf->$k, "Parrot::Configure::Data" );
52 can_ok( "Parrot::Configure", qw| data | );
53 can_ok( "Parrot::Configure", qw| options | );
54 can_ok( "Parrot::Configure", qw| steps | );
55 can_ok( "Parrot::Configure", qw| add_step | );
56 can_ok( "Parrot::Configure", qw| add_steps | );
57 can_ok( "Parrot::Configure", qw| run_single_step | );
58 can_ok( "Parrot::Configure", qw| runsteps | );
59 can_ok( "Parrot::Configure", qw| _run_this_step | );
61 $conf->add_steps( get_steps_list() );
62 my @confsteps = @{ $conf->steps };
63 isnt( scalar @confsteps, 0,
64     "Parrot::Configure object 'steps' key holds non-empty array reference" );
65 my $nontaskcount = 0;
66 foreach my $k (@confsteps) {
67     $nontaskcount++ unless $k->isa("Parrot::Configure::Task");
69 is( $nontaskcount, 0, "Each step is a Parrot::Configure::Task object" );
71 $conf->options->set(%args);
72 is( $conf->options->{c}->{cc}, $CC, "command-line option '--cc' has been stored in object" );
73 is( $conf->options->{c}->{debugging},
74     1, "command-line option '--debugging' has been stored in object" );
76 my $res = eval "no strict; use Parrot::Config::Generated; \\%PConfig";
77 SKIP: {
78     my $reason = <<REASON;
79 If you have already completed configuration,
80 you can call Parrot::Configure::Data::get_PConfig().
81 But here you are testing for that method's failure.
82 REASON
84     skip $reason, 1 if defined $res;
86     eval { $conf->data()->get_PConfig(); };
87     like(
88         $@,
89         qr/You cannot use --step until you have completed the full configure process/,
90 "Got expected error message for --step option and get_PConfig() without prior configuration"
91     );
94 $res = eval "no strict; use Parrot::Config::Generated; \\%PConfig_Temp";
95 SKIP: {
96     my $reason = <<REASON;
97 If you have already completed configuration,
98 you can call Parrot::Configure::Data::get_PConfig_Temp().
99 But here you are testing for that method's failure.
100 REASON
102     skip $reason, 1 if defined $res;
104     eval { $conf->data()->get_PConfig_Temp(); };
105     like(
106         $@,
107         qr/You cannot use --step until you have completed the full configure process/,
108 "Got expected error message for --step option and get_PConfig_Temp() without prior configuration"
109     );
112 pass("Completed all tests in $0");
114 ################### DOCUMENTATION ###################
116 =head1 NAME
118 004-configure.t - test Parrot::Configure
120 =head1 SYNOPSIS
122     % prove t/configure/004-configure.t
124 =head1 DESCRIPTION
126 The files in this directory test functionality used by F<Configure.pl>.
128 The tests in this file test those Parrot::Configure methods regularly called
129 by F<Configure.pl> up to, but not including, C<Parrot::Configure::runsteps()>.
130 There is also a test for failure of the C<--step> option without prior
131 completed configuration.
133 =head1 AUTHOR
135 James E Keenan
137 =head1 SEE ALSO
139 Parrot::Configure, F<Configure.pl>.
141 =cut
143 # Local Variables:
144 #   mode: cperl
145 #   cperl-indent-level: 4
146 #   fill-column: 100
147 # End:
148 # vim: expandtab shiftwidth=4: