Commit | Line | Data |
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 | |
12 | use strict; |
13 | |
14 | use IO::File; |
307d9560 |
15 | use Storable 'freeze'; |
0494e672 |
16 | use SQL::Translator; |
40e47dd5 |
17 | use Test::More tests => 3; |
30df963a |
18 | |
0494e672 |
19 | |
20 | # The filename, holder for all the data, and the filehandle |
21 | my $datafile = "t/data/mysql/Apache-Session-MySQL.sql"; |
22 | my $data; |
23 | my $fh = IO::File->new($datafile); |
24 | |
307d9560 |
25 | my ($v1, $v2); |
26 | { |
27 | my $tr = SQL::Translator->new; |
28 | # Pass filename: simplest way |
29 | $tr->translate($datafile); |
30 | $v1 = freeze( $tr->schema ); |
31 | } |
0494e672 |
32 | |
307d9560 |
33 | { |
34 | my $tr = SQL::Translator->new; |
35 | # Pass string reference |
36 | read($fh, $data, -s $datafile); |
37 | $tr->translate(\$data); |
38 | $v2 = freeze( $tr->schema ); |
39 | } |
0494e672 |
40 | |
307d9560 |
41 | ok(length $v1, "passing string (filename) works"); |
42 | ok(length $v2, "passing string as SCALAR reference"); |
43 | is($v1, $v2, "from file == from string"); |