Author: jkeenan Date: Sat Apr 7 12:59:19 2007 New Revision: 18027 Added: trunk/lib/Parrot/Configure/Messages.pm (contents, props changed) trunk/t/configure/02-messages.t (contents, props changed) Modified: trunk/Configure.pl trunk/MANIFEST
Log: Committing patch presented in http://rt.perl.org/rt3//Ticket/Display.html?id=42305. Refactoring messages printed to STDOUT during Configure.pl to Parrot::Configure::Messages. Providing one file testing that refactoring. Modified: trunk/Configure.pl ============================================================================== --- trunk/Configure.pl (original) +++ trunk/Configure.pl Sat Apr 7 12:59:19 2007 @@ -263,6 +263,10 @@ use Parrot::BuildUtil; use Parrot::Configure; use Parrot::Configure::Options qw( process_options ); +use Parrot::Configure::Messages qw( + print_introduction + print_conclusion +); # These globals are accessed in config/init/defaults.pm our $parrot_version = Parrot::BuildUtil::parrot_version(); @@ -290,18 +294,8 @@ my %args = %$args; -print <<"END"; -Parrot Version $parrot_version Configure 2.0 -Copyright (C) 2001-2007, The Perl Foundation. - -Hello, I'm Configure. My job is to poke and prod your system to figure out -how to build Parrot. The process is completely automated, unless you passed in -the `--ask' flag on the command line, in which case it'll prompt you for a few -pieces of info. - -Since you're running this program, you obviously have Perl 5--I'll be pulling -some defaults from its configuration. -END +# from Parrot::Configure::Messages +print_introduction($parrot_version); # EDIT HERE TO ADD NEW TESTS my @steps = qw( @@ -386,20 +380,9 @@ } # tell users what to do next -my $make = $conf->data->get('make'); - -print <<"END"; - -Okay, we're done! - -You can now use `$make' to build your Parrot. -(NOTE: do not use `$make -j <n>'!) -After that, you can use `$make test' to run the test suite. - -Happy Hacking, - The Parrot Team -END +# from Parrot::Configure::Messages +print_conclusion($conf->data->get('make')); exit(0); Modified: trunk/MANIFEST ============================================================================== --- trunk/MANIFEST (original) +++ trunk/MANIFEST Sat Apr 7 12:59:19 2007 @@ -2219,6 +2219,7 @@ lib/Parrot/Config.pm [devel] lib/Parrot/Configure.pm [devel] lib/Parrot/Configure/Data.pm [devel] +lib/Parrot/Configure/Messages.pm [devel] lib/Parrot/Configure/Options.pm [devel] lib/Parrot/Configure/Step.pm [devel] lib/Parrot/Configure/Step/Base.pm [devel] @@ -2764,6 +2765,7 @@ t/compilers/tge/harness [] t/compilers/tge/parser.t [] t/configure/01-options.t [] +t/configure/02-messages.t [] t/configure/base.t [] t/configure/config_steps.t [] t/configure/configure.t [] Added: trunk/lib/Parrot/Configure/Messages.pm ============================================================================== --- (empty file) +++ trunk/lib/Parrot/Configure/Messages.pm Sat Apr 7 12:59:19 2007 @@ -0,0 +1,132 @@ +# Copyright (C) 2001-2006, The Perl Foundation. +# $Id$ +package Parrot::Configure::Messages; +use strict; +use warnings; +use base qw( Exporter ); +our @EXPORT_OK = qw( + print_introduction + print_conclusion +); + +################### SUBROUTINES ################### + +sub print_introduction { + my $parrot_version = shift; + print <<"END"; +Parrot Version $parrot_version Configure 2.0 +Copyright (C) 2001-2007, The Perl Foundation. + +Hello, I'm Configure. My job is to poke and prod your system to figure out +how to build Parrot. The process is completely automated, unless you passed in +the `--ask' flag on the command line, in which case it'll prompt you for a few +pieces of info. + +Since you're running this program, you obviously have Perl 5--I'll be pulling +some defaults from its configuration. +END +} + +sub print_conclusion { + my $make = shift; + print <<"END"; + +Okay, we're done! + +You can now use `$make' to build your Parrot. +(NOTE: do not use `$make -j <n>'!) +After that, you can use `$make test' to run the test suite. + +Happy Hacking, + The Parrot Team + +END +} + +1; + +#################### DOCUMENTATION #################### + +=head1 NAME + +Parrot::Configure::Messages - Introduce and conclude Parrot configuration process + +=head1 SYNOPSIS + + use Parrot::Configure::Messages qw( + print_introduction + print_conclusion + ); + + print_introduction($parrot_version); + + print_conclusion($make_version); + +=head1 DESCRIPTION + +Parrot::Configure::Messages exports on demand two subroutines which print +messages to STDOUT when F<Configure.pl> is run. + +=head1 SUBROUTINES + +=head2 C<print_introduction()> + +=over 4 + +=item * Purpose + +Print the Parrot version, the version of F<Configure.pl>, the copyright notice +and a message introducing the Parrot configuration process. + +=item * Arguments + +One argument: String holding the Parrot version number (currently supplied by +C<Parrot::BuildUtil::parrot_version()>). + +=item * Return Value + +Implicit true value when C<print> returns successfully. + +=item * Comment + +=back + +=head2 C<print_conclusion()> + +=over 4 + +=item * Purpose + +Prints a message announcing the conclusion of the Parrot configuration process +and instructing the user to run F<make>. + +=item * Arguments + +One argument: String holding the version of F<make> located by the +configuration process. + +=item * Return Value + +Implicit true value when C<print> returns successfully. + +=item * Comment + +=back + +=head1 NOTES + +The functionality in this package was transferred from F<Configure.pl> by Jim +Keenan. + +=head1 SEE ALSO + +F<Configure.pl>. + +=cut + +# Local Variables: +# mode: cperl +# cperl-indent-level: 4 +# fill-column: 100 +# End: +# vim: expandtab shiftwidth=4: Added: trunk/t/configure/02-messages.t ============================================================================== --- (empty file) +++ trunk/t/configure/02-messages.t Sat Apr 7 12:59:19 2007 @@ -0,0 +1,100 @@ +#! perl +# Copyright (C) 2007, The Perl Foundation. +# $Id$ +# 02-messages.t + +use strict; +use warnings; + +BEGIN { + use FindBin qw($Bin); + use Cwd qw(cwd realpath); + realpath($Bin) =~ m{^(.*\/parrot)\/[^/]*\/[^/]*\/[^/]*$}; + our $topdir = $1; + if ( defined $topdir ) { + print "\nOK: Parrot top directory located\n"; + } + else { + $topdir = realpath($Bin) . "/../.."; + } + unshift @INC, qq{$topdir/lib}; +} +use Test::More tests => 10; +use Carp; +use_ok('Parrot::Configure::Messages', qw| + print_introduction + print_conclusion +| ); +use_ok("Parrot::IO::Capture::Mini"); + +my $parrot_version = '0.4.10'; +my $make_version = 'gnu make'; + +{ + my ($tie, $rv, $msg); + $tie = tie *STDOUT, "Parrot::IO::Capture::Mini" + or croak "Unable to tie"; + $rv = print_introduction($parrot_version); + ok($rv, "print_introduction() returned true"); + $msg = $tie->READLINE; + + # Following test is definitive. + like($msg, qr/$parrot_version/, + "Message included Parrot version number supplied as argument"); + + # Following tests are NOT definitive. They will break if content of + # strings printed by function is changed. + like($msg, qr/Parrot\sVersion/i, + "Message included string 'Parrot version'"); + like($msg, qr/Configure/i, + "Message included string 'Configure'"); + like($msg, qr/Copyright/i, + "Message included copyright notice"); + undef $tie; +} + +{ + my ($tie, $rv, $msg); + $tie = tie *STDOUT, "Parrot::IO::Capture::Mini" + or croak "Unable to tie"; + $rv = print_conclusion($make_version); + ok($rv, "print_conclusion() returned true"); + $msg = $tie->READLINE; + + # Following test is definitive. + like($msg, qr/$make_version/, + "Message included make version supplied as argument"); + + undef $tie; +} + +# print_conclusion($make_version); + +pass("Completed all tests in $0"); + +################### DOCUMENTATION ################### + +=head1 NAME + +02-messages.t - test Parrot::Configure::Messages + +=head1 SYNOPSIS + + % prove t/configure/components/02-messages.t + +=head1 DESCRIPTION + +The files in this directory test functionality used by F<Configure.pl>. + +The tests in this file test subroutines exported by +Parrot::Configure::Messages. + +=head1 AUTHOR + +James E Keenan + +=head1 SEE ALSO + +Parrot::Configure::Messages, F<Configure.pl>. + +=cut
