From: Peter Rabbitson Date: Tue, 3 Feb 2009 14:16:27 +0000 (+0000) Subject: Add sqlite roundtrip test (probably need to do the same for the rest of the parser... X-Git-Tag: v0.11008~245 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=54360ac93d5401fdc5c84054eec5324bc2f35bfa;p=dbsrgits%2FSQL-Translator.git Add sqlite roundtrip test (probably need to do the same for the rest of the parser/producer combos, possibly using a known xml schema as a starting point) --- diff --git a/t/27sqlite-roundtrip.t b/t/27sqlite-roundtrip.t new file mode 100644 index 0000000..78cb0dc --- /dev/null +++ b/t/27sqlite-roundtrip.t @@ -0,0 +1,71 @@ +#!/usr/bin/perl + +use warnings; +use strict; +use Test::More; +use Test::SQL::Translator qw(maybe_plan); +use FindBin qw/$Bin/; + +use SQL::Translator; +use SQL::Translator::Schema::Constants; + +BEGIN { + maybe_plan(7, + 'SQL::Translator::Parser::SQLite', + 'SQL::Translator::Producer::SQLite', + ); +} + +my $file = "$Bin/data/sqlite/create.sql"; + +{ + local $/; + open my $fh, "<$file" or die "Can't read file '$file': $!\n"; + my $data = <$fh>; + + my $t = SQL::Translator->new; + + $t->translate ( + parser => 'SQLite', + data => \$data, + ); + my $schema1 = $t->schema; + isa_ok ($schema1, 'SQL::Translator::Schema', 'First parser pass produced a schema'); + + + my $data2 = $t->translate ( + producer => 'SQLite', + ); + like ($data2, qr/BEGIN.+COMMIT/is, 'Received some meaningful output from the producer'); + + # get a new translator + $t = SQL::Translator->new; + + $t->translate ( + parser => 'SQLite', + data => \$data2, + ); + my $schema2 = $t->schema; + isa_ok ($schema2, 'SQL::Translator::Schema', 'Second parser pass produced a schema'); + + my @t1 = $schema1->get_tables; + my @t2 = $schema2->get_tables; + + my @v1 = $schema1->get_views; + my @v2 = $schema2->get_views; + + my @g1 = $schema1->get_triggers; + my @g2 = $schema2->get_triggers; + + is (@t2, @t1, 'Equal amount of tables'); + + is_deeply ( + [ map { $_->name } (@t1) ], + [ map { $_->name } (@t2) ], + 'Table names match', + ); + + is (@v2, @v1, 'Equal amount of views'); + + is (@g2, @g1, 'Equal amount of triggers'); +}