Changed some of the basic assumptions.
[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
17 # How many tests
18 BEGIN { print "1..3\n"; }
19
20 # Our object; uses the default parser and producer
21 my $tr = SQL::Translator->new;
22
23 # The filename, holder for all the data, and the filehandle
24 my $datafile = "t/data/mysql/Apache-Session-MySQL.sql";
25 my $data;
26 my $fh = IO::File->new($datafile);
27
28 # Pass filename: simplest way
29 my $translated_datafile = $tr->translate($datafile);
30 warn "Data from filename method is\n$translated_datafile\n\n\n";
31
32 # Pass string reference
33 read($fh, $data, -s $datafile);
34 my $translated_data = $tr->translate(\$data);
35 warn "Data from string is\n$translated_data\n\n\n";
36
37 print "not " unless length $translated_datafile;
38 print "ok 1 # passing string (filename) works\n";
39
40 print "not " unless length $translated_data;
41 print "ok 2 # passing string as SCALAR reference\n";
42
43 print "not " unless ($translated_datafile eq $translated_data);
44 print "ok 3 # from file == from string\n";