Commit | Line | Data |
4a7b83f4 |
1 | # This tests that the same file can be passed in using a filename, |
2 | # a filehandle, and a string, and return identical results. There's |
3 | # a lot of setup here, because we have to emulate the various ways |
4 | # that $tr->translate might be called: with a string (filename), |
5 | # with a filehandle (IO::File, FileHandle, or \*FOO), and with a |
6 | # scalar reference (data in a string). |
7 | |
8 | use strict; |
9 | |
10 | use IO::File; |
11 | use SQL::Translator; |
12 | use Test::More tests => 3; |
13 | |
14 | # The filename, holder for all the data, and the filehandle |
15 | my $datafile = "t/data/mysql/Apache-Session-MySQL.sql"; |
16 | my $data; |
17 | my $fh = IO::File->new($datafile); |
18 | |
19 | my ($v1, $v2); |
20 | { |
21 | my $tr = SQL::Translator->new; |
22 | # Pass filename: simplest way |
23 | $tr->translate(fh => $fh); |
24 | $v1 = $tr->schema; |
25 | } |
26 | |
27 | { |
28 | my $tr = SQL::Translator->new; |
29 | # Pass string reference |
30 | read($fh, $data, -s $datafile); |
31 | $tr->translate(\$data); |
32 | $v2 = $tr->schema; |
33 | } |
34 | |
35 | # XXX- Hack to remove Graph hack! |
36 | $_->translator (undef) for ($v1, $v2); |
37 | |
38 | ok(length $v1, "passing string (filename) works"); |
39 | ok(length $v2, "passing string as SCALAR reference"); |
40 | is_deeply($v1, $v2, "from file == from string"); |