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 condition‐
62 ally 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
81 field_ok
82
83 constraint_ok
84
85 index_ok
86
87 view_ok
88
89 trigger_ok
90
91 procedure_ok
92
94 The "maybe_plan" function handles conditionally running an individual
95 test. It is here to enable running the test suite even when dependen‐
96 cies are missing; not having (for example) GraphViz installed should
97 not keep the test suite from passing.
98
99 "maybe_plan" takes the number of tests to (maybe) run, and a list of
100 modules on which test execution depends:
101
102 maybe_plan(180, 'SQL::Translator::Parser::MySQL');
103
104 If one of "SQL::Translator::Parser::MySQL"'s dependencies does not
105 exist, then the test will be skipped.
106
108 table_ok, field_ok, constraint_ok, index_ok, view_ok, trigger_ok, pro‐
109 cedure_ok, maybe_plan
110
112 Test the tests!
113 Test Count Constants
114 Constants to give the number of tests each *_ok sub uses. e.g. How
115 many tests does field_ok run? Can then use these to set up the test
116 plan easily.
117
118 Test skipping
119 As the test subs wrap up lots of tests in one call you can't skip
120 idividual tests only whole sets e.g. a whole table or field. We
121 could add skip_* items to the test hashes to allow per test skips.
122 e.g.
123
124 skip_is_primary_key => "Need to fix primary key parsing.",
125
126 yaml test specs
127 Maybe have the test subs also accept yaml for the test hash ref as
128 its a much nicer for writing big data structures. We can then
129 define tests as in input schema file and test yaml file to compare
130 it against.
131
134 Mark D. Addison <mark.addison@itn.co.uk>, Darren Chamberlain <dar‐
135 ren@cpan.org>.
136
137 Thanks to Ken Y. Clark for the original table and field test code taken
138 from his mysql test.
139
141 perl(1), SQL::Translator, SQL::Translator::Schema, Test::More.
142
143
144
145perl v5.8.8 2007-10-24 Test::SQL::Translator(3)