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;};
26 maybe_plan(8, 'Template', 'Test::Differences')
28 use Test::Differences;
31 use SQL::Translator::Producer::TT::Table;
33 # Setup a tmp directory we can output files to.
34 my $tdir = tempdir( CLEANUP => 1 );
36 # Parse the test XML schema
38 $obj = SQL::Translator->new(
39 debug => DEBUG, #$opt{d},
43 filename => "$Bin/data/sqlite/create.sql",
46 tt_table => "$Bin/data/template/table.tt",
48 mk_files_base => "$tdir",
50 on_exists => "replace",
54 lives_ok { $out = $obj->translate; } "Translate ran";
55 ok $out ne "" ,"Produced something!";
56 warn $obj->error unless $out;
58 # Normal output looks ok
59 local $/ = undef; # slurp
60 eq_or_diff $out, <DATA> ,"Output looks right";
63 my @files = glob("$tdir/*.txt");
64 ok( @files == 2, "Wrote 2 files." );
65 is( $files[0], "$tdir/person.txt" , "Wrote person.txt" );
66 is( $files[1], "$tdir/pet.txt" , "Wrote pet.txt" );
68 open(FILE, "$tdir/person.txt") || die "Couldn't open $tdir/person.txt : $!";
69 eq_or_diff <FILE>, qq{Table: person
70 Primary Key: person_id
72 Data Fields: name, age, weight, iq, description
75 , "person.txt looks right";
78 open(FILE, "$tdir/pet.txt") || die "Couldn't open $tdir/pet.txt : $!";
79 eq_or_diff <FILE>, qq{Table: pet
80 Primary Key: pet_id, person_id
82 Data Fields: name, age
85 , "pet.txt looks right";
90 #print "Debug:", Dumper($obj) if DEBUG;
94 Primary Key: person_id
96 Data Fields: name, age, weight, iq, description
99 Primary Key: pet_id, person_id
101 Data Fields: name, age