Permalink
Browse files

Implement option of fully silent configuration.

Expand scope of '--silent' command-line option to handle pre- and
post-configuration messages.  Cf.: http://trac.parrot.org/parrot/ticket/1897.
rfw++ for spotting previous partial implementation..
  • Loading branch information...
1 parent 5d8c6f0 commit 46c8406019ceeb9c5b70dbcc4c917e794fe04289 @jkeenan jkeenan committed Dec 31, 2010
Showing with 48 additions and 20 deletions.
  1. +5 −2 Configure.pl
  2. +16 −12 lib/Parrot/Configure/Messages.pm
  3. +27 −6 t/configure/002-messages.t
View
@@ -5,6 +5,7 @@
use 5.008;
use strict;
use warnings;
+use Data::Dumper;$Data::Dumper::Indent=1;
use lib 'lib';
use Parrot::Configure;
@@ -41,6 +42,7 @@
}
);
exit(1) unless defined $args;
+#print STDERR Dumper $args;
my $opttest = Parrot::Configure::Options::Test->new($args);
@@ -51,7 +53,8 @@
my $parrot_version = $Parrot::Configure::Options::Conf::parrot_version;
# from Parrot::Configure::Messages
-print_introduction($parrot_version);
+print_introduction($parrot_version)
+ unless $args->{silent};
# Update revision number if needed
Parrot::Revision::update();
@@ -79,7 +82,7 @@
my $make = $conf->data->get('make');
# from Parrot::Configure::Messages
-( print_conclusion( $conf, $make ) ) ? exit 0 : exit 1;
+( print_conclusion( $conf, $make, $args ) ) ? exit 0 : exit 1;
################### DOCUMENTATION ###################
@@ -30,8 +30,7 @@ END
}
sub print_conclusion {
- my $conf = shift;
- my $make = shift;
+ my ($conf, $make, $args) = @_;
my @failed_steps = @{ $conf->{log} };
my @logged_failed_steps = ();
for (my $i = 1; $i <= $#failed_steps; $i++) {
@@ -40,19 +39,20 @@ sub print_conclusion {
}
}
if ( scalar ( @logged_failed_steps ) ) {
- print "\nDuring configuration the following steps failed:\n";
+ print STDERR "\nDuring configuration the following steps failed:\n";
foreach my $fail (@logged_failed_steps) {
my $msg = sprintf " %02d: %s\n", (
$fail->[0],
$fail->[1]->{step},
);
- print $msg;
+ print STDERR $msg;
}
- print "You should diagnose and fix these errors before calling '$make'\n";
+ print STDERR "You should diagnose and fix these errors before calling '$make'\n";
return;
}
else {
- print <<"END";
+ unless ( $args->{silent} ) {
+ print <<"END";
Okay, we're done!
@@ -63,6 +63,7 @@ Happy Hacking,
The Parrot Team
END
+ }
return 1;
}
}
@@ -84,7 +85,7 @@ Parrot::Configure::Messages - Introduce and conclude Parrot configuration proces
print_introduction($parrot_version);
- print_conclusion($make_version);
+ $rv = print_conclusion( $conf, $make, $args );
=head1 DESCRIPTION
@@ -126,14 +127,17 @@ and instructing the user to run F<make>.
=item * Arguments
-One argument: String holding the version of F<make> located by the
-configuration process.
+ $rv = print_conclusion( $conf, $make, $args );
-=item * Return Value
+List of three arguments: the Parrot::Configure object; the string holding the
+version of F<make> located by the configuration process; and the hash
+reference which is the first element in the list returned by
+C<Parrot::Configure::Options::process_options()>.
-Implicit true value when C<print> returns successfully.
+=item * Return Value
-=item * Comment
+Returns true value when configuration is successful and message has been
+printed. Otherwise return value is undefined.
=back
View
@@ -5,7 +5,7 @@
use strict;
use warnings;
use Carp;
-use Test::More tests => 10;
+use Test::More tests => 13;
use lib qw( lib );
use Parrot::Configure::Messages qw|
print_introduction
@@ -40,8 +40,9 @@ my $make_version = 'gnu make';
my $pseudo_conf = {
log => [],
};
+ my $args = {};
capture(
- sub { $rv = print_conclusion($pseudo_conf, $make_version); },
+ sub { $rv = print_conclusion($pseudo_conf, $make_version, $args); },
\$stdout,
);
ok( $rv, "print_conclusion() returned true" );
@@ -52,23 +53,43 @@ my $make_version = 'gnu make';
}
{
- my ( $rv, $stdout );
+ my ( $rv, $stdout, $stderr );
+ my $pseudo_conf = {
+ log => [],
+ };
+ my $args = { silent => 1 };
+ capture(
+ sub { $rv = print_conclusion($pseudo_conf, $make_version, $args); },
+ \$stdout,
+ \$stderr,
+ );
+ ok( $rv, "print_conclusion() returned true" );
+
+ # Following test is definitive.
+ ok( ! $stdout, "Configure.pl operated silently, as requested" );
+}
+
+{
+ my ( $rv, $stdout, $stderr );
my $pseudo_conf = {
log => [
undef,
{ step => q{init::manifest} },
],
};
+ my $args = {};
capture(
- sub { $rv = print_conclusion($pseudo_conf, $make_version); },
+ sub { $rv = print_conclusion($pseudo_conf, $make_version, $args); },
\$stdout,
+ \$stderr,
);
ok(! defined $rv, "print_conclusion() returned undefined value" );
- like( $stdout,
+ ok( ! $stdout,
+ "Because of the error, nothing printed to standard output");
+ like( $stderr,
qr/During configuration the following steps failed:.*init::manifest/s,
"Got expected message re configuration step failure" );
-
}
pass("Completed all tests in $0");

0 comments on commit 46c8406

Please sign in to comment.