General clean up to make it more like other tests.
[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;
37ac104a 16use Test::More;
0494e672 17
37ac104a 18plan tests => 3;
30df963a 19
2df9c21c 20# Our object; uses the default parser and producer
21my $tr = SQL::Translator->new;
0494e672 22
23# The filename, holder for all the data, and the filehandle
24my $datafile = "t/data/mysql/Apache-Session-MySQL.sql";
25my $data;
26my $fh = IO::File->new($datafile);
27
28# Pass filename: simplest way
29my $translated_datafile = $tr->translate($datafile);
0494e672 30
31# Pass string reference
32read($fh, $data, -s $datafile);
33my $translated_data = $tr->translate(\$data);
0494e672 34
37ac104a 35ok(length $translated_datafile, "passing string (filename) works");
36ok(length $translated_data, "passing string as SCALAR reference");
37is($translated_datafile, $translated_data, "from file == from string");