X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F04file%2Cfh%2Cstring.t;h=91214122795074a700f75cdae227dc3016fd2086;hb=aa4301a7a673eb7206bb6c837a2adaaf33d9c6d9;hp=ca768be400610cd2c1a65279240ad18807d02646;hpb=0494e6729c85162cd84131e60871fa428196947d;p=dbsrgits%2FSQL-Translator.git diff --git a/t/04file,fh,string.t b/t/04file,fh,string.t index ca768be..9121412 100644 --- a/t/04file,fh,string.t +++ b/t/04file,fh,string.t @@ -13,66 +13,32 @@ use strict; use IO::File; use SQL::Translator; - -# How many tests -BEGIN { print "1..3\n"; } - -# Our object. -my $tr = SQL::Translator->new(parser => "MySQL", producer => "Oracle"); +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); -# Pass filename: simplest way -my $translated_datafile = $tr->translate($datafile); -print "Data from filename method is\n$translated_datafile\n\n\n"; - -# Pass string reference -read($fh, $data, -s $datafile); -my $translated_data = $tr->translate(\$data); -print "Data from string is\n$translated_data\n\n\n"; - - -# Pass IO::File instance -$fh->setpos(0); -my $translated_fh = $tr->translate($fh); -print "Data from filehandle method is\n$translated_fh\n\n\n"; - -# With all that setup out of the way, we can perform the actual tests. -# We need to test the equality of: -# -# filename and string -# filename and filehandle -# filehandle and string -# -# And then we have all possibilities. Note that the order in which -# the comparison is done is pretty arbitrary, and doesn't affect the -# outcomes. Similarly, the order of the eq tests is also unimportant. -# -print "not " unless ($translated_datafile eq $translated_fh); -print "ok 1 # from file == from filehandle\n"; - -print "not " unless ($translated_datafile eq $translated_data); -print "ok 2 # from file == from string\n"; - -print "not " unless ($translated_data eq $translated_fh); -print "ok 3 # from string == from filehandle\n"; -# -# Problem with SQL::Translator::Producer::Oracle: it is keeping track of -# the last sequence number used, so as not to duplicate them, which -# is reasonable. However on runs past the first, it seems to be -# creating multiple constraint lines, that look like: -# -# CONSTRAINT i_sessions_pk_2 PRIMARY KEY (id), -# CONSTRAINT i_sessions_pk_3 PRIMARY KEY (id) -# -# Dunno why. - -# For this test, we should devise some other sort of output routine, -# that can take a data structure and output it in a reasonable -- and -# machine parsable! -- way. The tendency of ::Producer::Oracle to -# produce numerically incrementing constraints is fine, and is not a -# bug, but it makes this test fail. (The duplicate CONSTRAINT *is* a -# bug, though.) +my ($v1, $v2); +{ + my $tr = SQL::Translator->new; + # Pass filename: simplest way + $tr->translate($datafile); + $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");