Test::SQL::Translator - Test::More test functions for the Schema objects. |
Test::SQL::Translator - Test::More test functions for the Schema objects.
# t/magic.t
use FindBin '$Bin'; use Test::More; use Test::SQL::Translator;
# Run parse my $sqlt = SQL::Translator->new( parser => "Magic", filename => "$Bin/data/magic/test.magic", ... ); ... my $schema = $sqlt->schema;
# Test the table it produced. table_ok( $schema->get_table("Customer"), { name => "Customer", fields => [ { name => "CustomerID", data_type => "INT", size => 12, default_value => undef, is_nullable => 0, is_primary_key => 1, }, { name => "bar", data_type => "VARCHAR", size => 255, is_nullable => 0, }, ], constraints => [ { type => "PRIMARY KEY", fields => "CustomerID", }, ], indices => [ { name => "barindex", fields => ["bar"], }, ], });
Provides a set of Test::More tests for Schema objects. Testing a parsed schema is then as easy as writing a perl data structure describing how you expect the schema to look. Also provides maybe_plan for conditionally running tests based on their dependencies.
The data structures given to the test subs don't have to include all the possible values, only the ones you expect to have changed. Any left out will be tested to make sure they are still at their default value. This is a usefull check that you your parser hasn't accidentally set schema values you didn't expect it to.
For an example of the output run the t/16xml-parser.t test.
All the tests take a first arg of the schema object to test, followed by a hash ref describing how you expect that object to look (you only need give the attributes you expect to have changed from the default). The 3rd arg is an optional test name to pre-pend to all the generated test names.
The maybe_plan
function handles conditionally running an individual
test. It is here to enable running the test suite even when dependencies
are missing; not having (for example) GraphViz installed should not keep
the test suite from passing.
maybe_plan
takes the number of tests to (maybe) run, and a list of
modules on which test execution depends:
maybe_plan(180, 'SQL::Translator::Parser::MySQL');
If one of SQL::Translator::Parser::MySQL
's dependencies does not exist,
then the test will be skipped.
table_ok, field_ok, constraint_ok, index_ok, view_ok, trigger_ok, procedure_ok, maybe_plan
skip_is_primary_key => "Need to fix primary key parsing.",
Mark D. Addison <mark.addison@itn.co.uk>, Darren Chamberlain <darren@cpan.org>.
Thanks to Ken Y. Clark for the original table and field test code taken from his mysql test.
perl(1), SQL::Translator, SQL::Translator::Schema, Test::More.
Test::SQL::Translator - Test::More test functions for the Schema objects. |