tagged release 0.6.4
[parrot.git] / t / steps / auto_gettext-02.t
blob2ad7d2d75b3298f4963f92233225ab34f99721dc
1 #! perl
2 # Copyright (C) 2007, The Perl Foundation.
3 # $Id$
4 # auto_gettext-02.t
6 use strict;
7 use warnings;
8 use Test::More tests =>  24;
9 use Carp;
10 use lib qw( lib t/configure/testlib );
11 use_ok('config::init::defaults');
12 use_ok('config::auto::gettext');
13 use Parrot::Configure;
14 use Parrot::Configure::Options qw( process_options );
15 use Parrot::Configure::Test qw( test_step_thru_runstep);
16 use IO::CaptureOutput qw| capture |;
19 my $args = process_options(
20     {
21         argv => [ ],
22         mode => q{configure},
23     }
26 my $conf = Parrot::Configure->new;
28 test_step_thru_runstep( $conf, q{init::defaults}, $args );
30 my $pkg = q{auto::gettext};
32 $conf->add_steps($pkg);
33 $conf->options->set( %{$args} );
35 my ( $task, $step_name, $step);
36 $task        = $conf->steps->[-1];
37 $step_name   = $task->step;
39 $step = $step_name->new();
40 ok( defined $step, "$step_name constructor returned defined value" );
41 isa_ok( $step, $step_name );
43 # Mock values for OS and C-compiler
44 my ($osname, $cc, $initial_value);
45 $osname = 'mswin32';
46 $cc = 'gcc';
47 $initial_value = $conf->data->get( 'libs' );
48 ok($step->_add_to_libs( {
49     conf            => $conf,
50     osname          => $osname,
51     cc              => $cc,
52     win32_gcc       => '-lintl',
53     win32_nongcc    => 'intl.lib',
54     default         => defined $conf->data->get('glibc') ? '' : '-lintl',
55 } ),
56     "_add_to_libs() returned true value");
57 like($conf->data->get( 'libs' ), qr/-lintl/,
58     "'libs' modified as expected");
59 # Restore value for next test.
60 $conf->data->set( 'libs' => $initial_value );
62 $osname = 'mswin32';
63 $cc = 'cc';
64 ok($step->_add_to_libs( {
65     conf            => $conf,
66     osname          => $osname,
67     cc              => $cc,
68     win32_gcc       => '-lintl',
69     win32_nongcc    => 'intl.lib',
70     default         => defined $conf->data->get('glibc') ? '' : '-lintl',
71 } ),
72     "_add_to_libs() returned true value");
73 like($conf->data->get( 'libs' ), qr/intl.lib/,
74     "'libs' modified as expected");
75 # Restore value for next test.
76 $conf->data->set( 'libs' => $initial_value );
78 $osname = 'foobar';
79 $cc = 'cc';
80 $conf->data->set( glibc => 1 );
81 ok($step->_add_to_libs( {
82     conf            => $conf,
83     osname          => $osname,
84     cc              => $cc,
85     win32_gcc       => '-lintl',
86     win32_nongcc    => 'intl.lib',
87     default         => defined $conf->data->get('glibc') ? '' : '-lintl',
88 } ),
89     "_add_to_libs() returned true value");
90 unlike($conf->data->get( 'libs' ), qr/-lintl/,
91     "'libs' modified as expected");
92 # Restore value for next test.
93 $conf->data->set( 'libs' => $initial_value );
95 $osname = 'foobar';
96 $cc = 'cc';
97 $conf->data->set( glibc => undef );
98 ok($step->_add_to_libs( {
99     conf            => $conf,
100     osname          => $osname,
101     cc              => $cc,
102     win32_gcc       => '-lintl',
103     win32_nongcc    => 'intl.lib',
104     default         => defined $conf->data->get('glibc') ? '' : '-lintl',
105 } ),
106     "_add_to_libs() returned true value");
107 like($conf->data->get( 'libs' ), qr/-lintl/,
108     "'libs' modified as expected");
110 my ($test, $verbose);
111 my $has_gettext;
113 $test = "Hello, world!\n";
114 $verbose = undef;
115 $has_gettext = $step->_evaluate_cc_run($test, $verbose);
116 is($has_gettext, 1, "Got expected value for has_gettext");
117 is($step->result(), 'yes', "Expected result was set");
118 # Prepare for next test
119 $step->set_result(undef);
122     my $stdout;
123     $test = "Hello, world!\n";
124     $verbose = 1;
125     capture(
126         sub {
127             $has_gettext = $step->_evaluate_cc_run($test, $verbose);
128         },
129         \$stdout,
130     );
131     is($has_gettext, 1, "Got expected value for has_gettext");
132     is($step->result(), 'yes', "Expected result was set");
133     like($stdout, qr/\(yes\)/, "Got expected verbose output");
134     # Prepare for next test
135     $step->set_result(undef);
138 $test = "Foobar\n";
139 $verbose = undef;
140 $has_gettext = $step->_evaluate_cc_run($test, $verbose);
141 is($has_gettext, 0, "Got expected value for has_gettext");
142 ok(! defined $step->result(), "As expected, result is not yet defined");
145 pass("Completed all tests in $0");
147 ################### DOCUMENTATION ###################
149 =head1 NAME
151 auto_gettext-02.t - test config::auto::gettext
153 =head1 SYNOPSIS
155     % prove t/steps/auto_gettext-02.t
157 =head1 DESCRIPTION
159 The files in this directory test functionality used by F<Configure.pl>.
161 The tests in this file test internal method
162 C<auto::gettext::_evaluate_cc_run()>.
164 =head1 AUTHOR
166 James E Keenan
168 =head1 SEE ALSO
170 config::auto::gettext, F<Configure.pl>.
172 =cut
174 # Local Variables:
175 #   mode: cperl
176 #   cperl-indent-level: 4
177 #   fill-column: 100
178 # End:
179 # vim: expandtab shiftwidth=4: