local $SIG{__WARN__} = sub {
CORE::warn(@_)
- unless $_[0] =~ m#XML/Writer#;
+ unless $_[0] =~ m!XML/Writer!;
};
# Testing 1,2,3,4...
use SQL::Translator;
use SQL::Translator::Producer::XML::SQLFairy;
+# Due to formatters being able to change style, e.g. by entries in .rc files
+# in $HOME, the layout and or indent might differ slightly. As leading white
+# is not important in XML, strip it when comparing
+sub xml_equals
+{
+ my ($got, $expect, $msg) = (@_, "XML looks right");
+ $got =~ s/^ +//gm;
+ $expect =~ s/^ +//gm;
+ eq_or_diff $got, $expect, $msg;
+}
+
#
# basic stuff
#
<extra />
</constraint>
</constraints>
+ <comments></comments>
</table>
</tables>
<views></views>
print "XML:\n$xml" if DEBUG;
# Strip sqlf header with its variable date so we diff safely
$xml =~ s/^([^\n]*\n){7}//m;
-eq_or_diff $xml, $ans, "XML looks right";
+xml_equals $xml, $ans;
} # end basic stuff
ok("$xml" ne "" ,"Produced something!");
print "XML attrib_values=>1:\n$xml" if DEBUG;
# Strip sqlf header with its variable date so we diff safely
- $xml =~ s/^([^\n]*\n){7}//m;
- eq_or_diff $xml, $ans ,"XML looks right";
+ $xml =~ s/^([^\n]*\n){7}//m;
+ xml_equals $xml, $ans;
} # end View
#
$ans = <<EOXML;
<schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
<extra />
- <tables></tables>
+ <tables>
+ <table name="Basic" order="1">
+ <extra />
+ <fields></fields>
+ <indices></indices>
+ <constraints></constraints>
+ <comments></comments>
+ </table>
+ </tables>
<views></views>
<triggers>
- <trigger name="foo_trigger" database_event="insert" on_table="foo" perform_action_when="after" order="1">
+ <trigger name="foo_trigger" database_events="insert" on_table="Basic" perform_action_when="after" order="1">
<action>update modified=timestamp();</action>
<extra hello="world" />
</trigger>
my $name = 'foo_trigger';
my $perform_action_when = 'after';
my $database_event = 'insert';
- my $on_table = 'foo';
my $action = 'update modified=timestamp();';
+ my $table = $s->add_table( name => "Basic" ) or die $s->error;
my $t = $s->add_trigger(
name => $name,
perform_action_when => $perform_action_when,
- database_event => $database_event,
- on_table => $on_table,
+ database_events => [$database_event],
+ table => $table,
action => $action,
extra => { hello => "world" },
) or die $s->error;
ok("$xml" ne "" ,"Produced something!");
print "XML attrib_values=>1:\n$xml" if DEBUG;
# Strip sqlf header with its variable date so we diff safely
- $xml =~ s/^([^\n]*\n){7}//m;
- eq_or_diff $xml, $ans ,"XML looks right";
+ $xml =~ s/^([^\n]*\n){7}//m;
+ xml_equals $xml, $ans;
} # end Trigger
#
ok("$xml" ne "" ,"Produced something!");
print "XML attrib_values=>1:\n$xml" if DEBUG;
# Strip sqlf header with its variable date so we diff safely
- $xml =~ s/^([^\n]*\n){7}//m;
- eq_or_diff $xml, $ans ,"XML looks right";
+ $xml =~ s/^([^\n]*\n){7}//m;
+ xml_equals $xml, $ans;
} # end Procedure
#
<schema name="" database="" xmlns="http://sqlfairy.sourceforge.net/sqlfairy.xml">
<extra />
<tables>
- <table name="Basic" order="2">
+ <table name="Basic" order="1">
<extra />
<fields>
- <field name="foo" data_type="integer" size="10" is_nullable="1" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="5">
+ <field name="foo" data_type="integer" size="10" is_nullable="1" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="1">
<extra ZEROFILL="1" />
<comments></comments>
</field>
+ <field name="bar" data_type="numeric" size="10,2" is_nullable="1" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="2">
+ <extra />
+ <comments></comments>
+ </field>
+ <field name="baz" data_type="decimal" size="8,3" is_nullable="1" is_auto_increment="0" is_primary_key="0" is_foreign_key="0" order="3">
+ <extra />
+ <comments></comments>
+ </field>
</fields>
<indices></indices>
<constraints></constraints>
+ <comments></comments>
</table>
</tables>
<views></views>
) or die $t->error;
$f->extra(ZEROFILL => "1");
+ $t->add_field(
+ name => "bar",
+ data_type => "numeric",
+ size => "10,2",
+ ) or die $t->error;
+ $t->add_field(
+ name => "baz",
+ data_type => "decimal",
+ size => [8,3],
+ ) or die $t->error;
+
+
# As we have created a Schema we give translate a dummy string so that
# it will run the produce.
lives_ok {$xml =$obj->translate("FOO");} "Translate (Field.extra) ran";
print "XML:\n$xml" if DEBUG;
# Strip sqlf header with its variable date so we diff safely
$xml =~ s/^([^\n]*\n){7}//m;
- eq_or_diff $xml, $ans ,"XML looks right";
+ xml_equals $xml, $ans;
} # end extra