1Test::SQL::Translator(3U)ser Contributed Perl DocumentatiToenst::SQL::Translator(3)
2
3
4

NAME

6       Test::SQL::Translator - Test::More test functions for the Schema
7       objects.
8

SYNOPSIS

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

DESCRIPTION

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 useful 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

Tests

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 prepend 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

CONDITIONAL TESTS

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
100       Instead of a number of tests, you can pass "undef" if you're using
101       done_testing(), or 'no_plan' if you don't want a plan at all.
102

EXPORTS

104       table_ok, field_ok, constraint_ok, index_ok, view_ok, trigger_ok,
105       procedure_ok, maybe_plan
106

TODO

108       Test the tests!
109       Test Count Constants
110           Constants to give the number of tests each *_ok sub uses. e.g. How
111           many tests does "field_ok" run? Can then use these to set up the
112           test plan easily.
113
114       Test skipping
115           As the test subs wrap up lots of tests in one call you can't skip
116           individual tests only whole sets e.g. a whole table or field.  We
117           could add "skip_*" items to the test hashes to allow per test
118           skips. e.g.
119
120            skip_is_primary_key => "Need to fix primary key parsing.",
121
122       yaml test specs
123           Maybe have the test subs also accept yaml for the test hash ref as
124           it is much nicer for writing big data structures. We can then
125           define tests as in input schema file and test yaml file to compare
126           it against.
127

AUTHOR

129       Mark D. Addison <mark.addison@itn.co.uk>, Darren Chamberlain
130       <darren@cpan.org>.
131
132       Thanks to Ken Y. Clark for the original table and field test code taken
133       from his mysql test.
134

SEE ALSO

136       perl(1), SQL::Translator, SQL::Translator::Schema, Test::More.
137
138
139
140perl v5.36.0                      2023-02-27          Test::SQL::Translator(3)
Impressum