1#! perl
2# Copyright (C) 2007, Parrot Foundation.
3# 002-messages.t
4
5use strict;
6use warnings;
7use Carp;
8use Test::More tests => 13;
9use lib qw( lib );
10use Parrot::Configure::Messages qw|
11    print_introduction
12    print_conclusion
13|;
14use Parrot::Configure::Utils qw| capture |;
15
16my $parrot_version = '0.4.10';
17my $make_version   = 'gnu make';
18
19{
20    my ( $rv, $stdout );
21    capture(
22        sub { $rv = print_introduction($parrot_version); },
23        \$stdout,
24    );
25    ok( $rv, "print_introduction() returned true" );
26
27    # Following test is definitive.
28    like( $stdout, qr/$parrot_version/,
29        "Message included Parrot version number supplied as argument" );
30
31    # Following tests are NOT definitive.  They will break if content of
32    # strings printed by function is changed.
33    like( $stdout, qr/Parrot\sVersion/i, "Message included string 'Parrot version'" );
34    like( $stdout, qr/Configure/i,       "Message included string 'Configure'" );
35    like( $stdout, qr/Copyright/i,       "Message included copyright notice" );
36}
37
38{
39    my ( $rv, $stdout );
40    my $pseudo_conf = {
41        log => [],
42    };
43    my $args = {};
44    capture(
45        sub { $rv = print_conclusion($pseudo_conf, $make_version, $args); },
46        \$stdout,
47    );
48    ok( $rv, "print_conclusion() returned true" );
49
50    # Following test is definitive.
51    like( $stdout, qr/$make_version/, "Message included make version supplied as argument" );
52
53}
54
55{
56    my ( $rv, $stdout, $stderr );
57    my $pseudo_conf = {
58        log => [],
59    };
60    my $args = { silent => 1 };
61    capture(
62        sub { $rv = print_conclusion($pseudo_conf, $make_version, $args); },
63        \$stdout,
64        \$stderr,
65    );
66    ok( $rv, "print_conclusion() returned true" );
67
68    # Following test is definitive.
69    ok( ! $stdout, "Configure.pl operated silently, as requested" );
70}
71
72{
73    my ( $rv, $stdout, $stderr );
74    my $pseudo_conf = {
75        log => [
76            undef,
77            {   step    => q{init::manifest} },
78        ],
79    };
80    my $args = {};
81    capture(
82        sub { $rv = print_conclusion($pseudo_conf, $make_version, $args); },
83        \$stdout,
84        \$stderr,
85    );
86    ok(! defined $rv, "print_conclusion() returned undefined value" );
87
88    ok( ! $stdout,
89        "Because of the error, nothing printed to standard output");
90    like( $stderr,
91        qr/During configuration the following steps failed:.*init::manifest/s,
92        "Got expected message re configuration step failure" );
93}
94
95pass("Completed all tests in $0");
96
97################### DOCUMENTATION ###################
98
99=head1 NAME
100
101002-messages.t - test Parrot::Configure::Messages
102
103=head1 SYNOPSIS
104
105    % prove t/configure/components/002-messages.t
106
107=head1 DESCRIPTION
108
109The files in this directory test functionality used by F<Configure.pl>.
110
111The tests in this file test subroutines exported by
112Parrot::Configure::Messages.
113
114=head1 AUTHOR
115
116James E Keenan
117
118=head1 SEE ALSO
119
120Parrot::Configure::Messages, F<Configure.pl>.
121
122=cut
123
124# Local Variables:
125#   mode: cperl
126#   cperl-indent-level: 4
127#   fill-column: 100
128# End:
129# vim: expandtab shiftwidth=4:
130