TAP::Parser::SourceHandler::pgTAP(3pm) | User Contributed Perl Documentation | TAP::Parser::SourceHandler::pgTAP(3pm) |
TAP::Parser::SourceHandler::pgTAP - Stream TAP from pgTAP test scripts
In Build.PL for your application with pgTAP tests in t/*.pg:
Module::Build->new( 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', }, )->create_build_script;
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', }}); $source->assemble_meta; my $class = 'TAP::Parser::SourceHandler::pgTAP'; my $vote = $class->can_handle( $source ); my $iter = $class->make_iterator( $source );
This source handler executes pgTAP tests. It does two things:
Unless you're writing a plugin or subclassing TAP::Parser, you probably won't need to use this module directly.
If you just want to write tests with pgTAP <https://pgtap.org/>, here's how:
make TAPSCHEMA=tap make install psql -U postgres -d try -f pgtap.sql
BEGIN; SET search_path = public,tap,pg_catalog; SELECT plan(1); SELECT pass('This should pass!'); SELECT * FROM finish(); ROLLBACK;
Note how "search_path" has been set so that the pgTAP functions can be found in the "tap" schema. Consult the extensive pgTAP documentation <https://pgtap.org/documentation.html> for a comprehensive list of test functions.
prove --source Perl \ --ext .t --ext .pg \ --source pgTAP --pgtap-option dbname=try \ --pgtap-option username=postgres \ --pgtap-option suffix=.pg
This will run both your Perl .t tests and your pgTAP .pg tests all together. You can also use pg_prove to run just the pgTAP tests like so:
pg_prove -d try -U postgres t/
Module::Build->new( module_name => 'MyApp', test_file_exts => [qw(.t .pg)], use_tap_harness => 1, configure_requires => { 'Module::Build' => '0.30', }, 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', }, )->create_build_script;
The "use_tap_harness" parameter is optional, since it's implicitly set by the use of the "tap_harness_args" parameter. All the other parameters are required as you see here. See the documentation for "make_iterator()" for a complete list of options to the "pgTAP" key under "sources".
And that's it. Now get testing!
"can_handle"
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 a "suffix" config 0.9 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.
"make_iterator"
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:
This module is managed in an open GitHub repository <https://github.com/theory/tap-parser-sourcehandler-pgtap/>. 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 <https://github.com/theory/tap-parser-sourcehandler-pgtap/issues> or email <mailto:bug-tap-parser-sourcehandler-pgtap@rt.cpan.org> a report!
David E. Wheeler <dwheeler@cpan.org>
Copyright (c) 2010-2022 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.
2022-11-27 | perl v5.36.0 |