Added Spreadsheet::ParseExcel
[dbsrgits/SQL-Translator.git] / t / 04file,fh,string.t
CommitLineData
0494e672 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
12use strict;
13
14use IO::File;
15use SQL::Translator;
16
17# How many tests
18BEGIN { print "1..3\n"; }
19
30df963a 20$SQL::Translator::DEBUG = 0;
21
2df9c21c 22# Our object; uses the default parser and producer
23my $tr = SQL::Translator->new;
0494e672 24
25# The filename, holder for all the data, and the filehandle
26my $datafile = "t/data/mysql/Apache-Session-MySQL.sql";
27my $data;
28my $fh = IO::File->new($datafile);
29
30# Pass filename: simplest way
31my $translated_datafile = $tr->translate($datafile);
30df963a 32#warn "Data from filename method is\n$translated_datafile\n\n\n";
0494e672 33
34# Pass string reference
35read($fh, $data, -s $datafile);
36my $translated_data = $tr->translate(\$data);
30df963a 37#warn "Data from string is\n$translated_data\n\n\n";
0494e672 38
d152043f 39print "not " unless length $translated_datafile;
40print "ok 1 # passing string (filename) works\n";
0494e672 41
d152043f 42print "not " unless length $translated_data;
43print "ok 2 # passing string as SCALAR reference\n";
0494e672 44
0494e672 45print "not " unless ($translated_datafile eq $translated_data);
d152043f 46print "ok 3 # from file == from string\n";