2 # Copyright (C) 2007, Parrot Foundation.
10 use Test::More tests => 20;
12 use IO::CaptureOutput qw| capture |;
13 use Parrot::Configure::Options qw| process_options |;
14 use Parrot::Configure::Options::Test;
15 use Parrot::Configure::Options::Test::Prepare qw|
16 get_preconfiguration_tests
17 get_postconfiguration_tests
21 my ( $args, $step_list_ref ) = process_options(
28 "process_options() returned successfully when no options were specified" );
30 my $opttest = Parrot::Configure::Options::Test->new($args);
31 ok( defined $opttest, "Constructor returned successfully" );
36 sub { $opttest->run_configure_tests( get_preconfiguration_tests() ); },
40 "Nothing captured because no pre-configuration tests were run." );
46 sub { $opttest->run_build_tests( get_postconfiguration_tests() ); },
50 "Nothing captured because no pre-build tests were run." );
54 ($args, $step_list_ref) = process_options(
56 argv => [q{--test=configure}],
61 "process_options() returned successfully when '--test=configure' was specified" );
63 $opttest = Parrot::Configure::Options::Test->new($args);
64 ok( defined $opttest, "Constructor returned successfully" );
67 ($args, $step_list_ref) = process_options(
69 argv => [q{--test=build}],
74 "process_options() returned successfully when '--test=build' was specified" );
76 $opttest = Parrot::Configure::Options::Test->new($args);
77 ok( defined $opttest, "Constructor returned successfully" );
80 my $badoption = q{foobar};
81 ($args, $step_list_ref) = process_options(
83 argv => [qq{--test=$badoption}],
88 "process_options() returned successfully when '--test=$badoption' was specified" );
90 eval { $opttest = Parrot::Configure::Options::Test->new($args); };
93 qr/'$badoption' is a bad value/,
94 "Bad option to '--test' correctly detected"
98 ($args, $step_list_ref) = process_options(
101 mode => q{configure},
105 "process_options() returned successfully when no options were specified" );
107 $opttest = Parrot::Configure::Options::Test->new($args);
108 ok( defined $opttest, "Constructor returned successfully" );
110 eval { $opttest->set( 'foobar' ); };
111 like($@, qr/Need 2 arguments to Parrot::Configure::Options::Test::set/,
112 "Correctly detected lack of argument to set()");
114 $opttest->set( foo => 'bar' );
115 is($opttest->get( 'foo' ), 'bar', "set() set value correctly");
117 eval { $opttest->get( foo => 'bar' ); };
118 like($@, qr/Need 1 argument to Parrot::Configure::Options::Test::get/,
119 "Correctly detected wrong number of arguments to get()");
121 ok(! defined $opttest->get( 'baz' ),
122 "Correctly detected value which never was set");
124 eval { $opttest->set_run( 'foobar' ); };
125 like($@, qr/Need 2 arguments to Parrot::Configure::Options::Test::set_run/,
126 "Correctly detected lack of argument to set_run()");
128 $opttest->set_run( foo => 'bar' );
129 is($opttest->get_run( 'foo' ), 'bar', "set_run() set value correctly");
131 eval { $opttest->get_run( foo => 'bar' ); };
132 like($@, qr/Need 1 argument to Parrot::Configure::Options::Test::get_run/,
133 "Correctly detected wrong number of arguments to get_run()");
135 pass("Completed all tests in $0");
137 ################### DOCUMENTATION ###################
141 026-options_test.t - test Parrot::Configure::Options::Test
145 % prove t/configure/026-options_test.t
149 The files in this directory test functionality used by F<Configure.pl>.
151 The tests in this file test Parrot::Configure::Options::Test methods.
159 Parrot::Configure::Options, F<Configure.pl>.
165 # cperl-indent-level: 4
168 # vim: expandtab shiftwidth=4: