From: Justin Hunter Date: Wed, 27 Jan 2010 07:19:09 +0000 (-0800) Subject: more tests and test data X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4a7b83f4e10382f98d3d8d9b0c18616e9924069a;p=dbsrgits%2FSQL-Translator-2.0-ish.git more tests and test data --- diff --git a/t/04file,fh,string.t b/t/04file,fh,string.t new file mode 100644 index 0000000..c72f72d --- /dev/null +++ b/t/04file,fh,string.t @@ -0,0 +1,40 @@ +# This tests that the same file can be passed in using a filename, +# a filehandle, and a string, and return identical results. There's +# a lot of setup here, because we have to emulate the various ways +# that $tr->translate might be called: with a string (filename), +# with a filehandle (IO::File, FileHandle, or \*FOO), and with a +# scalar reference (data in a string). + +use strict; + +use IO::File; +use SQL::Translator; +use Test::More tests => 3; + +# The filename, holder for all the data, and the filehandle +my $datafile = "t/data/mysql/Apache-Session-MySQL.sql"; +my $data; +my $fh = IO::File->new($datafile); + +my ($v1, $v2); +{ + my $tr = SQL::Translator->new; + # Pass filename: simplest way + $tr->translate(fh => $fh); + $v1 = $tr->schema; +} + +{ + my $tr = SQL::Translator->new; + # Pass string reference + read($fh, $data, -s $datafile); + $tr->translate(\$data); + $v2 = $tr->schema; +} + +# XXX- Hack to remove Graph hack! +$_->translator (undef) for ($v1, $v2); + +ok(length $v1, "passing string (filename) works"); +ok(length $v2, "passing string as SCALAR reference"); +is_deeply($v1, $v2, "from file == from string"); diff --git a/t/24yaml.t b/t/24yaml.t new file mode 100644 index 0000000..6fbd2ca --- /dev/null +++ b/t/24yaml.t @@ -0,0 +1,248 @@ +use warnings; +use strict; +use Test::More; +use Test::Differences; +#use Test::SQL::Translator qw(maybe_plan); +use SQL::Translator; +use FindBin '$Bin'; + +#BEGIN { +# maybe_plan(2, +# 'SQL::Translator::Parser::SQLite', +# 'SQL::Translator::Producer::YAML'); +#} + +my $sqlt_version = $SQL::Translator::VERSION; +my $yaml = <; +my $tr = SQL::Translator->new( + parser => 'SQLite', + producer => 'YAML', + data => $data, +); + +my $out; +ok( $out = $tr->translate, 'Translate SQLite to YAML' ); +eq_or_diff( $out, $yaml, 'YAML matches expected' ); + +done_testing; diff --git a/t/data/mysql/Apache-Session-MySQL.sql b/t/data/mysql/Apache-Session-MySQL.sql new file mode 100644 index 0000000..ec075e0 --- /dev/null +++ b/t/data/mysql/Apache-Session-MySQL.sql @@ -0,0 +1,6 @@ +CREATE TABLE random ( + id int auto_increment PRIMARY KEY, + foo varchar(255) not null default '', + updated timestamp +); +