Author: jkeenan
Date: Thu Aug 7 16:40:08 2008
New Revision: 30111
Modified:
branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/File.pm
branches/scriptconfigure/t/configure/062-options_conf_file.t
Log:
P::C::O::Conf::File: Eliminate some unreachable branches. t/configure/062:
Add tests for previously uncovered branches.
Modified: branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/File.pm
==============================================================================
--- branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/File.pm
(original)
+++ branches/scriptconfigure/lib/Parrot/Configure/Options/Conf/File.pm Thu Aug
7 16:40:08 2008
@@ -12,7 +12,7 @@
$parrot_version
$svnid
);
-use Data::Dumper;$Data::Dumper::Indent = 1;
+#use Data::Dumper;$Data::Dumper::Indent = 1;
use File::Spec;
use lib qw( lib );
use Parrot::BuildUtil;
@@ -129,20 +129,14 @@
my @steplines = split /\n/, $steps;
my @steps_list = ();
LINE: foreach my $line (@steplines) {
- next unless ($line =~ /^(\w+::\w+)(?:\s+(\S+\s+)*(\S+))?$/);
+ next unless ($line =~ /^(\w+::\w+)(?:\s+([-=\w]+\s+)*([-=\w]+))?$/);
my $step = $1;
push @steps_list, $step;
next LINE unless $3;
my $opts_string = $2 ? qq{$2$3} : $3;
my @opts = split /\s+/, $opts_string;
foreach my $el (@opts) {
- my ( $key, $value );
- if ($el =~ m/([-\w]+)(?:=(.*))?/) {
- ( $key, $value ) = ($1, $2);
- }
- if (! defined $key) {
- die "Unable to process key $key in step $step in configuration
data file $data->{file}: $!"
- }
+ my ( $key, $value ) = $el =~ m/([-\w]+)(?:=(.*))?/;
unless ( $optsref->{$key} ) {
die qq/Invalid option "$key". See "perl Configure.pl --help"
for options valid within a configuration file\n/;
}
Modified: branches/scriptconfigure/t/configure/062-options_conf_file.t
==============================================================================
--- branches/scriptconfigure/t/configure/062-options_conf_file.t
(original)
+++ branches/scriptconfigure/t/configure/062-options_conf_file.t Thu Aug
7 16:40:08 2008
@@ -5,7 +5,7 @@
use strict;
use warnings;
-use Test::More qw(no_plan); # tests => 9;
+use Test::More qw(no_plan); # tests => 8;
#use Carp;
#use Cwd;
#use Data::Dumper;
@@ -23,21 +23,27 @@
);
#use IO::CaptureOutput qw| capture |;
-my $variables = <<END;
+my ($variables, $general, $substitutions);
+my $data = {};;
+my %valid_step_options;
+my ($steps, $steps_list_ref);
+my $cc;
+
+$variables = <<END;
CC=/usr/bin/gcc
#CX=/usr/bin/g++
ABC=abc
END
-my $substitutions =
+$substitutions =
Parrot::Configure::Options::Conf::File::_get_substitutions($variables);
is_deeply($substitutions,
{ CC => '/usr/bin/gcc', ABC => 'abc' },
"Got expected substitutions"
);
-my $general = <<END;
+$general = <<END;
cc=\$CC
this=will not=work
#abc=abc
@@ -47,14 +53,13 @@
configure_trace
END
-my $data = shift;
$data->{debugging} = 1;
$data->{maintainer} = undef;
-my %valid_step_options = map {$_ => 1} @shared_valid_options;
+%valid_step_options = map {$_ => 1} @shared_valid_options;
$data = Parrot::Configure::Options::Conf::File::_set_general(
$data, $substitutions, $general, \%valid_step_options
);
-my $cc = q{/usr/bin/gcc};
+$cc = q{/usr/bin/gcc};
is_deeply($data,
{
debugging => 1,
@@ -67,18 +72,17 @@
"Got expected return value for _set_general()"
);
-my $steps = <<END;
+$steps = <<END;
init::manifest nomanicheck
init::defaults
-auto::icu without-icu
+auto::icu without-icu fatal-step
#auto::perldoc
END
-my $steps_list_ref;
($data, $steps_list_ref) = Parrot::Configure::Options::Conf::File::_set_steps(
- $data, $steps, \%valid_step_options);
+ $data, $steps, \%valid_step_options);
is_deeply($data,
{
debugging => 1,
@@ -89,6 +93,7 @@
'verbose-step' => 'init::hints',
nomanicheck => 1,
'without-icu' => 1,
+ 'fatal-step' => 'auto::icu',
},
"Got expected return value for 'data' from _set_steps()"
);
@@ -101,6 +106,89 @@
"Got expected list of configuration steps"
);
+##### Test of bad variable for substitution
+
+$variables = <<END;
+#CC=/usr/bin/gcc
+#CX=/usr/bin/g++
+
+ABC=abc
+END
+
+$substitutions =
+ Parrot::Configure::Options::Conf::File::_get_substitutions($variables);
+$general = <<END;
+cc=\$CC
+this=will not=work
+#abc=abc
+
+verbose
+verbose-step=init::hints
+configure_trace
+END
+
+undef $data;
+$data->{debugging} = 1;
+$data->{maintainer} = undef;
+$data->{file} = q{Configure.pl};
+%valid_step_options = map {$_ => 1} @shared_valid_options;
+eval { $data = Parrot::Configure::Options::Conf::File::_set_general(
+ $data, $substitutions, $general, \%valid_step_options
+); };
+like($@, qr/Bad variable substitution in $data->{file}/,
+ "Got expected message when _set_general() died");
+$data = {};
+
+##### Test of bad option
+
+$variables = <<END;
+CC=/usr/bin/gcc
+#CX=/usr/bin/g++
+
+ABC=abc
+END
+
+$substitutions =
+ Parrot::Configure::Options::Conf::File::_get_substitutions($variables);
+$general = <<END;
+cc=\$CC
+this=will not=work
+#abc=abc
+
+verbose
+verbose-step=init::hints
+configure_trace
+END
+
+is_deeply($substitutions,
+ { CC => '/usr/bin/gcc', ABC => 'abc' },
+ "Got expected substitutions"
+);
+$data->{debugging} = 1;
+$data->{maintainer} = undef;
+$data->{file} = q{Configure.pl};
+%valid_step_options = map {$_ => 1} @shared_valid_options;
+$data = Parrot::Configure::Options::Conf::File::_set_general(
+ $data, $substitutions, $general, \%valid_step_options
+);
+
+$steps = <<END;
+
+init::manifest nomanicheck
+init::defaults
+auto::icu without-icu fatal-step
+auto::gmp dizzy=like-a-fox
+
+#auto::perldoc
+END
+
+eval {
+ ($data, $steps_list_ref) =
+ Parrot::Configure::Options::Conf::File::_set_steps(
+ $data, $steps, \%valid_step_options);
+};
+like($@, qr/dizzy/, "Invalid option correctly detected");
+
pass("Completed all tests in $0");
################### DOCUMENTATION ###################