Commit | Line | Data |
6cedfc23 |
1 | #!/usr/bin/perl -w |
2 | # vim:filetype=perl |
3 | |
4 | # Before `make install' is performed this script should be runnable with |
5 | # `make test'. After `make install' it should work as `perl test.pl' |
6 | |
7 | # SQL::Translator::Filter::HelloWorld - Test filter in a package |
8 | #============================================================================= |
9 | package SQL::Translator::Filter::HelloWorld; |
10 | |
11 | use strict; |
12 | use vars qw/$VERSION/; |
13 | $VERSION=0.1; |
14 | |
15 | sub filter { |
16 | my ($schema,$args) = (shift,shift); |
17 | |
18 | my $greeting = $args->{greeting} || "Hello"; |
19 | $schema->add_table( |
20 | name => "HelloWorld", |
21 | ); |
22 | } |
23 | |
24 | # Hack to allow sqlt to see our module as it wasn't loaded from a .pm |
25 | $INC{'SQL/Translator/Filter/HelloWorld.pm'} |
26 | = 'lib/SQL/Translator/Filter/HelloWorld.pm'; |
27 | |
28 | #============================================================================= |
29 | |
30 | package main; |
31 | |
32 | use strict; |
33 | use Test::More; |
34 | use Test::Exception; |
35 | use Test::SQL::Translator qw(maybe_plan); |
36 | |
37 | use Data::Dumper; |
38 | |
39 | BEGIN { |
40 | maybe_plan(4, 'YAML', 'Test::Differences') |
41 | } |
42 | use Test::Differences; |
43 | use SQL::Translator; |
44 | |
45 | my $in_yaml = qq{--- |
46 | schema: |
47 | tables: |
48 | Person: |
49 | name: Person |
50 | fields: |
51 | first_name: |
52 | data_type: foovar |
53 | name: first_name |
54 | }; |
55 | |
56 | # helloworld: |
57 | # comments: '' |
58 | # constraints: [] |
59 | # fields: {} |
60 | # indices: [] |
61 | # name: HelloWorld |
62 | # options: [] |
63 | # order: 2 |
64 | my $ans_yaml = qq{--- |
65 | schema: |
66 | procedures: {} |
67 | tables: |
68 | person: |
69 | comments: '' |
70 | constraints: [] |
71 | fields: |
72 | First_name: |
a4fb1ddc |
73 | comments: '' |
6cedfc23 |
74 | data_type: foovar |
75 | default_value: ~ |
76 | extra: {} |
77 | is_nullable: 1 |
78 | is_primary_key: 0 |
79 | is_unique: 0 |
80 | name: First_name |
81 | order: 1 |
82 | size: |
83 | - 0 |
84 | indices: [] |
85 | name: person |
86 | options: [] |
87 | order: 1 |
88 | triggers: {} |
89 | views: {} |
90 | translator: |
91 | add_drop_table: 0 |
92 | filename: ~ |
93 | no_comments: 0 |
94 | parser_args: {} |
95 | parser_type: SQL::Translator::Parser::YAML |
96 | producer_args: {} |
97 | producer_type: SQL::Translator::Producer::YAML |
98 | show_warnings: 1 |
99 | trace: 0 |
100 | version: 0.07 |
101 | }; |
102 | |
103 | # Parse the test XML schema |
104 | my $obj; |
105 | $obj = SQL::Translator->new( |
106 | debug => 0, |
107 | show_warnings => 1, |
108 | from => "YAML", |
109 | to => "YAML", |
110 | data => $in_yaml, |
111 | filters => [ |
112 | # Filter from SQL::Translator::Filter::* |
113 | [ 'Names', { |
114 | tables => 'lc', |
115 | fields => 'ucfirst', |
116 | } ], |
117 | ], |
118 | |
119 | ) or die "Failed to create translator object: ".SQL::Translator->error; |
120 | |
121 | #sub translate_ok { |
122 | # my ($sqlt,$ans_yaml,$name) = @_; |
123 | # $name ||= ""; |
124 | # |
125 | # my $out = eval { $sqlt->translate }; |
126 | # fail( $sqlt->error ) if $sqlt->error; |
127 | # fail( "No output" ) unless $out; |
128 | # eq_or_diff $out, $ans_yaml ,"Translated $name"; |
129 | #} |
130 | |
131 | my $out; |
132 | lives_ok { $out = $obj->translate; } "Translate ran"; |
133 | is $obj->error, '' ,"No errors"; |
134 | ok $out ne "" ,"Produced something!"; |
135 | eq_or_diff $out, $ans_yaml ,"Output looks right"; |