X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F17sqlfxml-producer.t;h=cded24b4121a410f2dcc499ad3ae3fff6232edf2;hb=f82112a31415cc2d1855313695d412d079b53912;hp=091bee14c477fc057a5f375957b1d47b736f6bfc;hpb=87c5565efa0003b1cf1fcbd08b3b6891cd0c957b;p=dbsrgits%2FSQL-Translator.git diff --git a/t/17sqlfxml-producer.t b/t/17sqlfxml-producer.t index 091bee1..cded24b 100644 --- a/t/17sqlfxml-producer.t +++ b/t/17sqlfxml-producer.t @@ -23,7 +23,7 @@ my $file = "$Bin/data/mysql/sqlfxml-producer-basic.sql"; local $SIG{__WARN__} = sub { CORE::warn(@_) - unless $_[0] =~ m#XML/Writer#; + unless $_[0] =~ m!XML/Writer!; }; # Testing 1,2,3,4... @@ -40,6 +40,17 @@ use Test::Differences; 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 # @@ -48,8 +59,10 @@ my ($obj,$ans,$xml); $ans = < + + @@ -69,12 +82,19 @@ $ans = < - + + + - - + + + + + + +
@@ -96,7 +116,7 @@ ok("$xml" ne "" ,"Produced something!"); 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 @@ -109,10 +129,12 @@ my ($obj,$ans,$xml); $ans = < + select name, age from person + @@ -136,6 +158,7 @@ EOXML name => $name, sql => $sql, fields => $fields, + extra => { hello => "world" }, schema => $s, ) or die $s->error; @@ -145,8 +168,8 @@ EOXML 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 # @@ -158,11 +181,21 @@ my ($obj,$ans,$xml); $ans = < - + + + + + + + + +
+
- + update modified=timestamp(); + @@ -181,14 +214,15 @@ EOXML 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; # As we have created a Schema we give translate a dummy string so that @@ -197,8 +231,8 @@ EOXML 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 # @@ -210,6 +244,7 @@ my ($obj,$ans,$xml); $ans = < + @@ -217,6 +252,7 @@ $ans = < select foo from bar Go Sox! + @@ -242,6 +278,7 @@ EOXML parameters => $parameters, owner => $owner, comments => $comments, + extra => { hello => "world" }, ) or die $s->error; # As we have created a Schema we give translate a dummy string so that @@ -250,8 +287,8 @@ EOXML 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 # @@ -262,16 +299,27 @@ my ($obj,$ans,$xml); $ans = < + - +
+ - + + + + + + + + + +
@@ -297,6 +345,18 @@ EOXML ) 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"; @@ -304,5 +364,5 @@ EOXML 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