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).
18 BEGIN { print "1..3\n"; }
21 my $tr = SQL::Translator->new(parser => "MySQL", producer => "Oracle");
23 # The filename, holder for all the data, and the filehandle
24 my $datafile = "t/data/mysql/Apache-Session-MySQL.sql";
26 my $fh = IO::File->new($datafile);
28 # Pass filename: simplest way
29 my $translated_datafile = $tr->translate($datafile);
30 print "Data from filename method is\n$translated_datafile\n\n\n";
32 # Pass string reference
33 read($fh, $data, -s $datafile);
34 my $translated_data = $tr->translate(\$data);
35 print "Data from string is\n$translated_data\n\n\n";
38 # Pass IO::File instance
40 my $translated_fh = $tr->translate($fh);
41 print "Data from filehandle method is\n$translated_fh\n\n\n";
43 # With all that setup out of the way, we can perform the actual tests.
44 # We need to test the equality of:
47 # filename and filehandle
48 # filehandle and string
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.
54 print "not " unless ($translated_datafile eq $translated_fh);
55 print "ok 1 # from file == from filehandle\n";
57 print "not " unless ($translated_datafile eq $translated_data);
58 print "ok 2 # from file == from string\n";
60 print "not " unless ($translated_data eq $translated_fh);
61 print "ok 3 # from string == from filehandle\n";
63 # Problem with SQL::Translator::Producer::Oracle: it is keeping track of
64 # the last sequence number used, so as not to duplicate them, which
65 # is reasonable. However on runs past the first, it seems to be
66 # creating multiple constraint lines, that look like:
68 # CONSTRAINT i_sessions_pk_2 PRIMARY KEY (id),
69 # CONSTRAINT i_sessions_pk_3 PRIMARY KEY (id)
73 # For this test, we should devise some other sort of output routine,
74 # that can take a data structure and output it in a reasonable -- and
75 # machine parsable! -- way. The tendency of ::Producer::Oracle to
76 # produce numerically incrementing constraints is fine, and is not a
77 # bug, but it makes this test fail. (The duplicate CONSTRAINT *is* a