#!/usr/bin/perl -w
BEGIN {
map
{
$opt
{
$_
} = 1
if
s/^-// }
@ARGV
;
}
use
constant
DEBUG
=> (
exists
$opt
{d} ? 1 : 0);
BEGIN {
maybe_plan(8,
'Template 2.20'
,
'Test::Differences'
);
}
my
$tdir
= tempdir(
CLEANUP
=> 1);
my
$obj
;
$obj
= SQL::Translator->new(
debug
=> DEBUG,
show_warnings
=> 1,
add_drop_table
=> 1,
from
=>
"SQLite"
,
filename
=>
"$Bin/data/sqlite/create.sql"
,
to
=>
"TT-Table"
,
producer_args
=> {
tt_table
=>
"$Bin/data/template/table.tt"
,
mk_files
=> 1,
mk_files_base
=>
"$tdir"
,
mk_file_ext
=>
"txt"
,
on_exists
=>
"replace"
,
},
);
my
$out
;
lives_ok {
$out
=
$obj
->translate; }
"Translate ran"
;
ok
$out
ne
""
,
"Produced something!"
;
warn
$obj
->error
unless
$out
;
local
$/ =
undef
;
eq_or_diff
$out
,
do
{
local
(
@ARGV
, $/) =
"$Bin/data/template/testresult_table.txt"
; <> },
"Output looks right"
;
my
@files
=
glob
(
"$tdir/*.txt"
);
ok(
@files
== 2,
"Wrote 2 files."
);
is(
$files
[0],
"$tdir/person.txt"
,
"Wrote person.txt"
);
is(
$files
[1],
"$tdir/pet.txt"
,
"Wrote pet.txt"
);
open
(FILE,
"$tdir/person.txt"
) ||
die
"Couldn't open $tdir/person.txt : $!"
;
eq_or_diff <FILE>,
qq{Table: person
Primary Key: person_id
Foreign Keys:\x20
Data Fields: name, age, weight, iq, description
}
,
"person.txt looks right"
;
close
(FILE);
open
(FILE,
"$tdir/pet.txt"
) ||
die
"Couldn't open $tdir/pet.txt : $!"
;
eq_or_diff <FILE>,
qq{Table: pet
Primary Key: pet_id, person_id
Foreign Keys:\x20
Data Fields: name, age
}
,
"pet.txt looks right"
;
close
(FILE);
print
$out
if
DEBUG;