Release commit for 1.62
[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
0494e672 18# The filename, holder for all the data, and the filehandle
19my $datafile = "t/data/mysql/Apache-Session-MySQL.sql";
20my $data;
21my $fh = IO::File->new($datafile);
22
307d9560 23my ($v1, $v2);
24{
25 my $tr = SQL::Translator->new;
26 # Pass filename: simplest way
27 $tr->translate($datafile);
31cf3a54 28 $v1 = $tr->schema;
307d9560 29}
0494e672 30
307d9560 31{
32 my $tr = SQL::Translator->new;
33 # Pass string reference
34 read($fh, $data, -s $datafile);
35 $tr->translate(\$data);
31cf3a54 36 $v2 = $tr->schema;
307d9560 37}
0494e672 38
31cf3a54 39# XXX- Hack to remove Graph hack!
e593decb 40$_->translator (undef) for ($v1, $v2);
31cf3a54 41
307d9560 42ok(length $v1, "passing string (filename) works");
43ok(length $v2, "passing string as SCALAR reference");
31cf3a54 44is_deeply($v1, $v2, "from file == from string");