TAP::Parser::SourceHandler::MyTAP - Stream TAP from MyTAP test scripts
In Build.PL for your application with MyTAP tests in t/*.my:
Module::Build->new( module_name => 'MyApp', test_file_exts => [qw(.t .my)], use_tap_harness => 1, tap_harness_args => { sources => { Perl => undef, MyTAP => { database => 'try', user => 'root', suffix => '.my', }, } }, build_requires => { 'Module::Build' => '0.30', 'TAP::Parser::SourceHandler::MyTAP' => '3.22', }, )->create_build_script;
If you're using prove:
prove
prove --source Perl \ --ext .t --ext .my \ --source MyTAP --mytap-option database=try \ --mytap-option user=root \ --mytap-option suffix=.my
If you have only MyTAP tests, just use my_prove:
my_prove
my_prove --database try --user root
Direct use:
use TAP::Parser::Source; use TAP::Parser::SourceHandler::MyTAP; my $source = TAP::Parser::Source->new->raw(\'mytest.my'); $source->config({ MyTAP => { database => 'testing', user => 'root', suffix => '.my', }}); $source->assemble_meta; my $class = 'TAP::Parser::SourceHandler::MyTAP'; my $vote = $class->can_handle( $source ); my $iter = $class->make_iterator( $source );
This source handler executes MyTAP MySQL tests. It does two things:
Looks at the TAP::Parser::Source passed to it to determine whether or not the source in question is in fact a MyTAP test ("can_handle").
Creates an iterator that will call mysql to run the MyTAP tests ("make_iterator").
mysql
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 MyTAP, here's how:
Download MyTAP and install it into your MySQL server:
mysql -u root < mytap.sql
Write your tests in files ending in .my in the t directory, right alongside your normal Perl .t tests. Here's a simple MyTAP test to get you started:
BEGIN; SELECT tap.plan(1); SELECT tap.pass('This should pass!'); CALL tap.finish(); ROLLBACK;
Note how the MyTAP functions are being called from the tap database.
tap
Run your tests with my_prove like so:
my_prove --database try --user root t/
Or, if you have Perl .t and MyTAP .my tests, run them all together with prove:
--ext .t --ext .my \ --source MyTAP --mytap-option database=try \ --mytap-option user=root \ --mytap-option suffix=.my =item *
Once you're sure that you've got the MyTAP tests working, modify your Build.PL script to allow ./Build test to run both the Perl and the MyTAP tests, like so:
Module::Build->new( module_name => 'MyApp', test_file_exts => [qw(.t .my)], use_tap_harness => 1, configure_requires => { 'Module::Build' => '0.30', }, tap_harness_args => { sources => { Perl => undef, MyTAP => { database => 'try', user => 'root', suffix => '.my', }, } }, build_requires => { 'Module::Build' => '0.30', 'TAP::Parser::SourceHandler::MyTAP' => '3.22', }, )->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 MyTAP key under sources.
use_tap_harness
tap_harness_args
make_iterator()
MyTAP
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 MyTAP test file and returns a score for how likely it is in fact a MyTAP test file. The scores are as follows:
1 if it has a suffix equal to that in a "suffix" config 1 if its suffix is ".my" 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 MyTAP tests ending in ".my" 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.
$source->raw
The MyTAP tests are run by executing mysql, the MySQL 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 mysql command. Defaults to simply "mysql", which should work well enough if it's in your path.
database
The database to which to connect to run the tests. Defaults to the system username.
user
The MySQL user to use to connect to MySQL. If not specified, no user will be used, in which case mysql will fall back on the system username.
password
The password to use to connect to MySQL. If not specified, no password will be used.
host
Specifies the host name of the machine to which to connect to the MySQL server. Defaults to the local host.
port
Specifies the TCP port or the local Unix-domain socket file extension on which the server is listening for connections. Defaults to the port specified at the time mysql was compiled, usually 3306.
TAP::Object
TAP::Parser
TAP::Parser::IteratorFactory
TAP::Parser::SourceHandler
TAP::Parser::SourceHandler::Executable
TAP::Parser::SourceHandler::Perl
TAP::Parser::SourceHandler::pgTAP
TAP::Parser::SourceHandler::File
TAP::Parser::SourceHandler::Handle
TAP::Parser::SourceHandler::RawTAP
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-mytap.git and send patches!
git://github.com/theory/tap-parser-sourcehandler-mytap.git
Found a bug? Please post or email a report!
David E. Wheeler <dwheeler@cpan.org>
Copyright (c) 2010-2016 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.
To install TAP::Parser::SourceHandler::MyTAP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm TAP::Parser::SourceHandler::MyTAP
CPAN shell
perl -MCPAN -e shell install TAP::Parser::SourceHandler::MyTAP
For more information on module installation, please visit the detailed CPAN module installation guide.