Skip to content

Commit

Permalink
Let's try using a File::Spec function for testing for absoluteness. A…
Browse files Browse the repository at this point in the history
…dd a regression test for invalid value to '--prefix'.
  • Loading branch information
jkeenan authored and Reini Urban committed Sep 3, 2012
1 parent f1d2865 commit 1a0a31c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/Parrot/Configure/Options.pm
Expand Up @@ -9,6 +9,7 @@ our @EXPORT_OK = qw(
process_options process_options
); );
use Carp; use Carp;
use File::Spec;
use lib qw( lib ); use lib qw( lib );
use Parrot::Configure::Options::Conf::CLI (); use Parrot::Configure::Options::Conf::CLI ();
use Parrot::Configure::Options::Conf::File (); use Parrot::Configure::Options::Conf::File ();
Expand Down Expand Up @@ -92,8 +93,9 @@ sub _initial_pass {
unless ( $valid_opts{$key} ) { unless ( $valid_opts{$key} ) {
die qq/Invalid option "$key". See "perl $script --help" for valid options\n/; die qq/Invalid option "$key". See "perl $script --help" for valid options\n/;
} }
if ( $key eq 'prefix' and $value !~ m[^/] ) { if ( $key eq 'prefix' and
die qq/Relative path given to --prefix, please pass an absolute path\n/; ! File::Spec->file_name_is_absolute( $value) ) {
die qq/Relative path given to --prefix, please pass an absolute path/;
} }
if ( $options_components->{short_circuits}{$key} ) { if ( $options_components->{short_circuits}{$key} ) {
push @short_circuits_seen, $key; push @short_circuits_seen, $key;
Expand Down
12 changes: 11 additions & 1 deletion t/configure/001-options.t
Expand Up @@ -11,7 +11,7 @@ BEGIN {
our $topdir = realpath($Bin) . "/../.."; our $topdir = realpath($Bin) . "/../..";
unshift @INC, qq{$topdir/lib}; unshift @INC, qq{$topdir/lib};
} }
use Test::More tests => 51; use Test::More tests => 52;
use Carp; use Carp;
use Parrot::Configure::Options qw| process_options |; use Parrot::Configure::Options qw| process_options |;
use Parrot::Configure::Options::Conf::CLI (); use Parrot::Configure::Options::Conf::CLI ();
Expand Down Expand Up @@ -88,6 +88,16 @@ like(
"process_options() failed due to invalid 'mode' argument" "process_options() failed due to invalid 'mode' argument"
); );


eval { ($args, $step_list_ref) = process_options( {
argv => [ '--prefix=my/relative/path' ],
mode => q{configure}, } );
};
like(
$@,
qr/Relative path given to --prefix, please pass an absolute path/,
"process_options() failed due to relative path as value of 'prefix'",
);

($args, $step_list_ref) = process_options( ($args, $step_list_ref) = process_options(
{ {
mode => q{configure}, mode => q{configure},
Expand Down

0 comments on commit 1a0a31c

Please sign in to comment.