David E. Wheeler > TAP-Parser-SourceHandler-pgTAP > TAP::Parser::SourceHandler::pgTAP



Annotate this POD


View/Report Bugs
Module Version: 3.30   Source  

Name ^

TAP::Parser::SourceHandler::pgTAP - Stream TAP from pgTAP test scripts

Synopsis ^

In Build.PL for your application with pgTAP tests in t/*.pg:

      module_name        => 'MyApp',
      test_file_exts     => [qw(.t .pg)],
      use_tap_harness    => 1,
      tap_harness_args   => {
          sources => {
              Perl  => undef,
              pgTAP => {
                  dbname   => 'try',
                  username => 'postgres',
                  suffix   => '.pg',
      build_requires     => {
          'Module::Build'                     => '0.30',
          'TAP::Parser::SourceHandler::pgTAP' => '3.19',

If you're using prove:

  prove --source Perl \
        --ext .t --ext .pg \
        --source pgTAP --pgtap-option dbname=try \
                       --pgtap-option username=postgres \
                       --pgtap-option suffix=.pg

If you have only pgTAP tests, just use pg_prove:

  pg_prove --dbname try --username postgres

Direct use:

  use TAP::Parser::Source;
  use TAP::Parser::SourceHandler::pgTAP;

  my $source = TAP::Parser::Source->new->raw(\'mytest.pg');
  $source->config({ pgTAP => {
      dbname   => 'testing',
      username => 'postgres',
      suffix   => '.pg',

  my $class = 'TAP::Parser::SourceHandler::pgTAP';
  my $vote  = $class->can_handle( $source );
  my $iter  = $class->make_iterator( $source );

Description ^

This source handler executes pgTAP tests. It does two things:

  1. Looks at the TAP::Parser::Source passed to it to determine whether or not the source in question is in fact a pgTAP test ("can_handle").
  2. Creates an iterator that will call psql to run the pgTAP tests ("make_iterator").

Unless you're writing a plugin or subclassing TAP::Parser, you probably won't need to use this module directly.

Testing with pgTAP

If you just want to write tests with pgTAP, here's how:


Class Methods


  my $vote = $class->can_handle( $source );

Looks at the source to determine whether or not it's a pgTAP test and returns a score for how likely it is in fact a pgTAP test file. The scores are as follows:

  1    if it's not a file and starts with "pgsql:".
  1    if it has a suffix equal to that in the "suffix" config
  1    if its suffix is ".pg"
  0.8  if its suffix is ".sql"
  0.75 if its suffix is ".s"

The latter two scores are subject to change, so try to name your pgTAP tests ending in ".pg" or specify a suffix in the configuration to be sure.


  my $iterator = $class->make_iterator( $source );

Returns a new TAP::Parser::Iterator::Process for the source. $source->raw must be either a file name or a scalar reference to the file name -- or a string starting with "pgsql:", in which case the remainder of the string is assumed to be SQL to be executed inside the database.

The pgTAP tests are run by executing psql, the PostgreSQL command-line utility. A number of arguments are passed to it, many of which you can affect by setting up the source source configuration. The configuration must be a hash reference, and supports the following keys:


The path to the psql command. Defaults to simply "psql", which should work well enough if it's in your path.


The database to which to connect to run the tests. Defaults to the value of the $PGDATABASE environment variable or, if not set, to the system username.


The PostgreSQL username to use to connect to PostgreSQL. If not specified, no username will be used, in which case psql will fall back on either the $PGUSER environment variable or, if not set, the system username.


Specifies the host name of the machine to which to connect to the PostgreSQL server. If the value begins with a slash, it is used as the directory for the Unix-domain socket. Defaults to the value of the $PGDATABASE environment variable or, if not set, the local host.


Specifies the TCP port or the local Unix-domain socket file extension on which the server is listening for connections. Defaults to the value of the $PGPORT environment variable or, if not set, to the port specified at the time psql was compiled, usually 5432.


Specifies a hash of printing options in the style of \pset in the psql program. See the psql documentation for details on the supported options.

See Also ^

Support ^

This module is managed in an open GitHub repository. Feel free to fork and contribute, or to clone git://github.com/theory/tap-parser-sourcehandler-pgtap.git and send patches!

Found a bug? Please post or email a report!

Author ^

David E. Wheeler <dwheeler@cpan.org>

Copyright and License ^

Copyright (c) 2010-2014 David E. Wheeler. Some Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: