2 # Copyright (C) 2007, Parrot Foundation.
11 use Cwd qw(cwd realpath);
12 our $topdir = realpath($Bin) . "/../..";
13 unshift @INC, qq{$topdir/lib};
15 use Test::More tests => 29;
18 'Parrot::Configure::Options', qw|
23 "Parrot::Configure::Options::Reconf", qw|
27 use IO::CaptureOutput qw | capture |;
30 my $badoption = q{samsonanddelilah};
33 %valid = map { $_, 1 } @Parrot::Configure::Options::Reconf::valid_options;
35 ok( scalar keys %valid, "non-zero quantity of valid options found" );
36 ok( defined $valid{debugging}, "debugging option found" );
37 ok( defined $valid{maintainer}, "maintainer option found" );
38 ok( defined $valid{help}, "help option found" );
39 ok( defined $valid{verbose}, "verbose option found" );
40 ok( !defined $valid{$badoption}, "invalid option not found" );
43 $args = process_options(
46 mode => q{reconfigure},
49 ok( defined $args, "process_options() returned successfully" );
50 ok( $args->{debugging}, "debugging turned on by default" );
52 eval { $args = process_options( { argv => [] } ); };
55 qr/'mode' argument not provided to process_options\(\)/,
56 "process_options() failed due to lack of argument 'mode'"
59 eval { $args = process_options( { argv => [], mode => 'foobar' } ); };
62 qr/Invalid value for 'mode' argument to process_options\(\)/,
63 "process_options() failed due to invalid 'mode' argument"
66 $args = process_options( { mode => q{reconfigure}, } );
68 "process_options() returned successfully even though no explicit 'argv' key was provided" );
70 $args = process_options(
72 argv => [ q{--ask}, q{--verbose} ],
73 mode => q{reconfigure},
76 ok( defined $args, "process_options() returned successfully when options were specified" );
78 $args = process_options(
80 argv => [ q{--step=gen::makefiles}, q{--target=Makefile} ],
81 mode => q{reconfigure},
85 "With 'reconfigure' mode, 'step' and 'target' are valid options to process_options()" );
88 my $CC = "/usr/bin/gcc-3.3";
89 eval { $args = process_options( { argv => [qq{--$badoption=$CC}], mode => q{reconfigure}, } ); };
92 qr/^Invalid option "$badoption"/,
93 "process_options() failed due to bad option '$badoption'"
99 sub { $args = process_options(
100 { argv => [q{--help}], mode => q{reconfigure}, }
104 ok( !defined $args, "process_options() returned undef after 'help' option" );
105 like( $stdout, qr/--help/i, "got correct message after 'help' option" );
111 sub { $args = process_options(
112 { argv => [q{--}], mode => q{reconfigure}, }
116 like( $stdout, qr/--help/i, "got help message as expected" );
119 $badoption = q{version};
120 eval { $args = process_options( { argv => [qq{--$badoption}], mode => q{reconfigure}, } ); };
123 qr/^Invalid option "$badoption"/,
124 "process_options() failed due to bad option '$badoption'"
127 $args = process_options(
129 argv => [ q{--lex}, ],
130 mode => q{reconfigure},
133 ok( defined $args, "process_options() returned successfully after 'lex' option" );
134 ok( $args->{maintainer}, "'maintainer' attribute is true after 'lex' option" );
136 $args = process_options(
138 argv => [ q{--yacc}, ],
139 mode => q{reconfigure},
142 ok( defined $args, "process_options() returned successfully after 'yacc' option" );
143 ok( $args->{maintainer}, "'maintainer' attribute is true after 'yacc' option" );
145 $args = process_options(
147 argv => [q{--debugging=1}],
148 mode => q{reconfigure},
151 ok( defined $args, "process_options() returned successfully" );
152 ok( $args->{debugging}, "debugging turned on explicitly" );
154 $args = process_options(
156 argv => [q{--debugging=0}],
157 mode => q{reconfigure},
160 ok( defined $args, "process_options() returned successfully" );
161 ok( !$args->{debugging}, "debugging explicitly turned off" );
163 pass("Completed all tests in $0");
165 ################### DOCUMENTATION ###################
169 01-options.t - test Parrot::Configure::Options as used in F<tools/dev/reconfigure.pl>
173 % prove t/postconfigure/01-options.t
177 The files in this directory test functionality used after initial
180 The tests in this file test subroutines exported by Parrot::Configure::Options
181 as it is used in F<tools/dev/reconfigure.pl>, I<i.e.>, with C<mode =>
190 Parrot::Configure::Options, Parrot::Configure::Options::Reconf, F<Configure.pl>.
196 # cperl-indent-level: 4
199 # vim: expandtab shiftwidth=4: