# New Ticket Created by James Keenan
# Please include the string: [perl #42305]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=42305 >
This patch transfers one aspect of Configure.pl's functionality --
the user-friendly messages it print to STDOUT at the beginning and
end of the configuration process -- out of that script and places it
in a new package: lib/Parrot/Configure/Messages.pm.
Parrot::Configure::Options exports two subroutines on demand:
print_introduction
print_conclusion
By placing this functionality in subroutines exported by a class, we
can write tests for it using Perl's standard testing apparatus.
Accordingly, a test file is supplied as part of this patch:
t/configure/01-messages.t
This is the second in a series of patches which a number of Parrot
hackers and I will be submitting a series of patches which refactor
Configure.pl and the various Parrot::Configure::* classes. This
refactoring will be focused primarily on increasing the testability
-- and, by extension, the long-term maintainability -- of Parrot's
configuration code.
Assuming no bug reports are received, we will apply this patch to
trunk in approximately 3 days. Thank you very much.
kid51
Index: lib/Parrot/Configure/Messages.pm
===================================================================
--- lib/Parrot/Configure/Messages.pm (revision 0)
+++ lib/Parrot/Configure/Messages.pm (revision 0)
@@ -0,0 +1,132 @@
+# Copyright (C) 2001-2006, The Perl Foundation.
+# $Id: Messages.pm 17733 2007-03-25 16:38:06Z jkeenan $
+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:
Index: MANIFEST
===================================================================
--- MANIFEST (revision 17984)
+++ MANIFEST (working copy)
@@ -2213,6 +2213,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]
@@ -2753,6 +2754,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 []
Index: Configure.pl
===================================================================
--- Configure.pl (revision 17984)
+++ Configure.pl (working copy)
@@ -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,19 +294,9 @@
my %args = %$args;
-print <<"END";
-Parrot Version $parrot_version Configure 2.0
-Copyright (C) 2001-2007, The Perl Foundation.
+# from Parrot::Configure::Messages
+print_introduction($parrot_version);
-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
-
# EDIT HERE TO ADD NEW TESTS
my @steps = qw(
init::manifest
@@ -386,21 +380,10 @@
}
# tell users what to do next
-my $make = $conf->data->get('make');
-print <<"END";
+# from Parrot::Configure::Messages
+print_conclusion($conf->data->get('make'));
-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
-
exit(0);
# Local Variables:
Index: t/configure/02-messages.t
===================================================================
--- t/configure/02-messages.t (revision 0)
+++ t/configure/02-messages.t (revision 0)
@@ -0,0 +1,100 @@
+#! perl
+# Copyright (C) 2007, The Perl Foundation.
+# $Id: 02-messages.t 17798 2007-03-28 01:15:57Z jkeenan $
+# 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