tagged release 0.6.4
[parrot.git] / t / configure / 026-options_test.t
blobe717e297a941215716f271ca71e12ac90575f2f5
1 #! perl
2 # Copyright (C) 2007, The Perl Foundation.
3 # $Id$
4 # 026-options_test.t
6 use strict;
7 use warnings;
8 use Carp;
9 use Cwd;
10 use Data::Dumper;
11 use Test::More tests => 23;
12 use lib qw( lib );
13 use IO::CaptureOutput qw| capture |;
14 use_ok(
15     'Parrot::Configure::Options', qw|
16         process_options
17         |
19 use_ok("Parrot::Configure::Options::Test");
20 use_ok('Parrot::Configure::Options::Test::Prepare', qw|
21     get_preconfiguration_tests
22     get_postconfiguration_tests
23     |
26 my ( $args, $opttest );
28 ##### 1 #####
29 $args = process_options(
30     {
31         argv => [],
32         mode => q{configure},
33     }
35 ok( defined $args,
36     "process_options() returned successfully when no options were specified" );
38 $opttest = Parrot::Configure::Options::Test->new($args);
39 ok( defined $opttest, "Constructor returned successfully" );
42     my $stdout;
43     capture(
44         sub { $opttest->run_configure_tests( get_preconfiguration_tests() ); },
45         \$stdout,
46     );
47     ok( ! $stdout,
48         "Nothing captured because no pre-configuration tests were run." );
52     my $stdout;
53     capture(
54         sub { $opttest->run_build_tests( get_postconfiguration_tests() ); },
55         \$stdout,
56     );
57     ok( ! $stdout,
58         "Nothing captured because no pre-build tests were run." );
61 ##### 2 #####
62 $args = process_options(
63     {
64         argv => [q{--test=configure}],
65         mode => q{configure},
66     }
68 ok( defined $args,
69     "process_options() returned successfully when '--test=configure' was specified" );
71 $opttest = Parrot::Configure::Options::Test->new($args);
72 ok( defined $opttest, "Constructor returned successfully" );
74 ##### 3 #####
75 $args = process_options(
76     {
77         argv => [q{--test=build}],
78         mode => q{configure},
79     }
81 ok( defined $args,
82     "process_options() returned successfully when '--test=build' was specified" );
84 $opttest = Parrot::Configure::Options::Test->new($args);
85 ok( defined $opttest, "Constructor returned successfully" );
87 ##### 4 #####
88 my $badoption = q{foobar};
89 $args = process_options(
90     {
91         argv => [qq{--test=$badoption}],
92         mode => q{configure},
93     }
95 ok( defined $args,
96     "process_options() returned successfully when '--test=$badoption' was specified" );
98 eval { $opttest = Parrot::Configure::Options::Test->new($args); };
99 like(
100     $@,
101     qr/'$badoption' is a bad value/,
102     "Bad option to '--test' correctly detected"
105 ##### 5 #####
106 $args = process_options(
107     {
108         argv => [],
109         mode => q{configure},
110     }
112 ok( defined $args,
113     "process_options() returned successfully when no options were specified" );
115 $opttest = Parrot::Configure::Options::Test->new($args);
116 ok( defined $opttest, "Constructor returned successfully" );
118 eval { $opttest->set( 'foobar' ); };
119 like($@, qr/Need 2 arguments to Parrot::Configure::Options::Test::set/,
120     "Correctly detected lack of argument to set()");
122 $opttest->set( foo => 'bar' );
123 is($opttest->get( 'foo' ), 'bar', "set() set value correctly");
125 eval { $opttest->get( foo => 'bar' ); };
126 like($@, qr/Need 1 argument to Parrot::Configure::Options::Test::get/,
127     "Correctly detected wrong number of arguments to get()");
129 ok(! defined $opttest->get( 'baz' ),
130     "Correctly detected value which never was set");
132 eval { $opttest->set_run( 'foobar' ); };
133 like($@, qr/Need 2 arguments to Parrot::Configure::Options::Test::set_run/,
134     "Correctly detected lack of argument to set_run()");
136 $opttest->set_run( foo => 'bar' );
137 is($opttest->get_run( 'foo' ), 'bar', "set_run() set value correctly");
139 eval { $opttest->get_run( foo => 'bar' ); };
140 like($@, qr/Need 1 argument to Parrot::Configure::Options::Test::get_run/,
141     "Correctly detected wrong number of arguments to get_run()");
143 pass("Completed all tests in $0");
145 ################### DOCUMENTATION ###################
147 =head1 NAME
149 026-options_test.t - test Parrot::Configure::Options::Test
151 =head1 SYNOPSIS
153     % prove t/configure/026-options_test.t
155 =head1 DESCRIPTION
157 The files in this directory test functionality used by F<Configure.pl>.
159 The tests in this file test Parrot::Configure::Options::Test methods.
161 =head1 AUTHOR
163 James E Keenan
165 =head1 SEE ALSO
167 Parrot::Configure::Options, F<Configure.pl>.
169 =cut
171 # Local Variables:
172 #   mode: cperl
173 #   cperl-indent-level: 4
174 #   fill-column: 100
175 # End:
176 # vim: expandtab shiftwidth=4: