X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F36-filters.t;h=f69206577324c69ea554b211c0d8d006d4b9f0c6;hb=a14ab50e885e610c35e84a4294e876764a44c46d;hp=c67a8c977ac18ab2cd82db3a6f5664d0649a4c9f;hpb=e7a96c90d974ba6eddcda9c52dbfdd49ac95bceb;p=dbsrgits%2FSQL-Translator.git diff --git a/t/36-filters.t b/t/36-filters.t index c67a8c9..f692065 100644 --- a/t/36-filters.t +++ b/t/36-filters.t @@ -1,24 +1,31 @@ #!/usr/bin/perl -w # vim:filetype=perl -# Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl test.pl' +#============================================================================= +# Test Package based filters that oks when called. +package SQL::Translator::Filter::Ok; +use strict; + +sub filter { Test::More::pass( + 'Filter called with args: ' . join ', ', @_ +) } + +# Hack to allow sqlt to see our module as it wasn't loaded from a .pm +$INC{'SQL/Translator/Filter/Ok.pm'} = 'lib/SQL/Translator/Filter/Ok.pm'; -# SQL::Translator::Filter::HelloWorld - Test filter in a package #============================================================================= -package SQL::Translator::Filter::HelloWorld; +# SQL::Translator::Filter::HelloWorld - Test filter in a package +package # hide from cpan + SQL::Translator::Filter::HelloWorld; use strict; -use vars qw/$VERSION/; -$VERSION=0.1; sub filter { - my ($schema,$args) = (shift,shift); + my ($schema,%args) = (shift,@_); - my $greeting = $args->{greeting} || "Hello"; - $schema->add_table( - name => "HelloWorld", - ); + my $greeting = $args{greeting} || "Hello"; + my $newtable = "${greeting}World"; + $schema->add_table( name => $newtable ); } # Hack to allow sqlt to see our module as it wasn't loaded from a .pm @@ -37,7 +44,10 @@ use Test::SQL::Translator qw(maybe_plan); use Data::Dumper; BEGIN { - maybe_plan(14, 'Template', 'Test::Differences') + maybe_plan(16, 'Template 2.20', 'Test::Differences', + 'SQL::Translator::Parser::YAML', + 'SQL::Translator::Producer::YAML') + } use Test::Differences; use SQL::Translator; @@ -53,12 +63,19 @@ schema: name: First_Name }; +my $sqlt_version = $SQL::Translator::VERSION; my $ans_yaml = qq{--- schema: procedures: {} tables: + GdayWorld: + constraints: [] + fields: {} + indices: [] + name: GdayWorld + options: [] + order: 3 HelloWorld: - comments: '' constraints: [] fields: {} indices: [] @@ -66,13 +83,11 @@ schema: options: [] order: 2 PERSON: - comments: '' constraints: [] fields: first_name: data_type: foovar default_value: ~ - extra: {} is_nullable: 1 is_primary_key: 0 is_unique: 0 @@ -96,7 +111,7 @@ translator: producer_type: SQL::Translator::Producer::YAML show_warnings: 1 trace: 0 - version: 0.07 + version: $sqlt_version }; # Parse the test XML schema @@ -112,22 +127,23 @@ $obj = SQL::Translator->new( sub { pass("Filter 1 called"); isa_ok($_[0],"SQL::Translator::Schema", "Filter 1, arg0 "); - ok( ref($_[1]) eq "HASH", "Filter 1, arg1 is a hashref "); + is( $#_, 0, "Filter 1, got no args"); }, sub { pass("Filter 2 called"); isa_ok($_[0],"SQL::Translator::Schema", "Filter 2, arg0 "); - ok( ref($_[1]) eq "HASH", "Filter 2, arg1 is a hashref "); + is( $#_, 0, "Filter 2, got no args"); }, # Sub filter with args [ sub { pass("Filter 3 called"); isa_ok($_[0],"SQL::Translator::Schema", "Filter 3, arg0 "); - ok( ref($_[1]) eq "HASH", "Filter 3, arg1 is a hashref "); - is( $_[1]->{hello}, "world", "Filter 3, got args "); + is( $#_, 2, "Filter 3, go 2 args"); + is( $_[1], "hello", "Filter 3, arg1=hello"); + is( $_[2], "world", "Filter 3, arg2=world"); }, - { hello=>"world" } ], + hello => "world" ], # Uppercase all the table names. sub { @@ -146,7 +162,9 @@ $obj = SQL::Translator->new( }, # Filter from SQL::Translator::Filter::* + 'Ok', [ 'HelloWorld' ], + [ 'HelloWorld', greeting => 'Gday' ], ], ) or die "Failed to create translator object: ".SQL::Translator->error;