1Test::SQL::Translator(3U)ser Contributed Perl DocumentatiToenst::SQL::Translator(3)
2
3
4
6 Test::SQL::Translator - Test::More test functions for the Schema
7 objects.
8
10 # t/magic.t
11
12 use FindBin '$Bin';
13 use Test::More;
14 use Test::SQL::Translator;
15
16 # Run parse
17 my $sqlt = SQL::Translator->new(
18 parser => "Magic",
19 filename => "$Bin/data/magic/test.magic",
20 ...
21 );
22 ...
23 my $schema = $sqlt->schema;
24
25 # Test the table it produced.
26 table_ok( $schema->get_table("Customer"), {
27 name => "Customer",
28 fields => [
29 {
30 name => "CustomerID",
31 data_type => "INT",
32 size => 12,
33 default_value => undef,
34 is_nullable => 0,
35 is_primary_key => 1,
36 },
37 {
38 name => "bar",
39 data_type => "VARCHAR",
40 size => 255,
41 is_nullable => 0,
42 },
43 ],
44 constraints => [
45 {
46 type => "PRIMARY KEY",
47 fields => "CustomerID",
48 },
49 ],
50 indices => [
51 {
52 name => "barindex",
53 fields => ["bar"],
54 },
55 ],
56 });
57
59 Provides a set of Test::More tests for Schema objects. Testing a parsed
60 schema is then as easy as writing a perl data structure describing how
61 you expect the schema to look. Also provides maybe_plan for
62 conditionally running tests based on their dependencies.
63
64 The data structures given to the test subs don't have to include all
65 the possible values, only the ones you expect to have changed. Any left
66 out will be tested to make sure they are still at their default value.
67 This is a usefull check that you your parser hasn't accidentally set
68 schema values you didn't expect it to.
69
70 For an example of the output run the t/16xml-parser.t test.
71
73 All the tests take a first arg of the schema object to test, followed
74 by a hash ref describing how you expect that object to look (you only
75 need give the attributes you expect to have changed from the default).
76 The 3rd arg is an optional test name to pre-pend to all the generated
77 test names.
78
79 table_ok
80 field_ok
81 constraint_ok
82 index_ok
83 view_ok
84 trigger_ok
85 procedure_ok
87 The "maybe_plan" function handles conditionally running an individual
88 test. It is here to enable running the test suite even when
89 dependencies are missing; not having (for example) GraphViz installed
90 should not keep the test suite from passing.
91
92 "maybe_plan" takes the number of tests to (maybe) run, and a list of
93 modules on which test execution depends:
94
95 maybe_plan(180, 'SQL::Translator::Parser::MySQL');
96
97 If one of "SQL::Translator::Parser::MySQL"'s dependencies does not
98 exist, then the test will be skipped.
99
101 table_ok, field_ok, constraint_ok, index_ok, view_ok, trigger_ok,
102 procedure_ok, maybe_plan
103
105 Test the tests!
106 Test Count Constants
107 Constants to give the number of tests each *_ok sub uses. e.g. How
108 many tests does field_ok run? Can then use these to set up the test
109 plan easily.
110
111 Test skipping
112 As the test subs wrap up lots of tests in one call you can't skip
113 idividual tests only whole sets e.g. a whole table or field. We
114 could add skip_* items to the test hashes to allow per test skips.
115 e.g.
116
117 skip_is_primary_key => "Need to fix primary key parsing.",
118
119 yaml test specs
120 Maybe have the test subs also accept yaml for the test hash ref as
121 its a much nicer for writing big data structures. We can then
122 define tests as in input schema file and test yaml file to compare
123 it against.
124
127 Mark D. Addison <mark.addison@itn.co.uk>, Darren Chamberlain
128 <darren@cpan.org>.
129
130 Thanks to Ken Y. Clark for the original table and field test code taken
131 from his mysql test.
132
134 perl(1), SQL::Translator, SQL::Translator::Schema, Test::More.
135
136
137
138perl v5.12.0 2009-09-28 Test::SQL::Translator(3)