Commit | Line | Data |
3c5dc866 |
1 | #!/usr/bin/perl |
2 | # vim: set ft=perl: |
8061d279 |
3 | # Test for Dumper producer |
3c5dc866 |
4 | |
5 | use strict; |
04c13c01 |
6 | use Config; |
04c13c01 |
7 | use File::Temp 'tempfile'; |
c401ac4b |
8 | use File::Spec; |
9 | use FindBin qw/$Bin/; |
10 | use IPC::Open3; |
3c5dc866 |
11 | use SQL::Translator; |
c401ac4b |
12 | use Test::More; |
3c5dc866 |
13 | use Test::SQL::Translator qw(maybe_plan); |
c401ac4b |
14 | use Symbol qw(gensym); |
3c5dc866 |
15 | |
16 | BEGIN { |
17 | maybe_plan( |
04c13c01 |
18 | 5, |
d2f0a9f6 |
19 | 'DBI', |
3c5dc866 |
20 | 'SQL::Translator::Parser::SQLite', |
21 | 'SQL::Translator::Producer::Dumper' |
22 | ); |
23 | } |
24 | |
04c13c01 |
25 | my $db_user = 'nomar'; |
26 | my $db_pass = 'gos0X!'; |
27 | my $dsn = 'dbi:SQLite:dbname=/tmp/foo'; |
3c5dc866 |
28 | my $file = "$Bin/data/sqlite/create.sql"; |
29 | my $t = SQL::Translator->new( |
30 | from => 'SQLite', |
31 | to => 'Dumper', |
32 | producer_args => { |
04c13c01 |
33 | skip => 'pet', |
34 | skiplike => '', |
3c5dc866 |
35 | db_user => $db_user, |
36 | db_password => $db_pass, |
37 | dsn => $dsn, |
38 | } |
39 | ); |
40 | |
41 | my $output = $t->translate( $file ); |
04c13c01 |
42 | |
43 | ok( $output, 'Got dumper script' ); |
44 | |
45 | my ( $fh, $filename ) = tempfile( 'XXXXXXXX' ); |
46 | |
47 | print $fh $output; |
8061d279 |
48 | close $fh or die "Can't close file '$filename': $!"; |
04c13c01 |
49 | |
50 | my $perl = $Config{'perlpath'}; |
c401ac4b |
51 | open( NULL, ">", File::Spec->devnull ); |
52 | my $pid = open3( gensym, ">&NULL", \*PH, "$perl -cw $filename" ); |
53 | my $res; |
54 | while( <PH> ) { $res .= $_; } |
55 | waitpid($pid, 0); |
56 | |
04c13c01 |
57 | like( $res, qr/syntax OK/, 'Generated script syntax is OK' ); |
58 | |
59 | like( $output, qr{DBI->connect\(\s*'$dsn',\s*'$db_user',\s*'$db_pass',}, |
60 | 'Script contains correct DSN, db user and password' ); |
61 | |
62 | like( $output, qr/table_name\s*=>\s*'person',/, 'Found "person" table' ); |
63 | unlike( $output, qr/table_name\s*=>\s*'pet',/, 'Skipped "pet" table' ); |
64 | |
65 | unlink $filename; |