Commit | Line | Data |
215c6c52 |
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 | # |
fd5abbd7 |
8 | # Tests the visibility arg. |
215c6c52 |
9 | # |
10 | |
11 | use strict; |
fd5abbd7 |
12 | use FindBin qw/$Bin/; |
215c6c52 |
13 | use Data::Dumper; |
fd5abbd7 |
14 | |
15 | # run test with -d for debug |
215c6c52 |
16 | my %opt; |
17 | BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; } |
18 | use constant DEBUG => (exists $opt{d} ? 1 : 0); |
19 | |
fd5abbd7 |
20 | use Test::More; |
21 | use Test::Exception; |
2d691ec1 |
22 | use Test::SQL::Translator qw(maybe_plan); |
fd5abbd7 |
23 | use SQL::Translator; |
24 | use SQL::Translator::Schema::Constants; |
215c6c52 |
25 | |
215c6c52 |
26 | |
2d691ec1 |
27 | maybe_plan(8, |
28 | 'SQL::Translator::Parser::XML::XMI', |
29 | 'SQL::Translator::Producer::MySQL'); |
215c6c52 |
30 | |
215c6c52 |
31 | my $testschema = "$Bin/data/xmi/Foo.poseidon2.xmi"; |
32 | die "Can't find test schema $testschema" unless -e $testschema; |
215c6c52 |
33 | |
215c6c52 |
34 | my @testd = ( |
35 | "" => [qw/Foo PrivateFoo Recording CD Track ProtectedFoo/], |
36 | [qw/fooid name protectedname privatename/], |
37 | "public" => [qw/Foo Recording CD Track/], |
38 | [qw/fooid name /], |
39 | "protected" => [qw/Foo Recording CD Track ProtectedFoo/], |
40 | [qw/fooid name protectedname/], |
41 | "private" => [qw/Foo PrivateFoo Recording CD Track ProtectedFoo/], |
42 | [qw/fooid name protectedname privatename/], |
43 | ); |
44 | while ( my ($vis,$tables,$foofields) = splice @testd,0,3 ) { |
45 | my $obj; |
46 | $obj = SQL::Translator->new( |
47 | filename => $testschema, |
48 | from => 'XML-XMI', |
49 | to => 'MySQL', |
50 | debug => DEBUG, |
51 | show_warnings => 1, |
215c6c52 |
52 | parser_args => { |
53 | visibility => $vis, |
54 | }, |
55 | ); |
56 | my $sql = $obj->translate; |
fd5abbd7 |
57 | print $sql if DEBUG; |
215c6c52 |
58 | my $scma = $obj->schema; |
59 | |
fd5abbd7 |
60 | # Tables from classes |
61 | my @tblnames = map {$_->name} $scma->get_tables; |
215c6c52 |
62 | is_deeply( \@tblnames, $tables, "Tables with visibility => '$vis'"); |
63 | |
fd5abbd7 |
64 | # Fields from attributes |
215c6c52 |
65 | my @fldnames = map {$_->name} $scma->get_table("Foo")->get_fields; |
66 | is_deeply( \@fldnames, $foofields, "Foo fields with visibility => '$vis'"); |
215c6c52 |
67 | } |