# `make test'. After `make install' it should work as `perl test.pl'
#
-# basic.t
-# -------
-# Tests that;
+# Tests basic functionality and the default xmi2schema
#
use strict;
-use Test::More;
-use Test::Exception;
-
-use strict;
+use FindBin qw/$Bin/;
use Data::Dumper;
+
+# run test with -d for debug
my %opt;
BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
use constant DEBUG => (exists $opt{d} ? 1 : 0);
-local $SIG{__WARN__} = sub { diag "[warn] ", @_; };
-use FindBin qw/$Bin/;
+use Test::More;
+use Test::Exception;
+use Test::SQL::Translator qw(maybe_plan);
+use SQL::Translator;
+use SQL::Translator::Schema::Constants;
# Usefull test subs for the schema objs
#=============================================================================
# Testing 1,2,3,..
#=============================================================================
-plan tests => 111;
-
-use SQL::Translator;
-use SQL::Translator::Schema::Constants;
+maybe_plan(103,
+ 'SQL::Translator::Parser::XML::XMI',
+ 'SQL::Translator::Producer::MySQL');
my $testschema = "$Bin/data/xmi/Foo.poseidon2.xmi";
die "Can't find test schema $testschema" unless -e $testschema;
-my %base_translator_args = (
- filename => $testschema,
- from => 'XML-XMI',
- to => 'MySQL',
- debug => DEBUG,
- show_warnings => 1,
- add_drop_table => 1,
-);
-
-#
-# Basic tests
-#
-{
my $obj;
$obj = SQL::Translator->new(
to => 'MySQL',
debug => DEBUG,
show_warnings => 1,
- add_drop_table => 1,
);
my $sql = $obj->translate;
print $sql if DEBUG;
-#print "Debug: translator", Dumper($obj) if DEBUG;
-#print "Debug: schema", Dumper($obj->schema) if DEBUG;
#
# Test the schema
#
my $scma = $obj->schema;
my @tblnames = map {$_->name} $scma->get_tables;
-is_deeply( \@tblnames, [qw/Foo PrivateFoo Recording Track ProtectedFoo/]
+is_deeply( \@tblnames, [qw/Foo PrivateFoo Recording CD Track ProtectedFoo/]
,"tables");
-#
-
#
# Tables
#
},
],
);
-
-} # end basic tests
-
-#
-# Visibility tests
-#
-{
-
-# Classes
-my @testd = (
- "" => [qw/Foo PrivateFoo Recording Track ProtectedFoo/],
- [qw/fooid name protectedname privatename/],
- "public" => [qw/Foo Recording Track/],
- [qw/fooid name /],
- "protected" => [qw/Foo Recording Track ProtectedFoo/],
- [qw/fooid name protectedname/],
- "private" => [qw/Foo PrivateFoo Recording Track ProtectedFoo/],
- [qw/fooid name protectedname privatename/],
-);
- while ( my ($vis,$tables,$foofields) = splice @testd,0,3 ) {
- my $obj;
- $obj = SQL::Translator->new(
- filename => $testschema,
- from => 'XML-XMI',
- to => 'MySQL',
- debug => DEBUG,
- show_warnings => 1,
- add_drop_table => 1,
- parser_args => {
- visibility => $vis,
- },
- );
- my $sql = $obj->translate;
- my $scma = $obj->schema;
-
- my @tblnames = map {$_->name} $scma->get_tables;
- is_deeply( \@tblnames, $tables, "Tables with visibility => '$vis'");
-
- my @fldnames = map {$_->name} $scma->get_table("Foo")->get_fields;
- is_deeply( \@fldnames, $foofields, "Foo fields with visibility => '$vis'");
-
- #print "Debug: translator", Dumper($obj) if DEBUG;
- #print "Debug: schema", Dumper($obj->schema) if DEBUG;
-}
-
-# # Classes
-# %testd = (
-# "" => [qw/fooid name protectedname privatename/],
-# "public" => [qw/fooid name /],
-# "protected" => [qw/fooid name protectedname/],
-# "private" => [qw/fooid name protectedname privatename/],
-# );
-# while ( my ($vis,$ans) = each %testd ) {
-# my $obj;
-# $obj = SQL::Translator->new(
-# filename => $testschema,
-# from => 'XML-XMI',
-# to => 'MySQL',
-# debug => DEBUG,
-# show_warnings => 1,
-# add_drop_table => 1,
-# parser_args => {
-# visibility => $vis,
-# },
-# );
-# my $sql = $obj->translate;
-# my $scma = $obj->schema;
-# my @names = map {$_->name} $scma->get_table("Foo")->get_fields;
-# is_deeply( \@names, $ans, "Foo fields with visibility => '$vis'");
-#
-# #print "Debug: translator", Dumper($obj) if DEBUG;
-# #print "Debug: schema", Dumper($obj->schema) if DEBUG;
-# }
-#
-} # end visibility tests