.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Test::SQL::Translator 3pm" .TH Test::SQL::Translator 3pm 2024-01-20 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Test::SQL::Translator \- Test::More test functions for the Schema objects. .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& # t/magic.t \& \& use FindBin \*(Aq$Bin\*(Aq; \& 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"], \& }, \& ], \& }); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" 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 \f(CW\*(C`maybe_plan\*(C'\fR for conditionally running tests based on their dependencies. .PP 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 useful check that you your parser hasn't accidentally set schema values you didn't expect it to. .PP For an example of the output run the \fIt/16xml\-parser.t\fR test. .SH Tests .IX Header "Tests" 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 prepend to all the generated test names. .SS table_ok .IX Subsection "table_ok" .SS field_ok .IX Subsection "field_ok" .SS constraint_ok .IX Subsection "constraint_ok" .SS index_ok .IX Subsection "index_ok" .SS view_ok .IX Subsection "view_ok" .SS trigger_ok .IX Subsection "trigger_ok" .SS procedure_ok .IX Subsection "procedure_ok" .SH "CONDITIONAL TESTS" .IX Header "CONDITIONAL TESTS" The \f(CW\*(C`maybe_plan\*(C'\fR 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. .PP \&\f(CW\*(C`maybe_plan\*(C'\fR takes the number of tests to (maybe) run, and a list of modules on which test execution depends: .PP .Vb 1 \& maybe_plan(180, \*(AqSQL::Translator::Parser::MySQL\*(Aq); .Ve .PP If one of \f(CW\*(C`SQL::Translator::Parser::MySQL\*(C'\fR's dependencies does not exist, then the test will be skipped. .PP Instead of a number of tests, you can pass \f(CW\*(C`undef\*(C'\fR if you're using \&\f(CWdone_testing()\fR, or \f(CW\*(Aqno_plan\*(Aq\fR if you don't want a plan at all. .SH EXPORTS .IX Header "EXPORTS" table_ok, field_ok, constraint_ok, index_ok, view_ok, trigger_ok, procedure_ok, maybe_plan .SH TODO .IX Header "TODO" .IP "Test the tests!" 4 .IX Item "Test the tests!" .PD 0 .IP "Test Count Constants" 4 .IX Item "Test Count Constants" .PD Constants to give the number of tests each \f(CW*_ok\fR sub uses. e.g. How many tests does \f(CW\*(C`field_ok\*(C'\fR run? Can then use these to set up the test plan easily. .IP "Test skipping" 4 .IX Item "Test skipping" As the test subs wrap up lots of tests in one call you can't skip individual tests only whole sets e.g. a whole table or field. We could add \f(CW\*(C`skip_*\*(C'\fR items to the test hashes to allow per test skips. e.g. .Sp .Vb 1 \& skip_is_primary_key => "Need to fix primary key parsing.", .Ve .IP "yaml test specs" 4 .IX Item "yaml test specs" Maybe have the test subs also accept yaml for the test hash ref as it is much nicer for writing big data structures. We can then define tests as in input schema file and test yaml file to compare it against. .SH AUTHOR .IX Header "AUTHOR" Mark D. Addison , Darren Chamberlain . .PP Thanks to Ken Y. Clark for the original table and field test code taken from his mysql test. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBperl\fR\|(1), SQL::Translator, SQL::Translator::Schema, Test::More.