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::yacc');
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::yacc};
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},
44 "Step was skipped as expected; no '--maintainer' option" );
45 # re-set for next step
46 $step->set_result(q{});
48 $conf->replenish($serialized);
50 ########## ask; maintainer; $ENV{YACC} ##########
52 $ENV{YACC} = 'foobar';
53 ($args, $step_list_ref) = process_options(
55 argv => [ q{--ask}, q{--maintainer} ],
59 $conf->options->set( %{$args} );
60 $step = test_step_constructor_and_description($conf);
61 $ret = $step->runstep($conf);
62 ok( defined $ret, "runstep() returned defined value" );
63 my $result_expected = q{user defined};
64 is( $step->result(), $result_expected,
65 "Result was $result_expected because environment variable was set" );
66 # re-set for next step
68 $step->set_result('');
70 $conf->replenish($serialized);
72 ########## ask; maintainer; yacc=bison ##########
74 ($args, $step_list_ref) = process_options(
76 argv => [ q{--ask}, q{--maintainer}, q{--yacc=bison} ],
80 $conf->options->set( %{$args} );
81 $step = test_step_constructor_and_description($conf);
82 my ( @prompts, $object );
83 @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 $ret = $step->runstep($conf);
88 ok( defined $ret, "runstep() returned defined value" );
89 $result_expected = q{user defined};
90 is( $step->result(), $result_expected, "Result was $result_expected" );
93 # re-set for next step
94 $step->set_result(q{});
97 $conf->replenish($serialized);
99 ########## ask; maintainer; ##########
101 ($args, $step_list_ref) = process_options(
103 argv => [ q{--ask}, q{--maintainer} ],
104 mode => q{configure},
107 $conf->options->set( %{$args} );
108 $step = test_step_constructor_and_description($conf);
110 $object = tie *STDIN, 'Tie::Filehandle::Preempt::Stdin', @prompts;
111 can_ok( 'Tie::Filehandle::Preempt::Stdin', ('READLINE') );
112 isa_ok( $object, 'Tie::Filehandle::Preempt::Stdin' );
116 capture ( sub {$rv = $step->runstep($conf)}, \$stdout);
117 my $possible_results = qr/^(
118 no\syacc\sprogram\swas\sfound
119 | yacc\sprogram\sdoes\snot\sexist\sor\sdoes\snot\sunderstand\s--version
120 | could\snot\sunderstand\sbison\sversion\srequirement
121 | found\sbison\sversion.*?but\sat\sleast.*?is\srequired
124 my @dump_msg = ( Dumper( $step->result() ) =~ /'(.*?)'/ );
125 like( $step->result(), $possible_results,
126 "Response to prompt led to acceptable result: " . $dump_msg[0] );
127 if ( $dump_msg[0] eq q{no yacc program was found} ) {
128 ok( !$stdout, "No yacc program => no prompts" );
131 ok( $stdout, "prompts were captured" );
136 # re-set for next step
137 $step->set_result(q{});
141 pass("Completed all tests in $0");
143 ################### DOCUMENTATION ###################
147 inter/yacc-01.t - test inter::yacc
151 % prove t/steps/inter/yacc-01.t
155 The files in this directory test functionality used by F<Configure.pl>.
157 The tests in this file test inter::yacc.
165 config::inter::yacc, F<Configure.pl>.
171 # cperl-indent-level: 4
174 # vim: expandtab shiftwidth=4: