4 # Before `make install' is performed this script should be runnable with
5 # `make test'. After `make install' it should work as `perl test.pl'
10 use Test::SQL::Translator qw(maybe_plan);
14 BEGIN { map { $opt{$_}=1 if s/^-// } @ARGV; }
15 use constant DEBUG => (exists $opt{d} ? 1 : 0);
18 use File::Temp qw/tempdir/;
21 #=============================================================================
24 eval {require Template;};
25 plan skip_all => "Template v2.15+ is incompatible with SQL::Translator 0.08+"
26 if !$@ && Template->VERSION >= 2.15;
28 maybe_plan(8, 'Template', 'Test::Differences')
30 use Test::Differences;
33 use SQL::Translator::Producer::TT::Table;
35 # Setup a tmp directory we can output files to.
36 my $tdir = tempdir( CLEANUP => 1 );
38 # Parse the test XML schema
40 $obj = SQL::Translator->new(
41 debug => DEBUG, #$opt{d},
45 filename => "$Bin/data/sqlite/create.sql",
48 tt_table => "$Bin/data/template/table.tt",
50 mk_files_base => "$tdir",
52 on_exists => "replace",
56 lives_ok { $out = $obj->translate; } "Translate ran";
57 ok $out ne "" ,"Produced something!";
58 warn $obj->error unless $out;
60 # Normal output looks ok
61 local $/ = undef; # slurp
62 eq_or_diff $out, <DATA> ,"Output looks right";
65 my @files = glob("$tdir/*.txt");
66 ok( @files == 2, "Wrote 2 files." );
67 is( $files[0], "$tdir/person.txt" , "Wrote person.txt" );
68 is( $files[1], "$tdir/pet.txt" , "Wrote pet.txt" );
70 open(FILE, "$tdir/person.txt") || die "Couldn't open $tdir/person.txt : $!";
71 eq_or_diff <FILE>, qq{Table: person
72 Primary Key: person_id
74 Data Fields: name, age, weight, iq, description
77 , "person.txt looks right";
80 open(FILE, "$tdir/pet.txt") || die "Couldn't open $tdir/pet.txt : $!";
81 eq_or_diff <FILE>, qq{Table: pet
82 Primary Key: pet_id, person_id
84 Data Fields: name, age
87 , "pet.txt looks right";
92 #print "Debug:", Dumper($obj) if DEBUG;
96 Primary Key: person_id
98 Data Fields: name, age, weight, iq, description
101 Primary Key: pet_id, person_id
103 Data Fields: name, age