Toby Inkster avatar Toby Inkster committed fa0e0a9

auto-prove function

Comments (0)

Files changed (2)

lib/P5U/Command/AutoProve.pm

+package P5U::Command::AutoProve;
+
+use 5.010;
+use strict;
+use utf8;
+use P5U-command;
+
+BEGIN {
+	$P5U::Command::AutoProve::AUTHORITY = 'cpan:TOBYINK';
+	$P5U::Command::AutoProve::VERSION   = '0.001';
+};
+
+use Cwd 'cwd';
+
+use constant {
+	abstract    => q[show CPAN testers statistics for a distribution],
+	usage_desc  => q[%c auto-prove %o],
+};
+
+sub command_names
+{
+	qw(
+		auto-prove
+		ap
+	);
+}
+
+sub opt_spec
+{
+	require P5U::Lib::AutoProve;
+	return (
+		[ xt => 'run "xt" tests too' ],
+		map { [ $_ => 'passed through to "prove"' ] } P5U::Lib::AutoProve->opts
+	);
+}
+
+sub execute
+{
+	require P5U::Lib::AutoProve;
+	my ($self, $opt, $args) = @_;
+	$self->usage_error("This command takes no non-option arguments.")
+		if @$args;
+	my ($wd, $app) = P5U::Lib::AutoProve::->get_app(%$opt);
+	my $orig = cwd;
+	
+	chdir $wd;
+	$app->run;
+	chdir $orig;
+}
+
+1;

lib/P5U/Lib/AutoProve.pm

+package P5U::Lib::AutoProve;
+
+BEGIN {
+	$P5U::Lib::AutoProve::AUTHORITY = 'cpan:TOBYINK';
+	$P5U::Lib::AutoProve::VERSION   = '0.001';
+};
+
+use 5.010;
+use strict;
+use utf8;
+
+use App::Prove;
+use Cwd 'cwd';
+use Object::AUTHORITY;
+
+sub change_to_suitable_directory
+{
+	my ($self) = @_;
+	
+	while (-d '..' and not -d 't')
+	{
+		chdir '..';
+	}
+
+	unless (-d 't')
+	{
+		die "No suitable test suite found.\n";
+	}
+
+	return cwd;
+}
+
+sub opts
+{
+	qw(
+		recurse|r timer verbose|v color|c dry|D failures|f comments|o fork
+		ignore-exit merge|m shuffle|s reverse normalize T t W w jobs|j=i
+	);
+}
+
+sub build_option_args
+{
+	my ($self, %opt) = @_;
+	my $jobs = delete $opt{jobs};
+	
+	my @args =
+		map { "--$_" }
+		sort keys %opt;
+	
+	push @args, "--jobs=$jobs" if $jobs;
+	
+	return @args;
+}
+
+sub build_lib_args
+{
+	map { "-I$_" } grep { -d $_ } qw( blib/lib inc lib t/lib xt/lib );
+}
+
+sub get_app
+{
+	my ($self, %opt) = @_;
+
+	my $do_author_tests = delete $opt{xt};
+
+	my $origwd = cwd;
+	my $cwd    = $self->change_to_suitable_directory;
+	print "Found suitable test suite within directory '$cwd'.\n";
+
+	my @args = $self->build_option_args(%opt);
+	push @args, $self->build_lib_args;
+	
+	push @args, 't'  if -d 't';
+	push @args, 'xt' if -d 'xt' && $do_author_tests;
+	
+	chdir $origwd;	
+
+	print join(q{ }, prove => @args), "\n"
+		if $opt{verbose};
+	
+	my $app = App::Prove->new;
+	$app->process_args(@args);
+	return ($cwd, $app);
+}
+
+1;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.