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 maybe_plan(8, 'Template 2.20', 'Test::Differences')
26 use Test::Differences;
29 use SQL::Translator::Producer::TT::Table;
31 # Setup a tmp directory we can output files to.
32 my $tdir = tempdir( CLEANUP => 1 );
34 # Parse the test XML schema
36 $obj = SQL::Translator->new(
37 debug => DEBUG, #$opt{d},
41 filename => "$Bin/data/sqlite/create.sql",
44 tt_table => "$Bin/data/template/table.tt",
46 mk_files_base => "$tdir",
48 on_exists => "replace",
52 lives_ok { $out = $obj->translate; } "Translate ran";
53 ok $out ne "" ,"Produced something!";
54 warn $obj->error unless $out;
56 # Normal output looks ok
57 local $/ = undef; # slurp
60 do { local (@ARGV, $/) = "$Bin/data/template/testresult_table.txt"; <> },
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";
91 #print "Debug:", Dumper($obj) if DEBUG;