Cleaned up "translate" hash a bit, changed to use schema objects now,
[dbsrgits/SQL-Translator.git] / t / 04file,fh,string.t
1 #!/usr/bin/perl
2 # vim: set ft=perl:
3 #
4 # This tests that the same file can be passed in using a filename,
5 # a filehandle, and a string, and return identical results.  There's
6 # a lot of setup here, because we have to emulate the various ways
7 # that $tr->translate might be called:  with a string (filename),
8 # with a filehandle (IO::File, FileHandle, or \*FOO), and with a
9 # scalar reference (data in a string).
10 #
11
12 use strict;
13
14 use IO::File;
15 use SQL::Translator;
16 use Test::More tests => 3;
17
18 # Our object; uses the default parser and producer
19 my $tr = SQL::Translator->new;
20
21 # The filename, holder for all the data, and the filehandle
22 my $datafile = "t/data/mysql/Apache-Session-MySQL.sql";
23 my $data;
24 my $fh = IO::File->new($datafile);
25
26 # Pass filename: simplest way
27 my $translated_datafile = $tr->translate($datafile);
28
29 # Pass string reference
30 read($fh, $data, -s $datafile);
31 my $translated_data = $tr->translate(\$data);
32
33 ok(length $translated_datafile, "passing string (filename) works");
34 ok(length $translated_data, "passing string as SCALAR reference");
35 is($translated_datafile, $translated_data, "from file == from string");