6 use File::Spec::Functions qw(catfile updir tmpdir);
10 use Test::SQL::Translator qw(maybe_plan);
11 use Text::ParseWords qw(shellwords);
13 my @script = qw(script sqlt-diff);
14 my @create1 = qw(data sqlite create.sql);
15 my @create2 = qw(data sqlite create2.sql);
17 my $sqlt_diff = catfile($Bin, updir, @script);
18 my $create1 = catfile($Bin, @create1);
19 my $create2 = catfile($Bin, @create2);
23 'SQL::Translator::Parser::MySQL',
27 my @mysql_create1 = qw(data mysql create.sql);
28 my @mysql_create2 = qw(data mysql create2.sql);
30 my $mysql_create1 = (-d "t")
31 ? catfile($Bin, @mysql_create1)
32 : catfile($Bin, "t", @mysql_create1);
34 my $mysql_create2 = (-d "t")
35 ? catfile($Bin, @mysql_create2)
36 : catfile($Bin, "t", @mysql_create2);
38 # Test for differences
39 my $out = _run_cmd ($sqlt_diff, "$mysql_create1=MySQL", "$mysql_create2=MySQL");
41 like($out, qr/CHANGE COLUMN person_id/, "Detected altered 'person_id' field");
42 like($out, qr/CHANGE COLUMN iq/, "Detected altered 'iq' field");
43 like($out, qr/CHANGE COLUMN name/, "Detected altered 'name' field");
44 like($out, qr/CHANGE COLUMN age/, "Detected altered 'age' field");
45 like($out, qr/ADD COLUMN is_rock_star/,
46 "Detected missing rock star field");
47 like($out, qr/ADD UNIQUE UC_person_id/,
48 "Detected missing unique constraint");
49 like($out, qr/ADD UNIQUE INDEX unique_name/,
50 "Detected unique index with different name");
51 like($out, qr/DROP FOREIGN KEY FK5302D47D93FE702E/,
52 "Detected drop foreign key");
53 like($out, qr/ADD CONSTRAINT FK5302D47D93FE702E_diff/,
54 "Detected add constraint");
55 unlike($out, qr/ADD PRIMARY KEY/, "Primary key looks different when it shouldn't");
57 # Test for quoted output
58 $out = _run_cmd ($sqlt_diff, '--quote=`', "$mysql_create1=MySQL", "$mysql_create2=MySQL");
60 like($out, qr/ALTER TABLE `person`/, "Quoted table name");
61 like($out, qr/CHANGE COLUMN `person_id`/, "Quoted 'person_id' field");
62 like($out, qr/CHANGE COLUMN `iq`/, "Quoted 'iq' field");
63 like($out, qr/CHANGE COLUMN `name`/, "Quoted 'name' field");
64 like($out, qr/CHANGE COLUMN `age`/, "Quoted 'age' field");
67 $out = _run_cmd ($sqlt_diff, "$mysql_create1=MySQL", "$mysql_create1=MySQL");
69 like($out, qr/No differences found/, "Properly detected no differences");
73 my $pid = open3( undef, $out, undef, $^X, shellwords($ENV{HARNESS_PERL_SWITCHES}||''), @_ );
74 my $res = do { local $/; <$out> };