X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F04file%2Cfh%2Cstring.t;h=ae8fd72b2464c7dbf6309449d7422e60d433c613;hb=04c13c01d1a2f27d3229a818e3a662f7446f4552;hp=cce41fa10da41e3d4360b924b6df7d801a58a3d0;hpb=2df9c21c77de51262a3e4577e8b6dcd2c113d8eb;p=dbsrgits%2FSQL-Translator.git diff --git a/t/04file,fh,string.t b/t/04file,fh,string.t index cce41fa..ae8fd72 100644 --- a/t/04file,fh,string.t +++ b/t/04file,fh,string.t @@ -12,54 +12,31 @@ use strict; use IO::File; +use Storable 'freeze'; use SQL::Translator; - -# How many tests -BEGIN { print "1..3\n"; } - -# Our object; uses the default parser and producer -my $tr = SQL::Translator->new; +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); -warn "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); -warn "Data from string is\n$translated_data\n\n\n"; - - -# Pass IO::File instance -$fh->setpos(0); -my $translated_fh = $tr->translate($fh); -warn "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"; - -# 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. +my ($v1, $v2); +{ + my $tr = SQL::Translator->new; + # Pass filename: simplest way + $tr->translate($datafile); + $v1 = freeze( $tr->schema ); +} + +{ + my $tr = SQL::Translator->new; + # Pass string reference + read($fh, $data, -s $datafile); + $tr->translate(\$data); + $v2 = freeze( $tr->schema ); +} + +ok(length $v1, "passing string (filename) works"); +ok(length $v2, "passing string as SCALAR reference"); +is($v1, $v2, "from file == from string");