2 # Copyright (C) 2007, The Perl Foundation.
11 use Test::More tests => 23;
13 use IO::CaptureOutput qw| capture |;
15 'Parrot::Configure::Options', qw|
19 use_ok("Parrot::Configure::Options::Test");
20 use_ok('Parrot::Configure::Options::Test::Prepare', qw|
21 get_preconfiguration_tests
22 get_postconfiguration_tests
26 my ( $args, $opttest );
29 $args = process_options(
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" );
44 sub { $opttest->run_configure_tests( get_preconfiguration_tests() ); },
48 "Nothing captured because no pre-configuration tests were run." );
54 sub { $opttest->run_build_tests( get_postconfiguration_tests() ); },
58 "Nothing captured because no pre-build tests were run." );
62 $args = process_options(
64 argv => [q{--test=configure}],
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" );
75 $args = process_options(
77 argv => [q{--test=build}],
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" );
88 my $badoption = q{foobar};
89 $args = process_options(
91 argv => [qq{--test=$badoption}],
96 "process_options() returned successfully when '--test=$badoption' was specified" );
98 eval { $opttest = Parrot::Configure::Options::Test->new($args); };
101 qr/'$badoption' is a bad value/,
102 "Bad option to '--test' correctly detected"
106 $args = process_options(
109 mode => q{configure},
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 ###################
149 026-options_test.t - test Parrot::Configure::Options::Test
153 % prove t/configure/026-options_test.t
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.
167 Parrot::Configure::Options, F<Configure.pl>.
173 # cperl-indent-level: 4
176 # vim: expandtab shiftwidth=4: