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 | |
6cedfc23 |
7 | use strict; |
8 | use Test::More; |
9 | use Test::Exception; |
10 | use Test::SQL::Translator qw(maybe_plan); |
11 | |
12 | use Data::Dumper; |
13 | |
14 | BEGIN { |
15 | maybe_plan(4, 'YAML', 'Test::Differences') |
16 | } |
17 | use Test::Differences; |
18 | use SQL::Translator; |
19 | |
20 | my $in_yaml = qq{--- |
21 | schema: |
22 | tables: |
23 | Person: |
24 | name: Person |
25 | fields: |
26 | first_name: |
27 | data_type: foovar |
28 | name: first_name |
29 | }; |
30 | |
6cedfc23 |
31 | my $ans_yaml = qq{--- |
32 | schema: |
33 | procedures: {} |
34 | tables: |
35 | person: |
6cedfc23 |
36 | constraints: [] |
37 | fields: |
38 | First_name: |
39 | data_type: foovar |
40 | default_value: ~ |
6cedfc23 |
41 | is_nullable: 1 |
42 | is_primary_key: 0 |
43 | is_unique: 0 |
44 | name: First_name |
45 | order: 1 |
46 | size: |
47 | - 0 |
48 | indices: [] |
49 | name: person |
50 | options: [] |
51 | order: 1 |
52 | triggers: {} |
53 | views: {} |
54 | translator: |
55 | add_drop_table: 0 |
56 | filename: ~ |
57 | no_comments: 0 |
58 | parser_args: {} |
59 | parser_type: SQL::Translator::Parser::YAML |
60 | producer_args: {} |
61 | producer_type: SQL::Translator::Producer::YAML |
62 | show_warnings: 1 |
63 | trace: 0 |
8ce5d615 |
64 | version: SUPPRESSED |
6cedfc23 |
65 | }; |
66 | |
0e452694 |
67 | # Parse the test schema |
6cedfc23 |
68 | my $obj; |
69 | $obj = SQL::Translator->new( |
70 | debug => 0, |
71 | show_warnings => 1, |
72 | from => "YAML", |
73 | to => "YAML", |
74 | data => $in_yaml, |
75 | filters => [ |
76 | # Filter from SQL::Translator::Filter::* |
77 | [ 'Names', { |
78 | tables => 'lc', |
79 | fields => 'ucfirst', |
80 | } ], |
81 | ], |
82 | |
83 | ) or die "Failed to create translator object: ".SQL::Translator->error; |
84 | |
6cedfc23 |
85 | my $out; |
86 | lives_ok { $out = $obj->translate; } "Translate ran"; |
87 | is $obj->error, '' ,"No errors"; |
88 | ok $out ne "" ,"Produced something!"; |
8ce5d615 |
89 | # Somewhat hackishly modify the yaml with a regex to avoid |
90 | # failing randomly on every change of version. |
91 | $out =~ s/version: .*/version: SUPPRESSED/; |
6cedfc23 |
92 | eq_or_diff $out, $ans_yaml ,"Output looks right"; |