tagged release 0.6.4
[parrot.git] / t / steps / inter_lex-05.t
blobd84f3021f38c5fd25979d8f04a52c915418b2ec6
1 #! perl
2 # Copyright (C) 2007, The Perl Foundation.
3 # $Id$
4 # inter_lex-05.t
6 use strict;
7 use warnings;
8 use Data::Dumper;
9 use Test::More tests =>  13;
10 use Carp;
11 use lib qw( lib t/configure/testlib );
12 use_ok('config::init::defaults');
13 use_ok('config::inter::lex');
14 use Parrot::Configure;
15 use Parrot::Configure::Options qw( process_options );
16 use Parrot::Configure::Test qw( test_step_thru_runstep);
17 use Tie::Filehandle::Preempt::Stdin;
18 use IO::CaptureOutput qw | capture |;
20 my $args = process_options(
21     {
22         argv => [ q{--ask}, q{--maintainer} ],
23         mode => q{configure},
24     }
27 my $conf = Parrot::Configure->new();
29 test_step_thru_runstep( $conf, q{init::defaults}, $args );
31 my ( @prompts, $object, @entered );
32 @prompts = q{flex};
33 $object = tie *STDIN, 'Tie::Filehandle::Preempt::Stdin', @prompts;
34 can_ok( 'Tie::Filehandle::Preempt::Stdin', ('READLINE') );
35 isa_ok( $object, 'Tie::Filehandle::Preempt::Stdin' );
37 my ( $task, $step_name, $step, $ret );
38 my $pkg = q{inter::lex};
40 $conf->add_steps($pkg);
41 $conf->options->set( %{$args} );
43 $task        = $conf->steps->[-1];
44 $step_name   = $task->step;
46 $step = $step_name->new();
47 ok( defined $step, "$step_name constructor returned defined value" );
48 isa_ok( $step, $step_name );
52     my $rv;
53     my $stdout;
54     capture ( sub {$rv = $step->runstep($conf)}, \$stdout);
55     my $possible_results = qr/^(
56         no\slex\sprogram\swas\sfound
57       | lex\sprogram\sdoes\snot\sexist\sor\sdoes\snot\sunderstand\s--version
58       | could\snot\sunderstand\sflex\sversion\srequirement
59       | found\sflex\sversion.*?but\sat\sleast.*?is\srequired
60       | flex
61     )/x;
62     my @dump_msg = ( Dumper( $step->result() ) =~ /'(.*?)'/ );
63     like( $step->result(), $possible_results,
64         "Response to prompt led to acceptable result:  " . $dump_msg[0] );
65     if ( $dump_msg[0] eq q{no lex program was found} ) {
66         ok( !$stdout, "No lex program => no prompts" );
67     }
68     else {
69         ok( $stdout, "prompts were captured" );
70     }
73 $object = undef;
75 pass("Completed all tests in $0");
77 ################### DOCUMENTATION ###################
79 =head1 NAME
81 inter_lex-05.t - test config::inter::lex
83 =head1 SYNOPSIS
85     % prove t/steps/inter_lex-05.t
87 =head1 DESCRIPTION
89 The files in this directory test functionality used by F<Configure.pl>.
91 The tests in this file test subroutines exported by config::inter::lex.
93 =head1 AUTHOR
95 James E Keenan
97 =head1 SEE ALSO
99 config::inter::lex, F<Configure.pl>.
101 =cut
103 # Local Variables:
104 #   mode: cperl
105 #   cperl-indent-level: 4
106 #   fill-column: 100
107 # End:
108 # vim: expandtab shiftwidth=4: