2 # Copyright (C) 2007, Parrot Foundation.
8 use Test::More tests => 21;
12 use File::Spec::Functions qw/catfile/;
13 use File::Temp qw(tempdir);
14 use lib qw( lib t/configure/testlib );
15 use_ok('config::init::hints');
16 use Parrot::Configure::Options qw( process_options );
17 use Parrot::Configure::Step::Test;
18 use Parrot::Configure::Test qw(
19 test_step_constructor_and_description
21 use IO::CaptureOutput qw | capture |;
23 ########## --verbose ##########
25 my ($args, $step_list_ref) = process_options(
27 argv => [q{--verbose}],
32 my $conf = Parrot::Configure::Step::Test->new;
33 $conf->include_config_results( $args );
35 my $pkg = q{init::hints};
37 $conf->add_steps($pkg);
39 my $serialized = $conf->pcfreeze();
41 $conf->options->set( %{$args} );
42 my $step = test_step_constructor_and_description($conf);
44 # need to capture the --verbose output, because the fact that it does not end
45 # in a newline confuses Test::Harness
49 capture ( sub {$rv = $step->runstep($conf)}, \$stdout);
50 ok( $stdout, "verbose output: hints were captured" );
51 ok( defined $rv, "runstep() returned defined value" );
54 $conf->replenish($serialized);
56 ########## --verbose; local hints directory ##########
58 ($args, $step_list_ref) = process_options(
60 argv => [q{--verbose}],
65 $conf->options->set( %{$args} );
66 $step = test_step_constructor_and_description($conf);
70 my $tdir = tempdir( CLEANUP => 1 );
71 File::Path::mkpath(qq{$tdir/init/hints})
72 or croak "Unable to create directory for local hints";
73 my $localhints = qq{$tdir/init/hints/local.pm};
74 open my $FH, '>', $localhints
75 or croak "Unable to open temp file for writing";
77 package init::hints::local;
84 close $FH or croak "Unable to close temp file after writing";
85 unshift( @INC, $tdir );
90 capture ( sub {$rv = $step->runstep($conf)}, \$stdout);
91 ok( $stdout, "verbose output: hints were captured" );
92 ok( defined $rv, "runstep() returned defined value" );
94 unlink $localhints or croak "Unable to delete $localhints";
97 $conf->replenish($serialized);
99 ########## --verbose; local hints directory; no runstep() in local hints ##########
101 ($args, $step_list_ref) = process_options(
103 argv => [q{--verbose}],
104 mode => q{configure},
108 $conf->options->set( %{$args} );
109 $step = test_step_constructor_and_description($conf);
113 my $tdir = tempdir( CLEANUP => 1 );
114 File::Path::mkpath(qq{$tdir/init/hints})
115 or croak "Unable to create directory for local hints";
116 my $localhints = qq{$tdir/init/hints/local.pm};
117 open my $FH, '>', $localhints
118 or croak "Unable to open temp file for writing";
120 package init::hints::local;
124 close $FH or croak "Unable to close temp file after writing";
125 unshift( @INC, $tdir );
130 capture ( sub {$rv = $step->runstep($conf)}, \$stdout);
131 ok( $stdout, "verbose output: hints were captured" );
132 ok( defined $rv, "runstep() returned defined value" );
134 unlink $localhints or croak "Unable to delete $localhints";
137 $conf->replenish($serialized);
139 ########## --verbose; imaginary OS ##########
141 ($args, $step_list_ref) = process_options(
143 argv => [ q{--verbose} ],
144 mode => q{configure},
148 $conf->options->set( %{$args} );
149 $step = test_step_constructor_and_description($conf);
151 my ($stdout, $stderr, $ret);
152 $conf->data->set( OSNAME_provisional => q{imaginaryOS} );
153 my $osname = lc( $conf->data->get( 'OSNAME_provisional' ) );
154 my $hints_file = catfile('config', 'init', 'hints', "$osname.pm");
156 sub { $ret = $step->runstep($conf); },
162 qr/No \Q$hints_file\E found/s,
163 "Got expected verbose output when no hints file found"
167 pass("Completed all tests in $0");
169 ################### DOCUMENTATION ###################
173 init/hints-01.t - test init::hints
177 % prove t/steps/init/hints-01.t
181 The files in this directory test functionality used by F<Configure.pl>.
183 The tests in this file test init::hints.
191 config::init::hints, F<Configure.pl>.
197 # cperl-indent-level: 4
200 # vim: expandtab shiftwidth=4: