App::Prove - Implements the command.prove
Version 3.36
Test::Harness provides a command, , which runs a TAP based test suite and prints a report. The prove command is a minimal wrapper around an instance of this module.prove
use App::Prove;
my $app = App::Prove->new;
$app->process_args(@ARGV);
$app->run;
newCreate a new . Optionally a hash ref of attribute initializers may be passed.App::Prove
state_classGetter/setter for the name of the class used for maintaining state. This class should either subclass from or provide an identical interface.App::Prove::State
state_managerGetter/setter for the instance of the .state_class
add_rc_file $prove->add_rc_file('myproj/.proverc');
Called before to prepend the contents of an rc file to the options.process_args
process_args $prove->process_args(@args);
Processes the command-line arguments. Attributes will be set appropriately. Any filenames may be found in the attribute.argv
Dies on invalid arguments.
runPerform whatever actions the command line args specified. The command line tool consists of the following code:prove
use App::Prove;
my $app = App::Prove->new;
$app->process_args(@ARGV);
exit( $app->run ? 0 : 1 ); # if you need the exit code
require_harnessLoad a harness replacement class.
$prove->require_harness($for => $class_name);
print_versionDisplay the version numbers of the loaded TAP::Harness and the current Perl.
After command line parsing the following attributes reflect the values of the corresponding command line switches. They may be altered before calling .run
archiveargvbackwardsblibcolordirectivesdryexecextensionsfailurescommentsformatterharnessignore_exitincludesjobslibmergemodulesparsepluginsquietreally_quietrecurserulesshow_countshow_helpshow_manshow_versionshufflestatestate_classtaint_failtaint_warntest_argstimerverbosewarnings_failwarnings_warntapversiontrap provides support for 3rd-party plugins. These are currently loaded at run-time, after arguments have been parsed (so you can not change the way arguments are processed, sorry), typically with the App::Prove switch, eg:-Pplugin
prove -PMyPlugin
This will search for a module named , or failing that, App::Prove::Plugin::MyPlugin. If the plugin can't be found, MyPlugin will complain & exit.prove
You can pass an argument to your plugin by appending an after the plugin name, eg =. You can pass multiple arguments using commas:-PMyPlugin=foo
prove -PMyPlugin=foo,bar,baz
These are passed in to your plugin's class method (if it has one), along with a reference to the load() object that is invoking your plugin:App::Prove
sub load {
my ($class, $p) = @_;
my @args = @{ $p->{args} };
# @args will contain ( 'foo', 'bar', 'baz' )
$p->{app_prove}->do_something;
...
}
Note that the user's arguments are also passed to your plugin's function as a list, eg:import()
sub import {
my ($class, @args) = @_;
# @args will contain ( 'foo', 'bar', 'baz' )
...
}
This is for backwards compatibility, and may be deprecated in the future.
Here's a sample plugin, for your reference:
package App::Prove::Plugin::Foo;
# Sample plugin, try running with:
# prove -PFoo=bar -r -j3
# prove -PFoo -Q
# prove -PFoo=bar,My::Formatter
use strict;
use warnings;
sub load {
my ($class, $p) = @_;
my @args = @{ $p->{args} };
my $app = $p->{app_prove};
print "loading plugin: $class, args: ", join(', ', @args ), "\n";
# turn on verbosity
$app->verbose( 1 );
# set the formatter?
$app->formatter( $args[1] ) if @args > 1;
# print some of App::Prove's state:
for my $attr (qw( jobs quiet really_quiet recurse verbose )) {
my $val = $app->$attr;
$val = 'undef' unless defined( $val );
print "$attr: $val\n";
}
return 1;
}
1;