Skip to content

Commit

Permalink
Get rid of YAML on the command-line.
Browse files Browse the repository at this point in the history
Options for sources loaded via `prove --source $source_name` may now be
specified via `--$source_name-option` options. They take key/value pairs in
the normal way of Getopt::Long hash options. An example:

    prove --source MyCustom \
          --source Perl --perl-option 'foo=bar baz' --perl-option avg=0.278 \
          --source File --file-option extensions=.txt --file-option extensions=.tmp t

I think that this is much better than allowing YAML on the command-line. I'd
be open to shortening those names somehow, though. Maybe `--pgtap-opt`?
  • Loading branch information
theory committed Nov 4, 2009
1 parent 18af31c commit 6efbb43
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
10 changes: 5 additions & 5 deletions bin/prove
Expand Up @@ -291,12 +291,12 @@ parser interprets particular I<sources> of TAP.
If you want to provide config to the source you can use:
prove --source MyCustom \
--source 'Perl: {foo: bar baz, avg: 0.278}' \
--source 'File: {extensions: [.txt, .tmp]}' t
--source Perl --perl-option 'foo=bar baz' --perl-option avg=0.278 \
--source File --file-option extensions=.txt --file-option extensions=.tmp t
In this case you must have L<YAML> installed, and the configuration you pass
must be a valid YAML string (a C<"\n"> is appended to whatever you pass), or an
error will be thrown.
Each C<--$source-option> option must specify a key/value pair separated by an
C<=>. If an option can take multiple values, just specify it multiple times,
as with the C<extensions=> examples above.
All C<--sources> are combined into a hash, and passed to L<TAP::Harness/new>'s
C<sources> parameter.
Expand Down
36 changes: 16 additions & 20 deletions lib/App/Prove.pm
Expand Up @@ -197,7 +197,7 @@ sub process_args {

{
local @ARGV = @args;
Getopt::Long::Configure( 'no_ignore_case', 'bundling' );
Getopt::Long::Configure(qw(no_ignore_case bundling pass_through));

# Don't add coderefs to GetOptions
GetOptions(
Expand Down Expand Up @@ -420,25 +420,21 @@ sub _load_extensions {
sub _parse_source {
my ( $self, $handler ) = @_;

my ($name, $config);
if ($handler =~ /\W/) {
eval 'require YAML';
if (my $e = $@) {
die "couldn't parse sources '$handler': YAML not available";
}
my $hash;
eval { $hash = YAML::Load( $handler . "\n" ) };
if (my $e = $@) {
die "couldn't parse sources '$handler': $e";
}
($name) = keys %$hash;
$config = $hash->{$name};
} else {
$name = $handler;
$config = {};
}

return( $name, $config );
# Load any options.
(my $opt_name = lc $handler) =~ s/::/-/g;
local @ARGV = @{ $self->{argv} };
my %config;
Getopt::Long::GetOptions("$opt_name-option=s%" => sub {
my (undef, $k, $v) = @_;
if (exists $config{$k}) {
$config{$k} = [ $config{$k} ] unless ref $config{$k} eq 'ARRAY';
push @{ $config{$k} } => $v;
} else {
$config{$k} = $v;
}
});
$self->{argv} = \@ARGV;
return ($handler, \%config);
}

=head3 C<run>
Expand Down
8 changes: 6 additions & 2 deletions t/prove.t
Expand Up @@ -1121,9 +1121,13 @@ BEGIN { # START PLAN
skip => $HAS_YAML ? 0 : 1,
skip_reason => "YAML not available",
switches =>
[ '--source', 'Perl: {foo: bar baz, avg: 0.278}',
[ '--source', 'Perl',
'--perl-option', 'foo=bar baz',
'--perl-option', 'avg=0.278',
'--source', 'MyCustom',
'--source', 'File: {extensions: [.txt, .tmp]}',
'--source', 'File',
'--file-option', 'extensions=.txt',
'--file-option', 'extensions=.tmp',
$dummy_test ],
expect => {
sources =>
Expand Down

0 comments on commit 6efbb43

Please sign in to comment.