File: 04file%2Cfh%2Cstring.t

package info (click to toggle)
libsql-translator-perl 0.11011-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 15,380 kB
  • sloc: perl: 251,748; sql: 3,805; xml: 233; makefile: 7
file content (44 lines) | stat: -rw-r--r-- 1,178 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl
# vim: set ft=perl:
#
# This tests that the same file can be passed in using a filename,
# a filehandle, and a string, and return identical results.  There's
# a lot of setup here, because we have to emulate the various ways
# that $tr->translate might be called:  with a string (filename),
# with a filehandle (IO::File, FileHandle, or \*FOO), and with a
# scalar reference (data in a string).
#

use strict;

use IO::File;
use SQL::Translator;
use Test::More tests => 3;

# The filename, holder for all the data, and the filehandle
my $datafile = "t/data/mysql/Apache-Session-MySQL.sql";
my $data;
my $fh = IO::File->new($datafile);

my ($v1, $v2);
{
    my $tr = SQL::Translator->new;
    # Pass filename: simplest way
    $tr->translate($datafile);
    $v1 = $tr->schema;
}

{
    my $tr = SQL::Translator->new;
    # Pass string reference
    read($fh, $data, -s $datafile);
    $tr->translate(\$data);
    $v2 = $tr->schema;
}

# XXX- Hack to remove Graph hack!
$_->translator (undef) for ($v1, $v2);

ok(length $v1, "passing string (filename) works");
ok(length $v2, "passing string as SCALAR reference");
is_deeply($v1, $v2, "from file == from string");