2 # Copyright (C) 2007-2008, Parrot Foundation.
8 use Test::More tests => 26;
11 use lib qw( lib t/configure/testlib );
12 use_ok('config::inter::lex');
13 use Parrot::Configure::Options qw( process_options );
14 use Parrot::Configure::Step::Test;
15 use Parrot::Configure::Test qw(
16 test_step_constructor_and_description
18 use Tie::Filehandle::Preempt::Stdin;
19 use IO::CaptureOutput qw | capture |;
21 ########## ask ##########
23 my ($args, $step_list_ref) = process_options(
30 my $conf = Parrot::Configure::Step::Test->new;
31 $conf->include_config_results( $args );
33 my $pkg = q{inter::lex};
35 $conf->add_steps($pkg);
37 my $serialized = $conf->pcfreeze();
39 $conf->options->set( %{$args} );
40 my $step = test_step_constructor_and_description($conf);
41 my $ret = $step->runstep($conf);
42 ok( defined $ret, "runstep() returned defined value" );
43 is( $step->result(), q{skipped}, "Step was skipped as expected; no '--maintainer' option" );
44 # re-set for next test
45 $step->set_result(q{});
47 $conf->replenish($serialized);
49 ########## ask; maintainer; $ENV{LEX} ##########
53 ($args, $step_list_ref) = process_options(
55 argv => [ q{--ask}, q{--maintainer} ],
60 $conf->options->set( %{$args} );
61 $step = test_step_constructor_and_description($conf);
62 $ret = $step->runstep($conf);
63 ok( defined $ret, "runstep() returned defined value" );
64 my $result_expected = q{user defined};
65 is( $step->result(), $result_expected,
66 "Result was $result_expected because environment variable was set" );
67 # re-set for next test
69 $step->set_result('');
71 $conf->replenish($serialized);
73 ########## ask; maintainer; lex=flex ##########
75 ($args, $step_list_ref) = process_options(
77 argv => [ q{--ask}, q{--maintainer}, q{--lex=flex} ],
81 my ( @prompts, $object, @entered );
82 @prompts = map { q{foo_} . $_ } qw| alpha |;
84 $object = tie *STDIN, 'Tie::Filehandle::Preempt::Stdin', @prompts;
85 can_ok( 'Tie::Filehandle::Preempt::Stdin', ('READLINE') );
86 isa_ok( $object, 'Tie::Filehandle::Preempt::Stdin' );
87 $conf->options->set( %{$args} );
88 $step = test_step_constructor_and_description($conf);
89 $ret = $step->runstep($conf);
90 ok( defined $ret, "runstep() returned defined value" );
91 $result_expected = q{user defined};
92 is( $step->result(), $result_expected, "Result was $result_expected" );
95 # re-set for next test
96 $step->set_result(q{});
98 $conf->replenish($serialized);
100 ########## ask; maintainer ##########
102 ($args, $step_list_ref) = process_options(
104 argv => [ q{--ask}, q{--maintainer} ],
105 mode => q{configure},
109 $object = tie *STDIN, 'Tie::Filehandle::Preempt::Stdin', @prompts;
110 can_ok( 'Tie::Filehandle::Preempt::Stdin', ('READLINE') );
111 isa_ok( $object, 'Tie::Filehandle::Preempt::Stdin' );
112 $conf->options->set( %{$args} );
113 $step = test_step_constructor_and_description($conf);
117 capture ( sub {$rv = $step->runstep($conf)}, \$stdout);
118 my $possible_results = qr/^(
119 no\slex\sprogram\swas\sfound
120 | lex\sprogram\sdoes\snot\sexist\sor\sdoes\snot\sunderstand\s--version
121 | could\snot\sunderstand\sflex\sversion\srequirement
122 | found\sflex\sversion.*?but\sat\sleast.*?is\srequired
125 my @dump_msg = ( Dumper( $step->result() ) =~ /'(.*?)'/ );
126 like( $step->result(), $possible_results,
127 "Response to prompt led to acceptable result: " . $dump_msg[0] );
128 if ( $dump_msg[0] eq q{no lex program was found} ) {
129 ok( !$stdout, "No lex program => no prompts" );
132 ok( $stdout, "prompts were captured" );
137 pass("Completed all tests in $0");
139 ################### DOCUMENTATION ###################
143 inter/lex-01.t - test inter::lex
147 % prove t/steps/inter/lex-01.t
151 The files in this directory test functionality used by F<Configure.pl>.
153 The tests in this file test inter::lex.
161 config::inter::lex, F<Configure.pl>.
167 # cperl-indent-level: 4
170 # vim: expandtab shiftwidth=4: