Changed many assumptions about the test.
[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
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);
2df9c21c 30warn "Data from filename method is\n$translated_datafile\n\n\n";
0494e672 31
32# Pass string reference
33read($fh, $data, -s $datafile);
34my $translated_data = $tr->translate(\$data);
2df9c21c 35warn "Data from string is\n$translated_data\n\n\n";
0494e672 36
37
38# Pass IO::File instance
39$fh->setpos(0);
40my $translated_fh = $tr->translate($fh);
2df9c21c 41warn "Data from filehandle method is\n$translated_fh\n\n\n";
0494e672 42
43# With all that setup out of the way, we can perform the actual tests.
44# We need to test the equality of:
45#
46# filename and string
47# filename and filehandle
48# filehandle and string
49#
50# And then we have all possibilities. Note that the order in which
51# the comparison is done is pretty arbitrary, and doesn't affect the
52# outcomes. Similarly, the order of the eq tests is also unimportant.
53#
54print "not " unless ($translated_datafile eq $translated_fh);
55print "ok 1 # from file == from filehandle\n";
56
57print "not " unless ($translated_datafile eq $translated_data);
58print "ok 2 # from file == from string\n";
59
60print "not " unless ($translated_data eq $translated_fh);
61print "ok 3 # from string == from filehandle\n";
0494e672 62
63# For this test, we should devise some other sort of output routine,
64# that can take a data structure and output it in a reasonable -- and
2df9c21c 65# machine parsable! -- way.