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