Perl 5 version 32.0 documentation

App::Prove

NAME

App::Prove - Implements the prove command.

VERSION

Version 3.42

DESCRIPTION

Test::Harness provides a command, prove , which runs a TAP based test suite and prints a report. The prove command is a minimal wrapper around an instance of this module.

SYNOPSIS

  1. use App::Prove;
  2. my $app = App::Prove->new;
  3. $app->process_args(@ARGV);
  4. $app->run;

METHODS

Class Methods

new

Create a new App::Prove . Optionally a hash ref of attribute initializers may be passed.

state_class

Getter/setter for the name of the class used for maintaining state. This class should either subclass from App::Prove::State or provide an identical interface.

state_manager

Getter/setter for the instance of the state_class .

add_rc_file

  1. $prove->add_rc_file('myproj/.proverc');

Called before process_args to prepend the contents of an rc file to the options.

process_args

  1. $prove->process_args(@args);

Processes the command-line arguments. Attributes will be set appropriately. Any filenames may be found in the argv attribute.

Dies on invalid arguments.

run

Perform whatever actions the command line args specified. The prove command line tool consists of the following code:

  1. use App::Prove;
  2. my $app = App::Prove->new;
  3. $app->process_args(@ARGV);
  4. exit( $app->run ? 0 : 1 ); # if you need the exit code

require_harness

Load a harness replacement class.

  1. $prove->require_harness($for => $class_name);

print_version

Display the version numbers of the loaded TAP::Harness and the current Perl.

Attributes

After command line parsing the following attributes reflect the values of the corresponding command line switches. They may be altered before calling run .

  • archive
  • argv
  • backwards
  • blib
  • color
  • directives
  • dry
  • exec
  • extensions
  • failures
  • comments
  • formatter
  • harness
  • ignore_exit
  • includes
  • jobs
  • lib
  • merge
  • modules
  • parse
  • plugins
  • quiet
  • really_quiet
  • recurse
  • rules
  • show_count
  • show_help
  • show_man
  • show_version
  • shuffle
  • state
  • state_class
  • taint_fail
  • taint_warn
  • test_args
  • timer
  • verbose
  • warnings_fail
  • warnings_warn
  • tapversion
  • trap

PLUGINS

App::Prove 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 -Pplugin switch, eg:

  1. prove -PMyPlugin

This will search for a module named App::Prove::Plugin::MyPlugin , or failing that, MyPlugin . If the plugin can't be found, prove will complain & exit.

You can pass an argument to your plugin by appending an = after the plugin name, eg -PMyPlugin=foo . You can pass multiple arguments using commas:

  1. prove -PMyPlugin=foo,bar,baz

These are passed in to your plugin's load() class method (if it has one), along with a reference to the App::Prove object that is invoking your plugin:

  1. sub load {
  2. my ($class, $p) = @_;
  3. my @args = @{ $p->{args} };
  4. # @args will contain ( 'foo', 'bar', 'baz' )
  5. $p->{app_prove}->do_something;
  6. ...
  7. }

Note that the user's arguments are also passed to your plugin's import() function as a list, eg:

  1. sub import {
  2. my ($class, @args) = @_;
  3. # @args will contain ( 'foo', 'bar', 'baz' )
  4. ...
  5. }

This is for backwards compatibility, and may be deprecated in the future.

Sample Plugin

Here's a sample plugin, for your reference:

  1. package App::Prove::Plugin::Foo;
  2. # Sample plugin, try running with:
  3. # prove -PFoo=bar -r -j3
  4. # prove -PFoo -Q
  5. # prove -PFoo=bar,My::Formatter
  6. use strict;
  7. use warnings;
  8. sub load {
  9. my ($class, $p) = @_;
  10. my @args = @{ $p->{args} };
  11. my $app = $p->{app_prove};
  12. print "loading plugin: $class, args: ", join(', ', @args ), "\n";
  13. # turn on verbosity
  14. $app->verbose( 1 );
  15. # set the formatter?
  16. $app->formatter( $args[1] ) if @args > 1;
  17. # print some of App::Prove's state:
  18. for my $attr (qw( jobs quiet really_quiet recurse verbose )) {
  19. my $val = $app->$attr;
  20. $val = 'undef' unless defined( $val );
  21. print "$attr: $val\n";
  22. }
  23. return 1;
  24. }
  25. 1;

SEE ALSO

prove, TAP::Harness