Commit | Line | Data |
da5a1bae |
1 | #!/usr/bin/perl |
2 | # vim: set ft=perl: |
3 | |
4 | use strict; |
5 | |
6 | use File::Spec::Functions qw(catfile updir tmpdir); |
7 | use FindBin qw($Bin); |
8 | use Test::More; |
9 | use Test::SQL::Translator qw(maybe_plan); |
10 | |
11 | my @script = qw(blib script sqlt-diff); |
12 | my @create1 = qw(data sqlite create.sql); |
13 | my @create2 = qw(data sqlite create2.sql); |
14 | |
15 | my $sqlt_diff = (-d "blib") |
16 | ? catfile($Bin, updir, @script) |
17 | : catfile($Bin, @script); |
18 | |
19 | my $create1 = (-d "t") |
20 | ? catfile($Bin, @create1) |
21 | : catfile($Bin, "t", @create1); |
22 | |
23 | my $create2 = (-d "t") |
24 | ? catfile($Bin, @create2) |
25 | : catfile($Bin, "t", @create2); |
26 | |
27 | BEGIN { |
28 | maybe_plan(16, 'SQL::Translator::Parser::MySQL', |
29 | ); |
30 | } |
31 | |
32 | ok(-e $sqlt_diff, 'Found sqlt-diff script'); |
33 | |
34 | my @mysql_create1 = qw(data mysql create.sql); |
35 | my @mysql_create2 = qw(data mysql create2.sql); |
36 | |
37 | my $mysql_create1 = (-d "t") |
38 | ? catfile($Bin, @mysql_create1) |
39 | : catfile($Bin, "t", @mysql_create1); |
40 | |
41 | my $mysql_create2 = (-d "t") |
42 | ? catfile($Bin, @mysql_create2) |
43 | : catfile($Bin, "t", @mysql_create2); |
44 | |
45 | # Test for differences |
46 | my @cmd = ($sqlt_diff, "$mysql_create1=MySQL", "$mysql_create2=MySQL"); |
47 | my $out = `@cmd`; |
48 | |
49 | unlike($out, qr/-- Target database MySQL is untested/, "Did not detect 'untested' comment"); |
50 | like($out, qr/ALTER TABLE person CHANGE COLUMN person_id/, "Detected altered 'person_id' field"); |
51 | like($out, qr/ALTER TABLE person CHANGE COLUMN iq/, "Detected altered 'iq' field"); |
52 | like($out, qr/ALTER TABLE person CHANGE COLUMN name/, "Detected altered 'name' field"); |
53 | like($out, qr/ALTER TABLE person CHANGE COLUMN age/, "Detected altered 'age' field"); |
54 | like($out, qr/ALTER TABLE person ADD COLUMN is_rock_star/, |
55 | "Detected missing rock star field"); |
56 | like($out, qr/ALTER TABLE person ADD UNIQUE UC_person_id/, |
57 | "Detected missing unique constraint"); |
58 | like($out, qr/ALTER TABLE person ADD UNIQUE INDEX unique_name/, |
59 | "Detected unique index with different name"); |
60 | like($out, qr/ALTER TABLE person ENGINE=InnoDB;/, |
61 | "Detected altered table option"); |
62 | like($out, qr/ALTER TABLE employee DROP FOREIGN KEY FK5302D47D93FE702E/, |
63 | "Detected drop foreign key"); |
64 | like($out, qr/ALTER TABLE employee ADD CONSTRAINT FK5302D47D93FE702E_diff/, |
65 | "Detected add constraint"); |
66 | unlike($out, qr/ALTER TABLE employee ADD PRIMARY KEY/, "Primary key looks different when it shouldn't"); |
67 | |
68 | # Test ignore parameters |
69 | @cmd = ($sqlt_diff, "--ignore-index-names", "--ignore-constraint-names", |
70 | "$mysql_create1=MySQL", "$mysql_create2=MySQL"); |
71 | $out = `@cmd`; |
72 | |
73 | unlike($out, qr/CREATE UNIQUE INDEX unique_name/, |
74 | "Detected unique index with different name"); |
75 | unlike($out, qr/ALTER TABLE employee ADD CONSTRAINT employee_FK5302D47D93FE702E_diff/, |
76 | "Detected add constraint"); |
77 | |
78 | # Test for sameness |
79 | @cmd = ($sqlt_diff, "$mysql_create1=MySQL", "$mysql_create1=MySQL"); |
80 | $out = `@cmd`; |
81 | |
82 | like($out, qr/No differences found/, "Properly detected no differences"); |
83 | |