X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FTest%2FSQL%2FTranslator.pm;h=890c7a3dbfe906b806cd5c2e6d3d23f17f4330a5;hb=HEAD;hp=63a89540a738d0bbfa95583ef25342b6960e1109;hpb=df399712c8e458cbd2bf0389cb17666ce499dedd;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/Test/SQL/Translator.pm b/lib/Test/SQL/Translator.pm index 63a8954..890c7a3 100644 --- a/lib/Test/SQL/Translator.pm +++ b/lib/Test/SQL/Translator.pm @@ -14,9 +14,9 @@ use Test::More; use SQL::Translator::Schema::Constants; use base qw(Exporter); -use vars qw($VERSION @EXPORT @EXPORT_OK); -$VERSION = '1.59'; -@EXPORT = qw( +our @EXPORT_OK; +our $VERSION = '1.62'; +our @EXPORT = qw( schema_ok table_ok field_ok @@ -284,6 +284,9 @@ sub trigger_ok { is( $obj->on_table, $test->{on_table}, "$t_name on_table is '$test->{on_table}'" ); + is( $obj->scope, $test->{scope}, "$t_name scope is '$test->{scope}'" ) + if exists $test->{scope}; + is( $obj->action, $test->{action}, "$t_name action is '$test->{action}'" ); is_deeply( { $obj->extra }, $test->{extra}, "$t_name extra" ); @@ -459,6 +462,13 @@ sub maybe_plan { elsif ($@ =~ /([\w\:]+ version [\d\.]+) required.+?this is only version/) { push @errors, $1; } + elsif ($@ =~ /Can't load .+? for module .+?DynaLoader\.pm/i ) { + push @errors, $module; + } + else { + (my $err = $@) =~ s/\n+/\\n/g; # Can't have newlines in the skip message + push @errors, "$module: $err"; + } } if (@errors) { @@ -467,7 +477,9 @@ sub maybe_plan { join ", ", @errors; plan skip_all => $msg; } - elsif ($ntests and $ntests ne 'no_plan') { + return unless defined $ntests; + + if ($ntests ne 'no_plan') { plan tests => $ntests; } else { @@ -530,11 +542,11 @@ __END__ ], }); -=head1 DESCSIPTION +=head1 DESCRIPTION Provides a set of Test::More tests for Schema objects. Testing a parsed schema is then as easy as writing a perl data structure describing how you -expect the schema to look. Also provides maybe_plan for conditionally running +expect the schema to look. Also provides C for conditionally running tests based on their dependencies. The data structures given to the test subs don't have to include all the @@ -543,14 +555,14 @@ tested to make sure they are still at their default value. This is a useful check that you your parser hasn't accidentally set schema values you didn't expect it to. -For an example of the output run the t/16xml-parser.t test. +For an example of the output run the F test. =head1 Tests All the tests take a first arg of the schema object to test, followed by a hash ref describing how you expect that object to look (you only need give the attributes you expect to have changed from the default). -The 3rd arg is an optional test name to pre-pend to all the generated test +The 3rd arg is an optional test name to prepend to all the generated test names. =head2 table_ok @@ -582,6 +594,9 @@ modules on which test execution depends: If one of C's dependencies does not exist, then the test will be skipped. +Instead of a number of tests, you can pass C if you're using +C, or C<'no_plan'> if you don't want a plan at all. + =head1 EXPORTS table_ok, field_ok, constraint_ok, index_ok, view_ok, trigger_ok, procedure_ok, @@ -595,27 +610,25 @@ maybe_plan =item Test Count Constants -Constants to give the number of tests each *_ok sub uses. e.g. How many tests -does field_ok run? Can then use these to set up the test plan easily. +Constants to give the number of tests each C<*_ok> sub uses. e.g. How many tests +does C run? Can then use these to set up the test plan easily. =item Test skipping -As the test subs wrap up lots of tests in one call you can't skip idividual +As the test subs wrap up lots of tests in one call you can't skip individual tests only whole sets e.g. a whole table or field. -We could add skip_* items to the test hashes to allow per test skips. e.g. +We could add C items to the test hashes to allow per test skips. e.g. skip_is_primary_key => "Need to fix primary key parsing.", =item yaml test specs -Maybe have the test subs also accept yaml for the test hash ref as its a much +Maybe have the test subs also accept yaml for the test hash ref as it is much nicer for writing big data structures. We can then define tests as in input schema file and test yaml file to compare it against. =back -=head1 BUGS - =head1 AUTHOR Mark D. Addison Emark.addison@itn.co.ukE,