From: Darren Chamberlain Date: Thu, 4 Mar 2004 14:43:43 +0000 (+0000) Subject: Update tests to use maybe_plan. X-Git-Tag: v0.06~154 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2d691ec135298f8a4523656dc0516dcb7af3e8cd;p=dbsrgits%2FSQL-Translator.git Update tests to use maybe_plan. --- diff --git a/t/02mysql-parser.t b/t/02mysql-parser.t index 3aa829a..1839795 100644 --- a/t/02mysql-parser.t +++ b/t/02mysql-parser.t @@ -7,16 +7,11 @@ use strict; use Test::More; use SQL::Translator; use SQL::Translator::Schema::Constants; +use Test::SQL::Translator qw(maybe_plan); -eval { - require SQL::Translator::Parser::MySQL; +BEGIN { + maybe_plan(180, "SQL::Translator::Parser::MySQL"); SQL::Translator::Parser::MySQL->import('parse'); -}; -if ($@) { - plan skip_all => "$@"; -} -else { - plan tests => 180; } { diff --git a/t/03mysql-to-oracle.t b/t/03mysql-to-oracle.t index 0897878..a257552 100644 --- a/t/03mysql-to-oracle.t +++ b/t/03mysql-to-oracle.t @@ -2,8 +2,9 @@ # vim: set ft=perl: use strict; -use Test::More tests => 1; +use Test::More; use SQL::Translator; +use Test::SQL::Translator qw(maybe_plan); my $create = q| CREATE TABLE random ( @@ -13,6 +14,12 @@ CREATE TABLE random ( ); |; +BEGIN { + maybe_plan(1, + 'SQL::Translator::Parser::MySQL', + 'SQL::Translator::Producer::Oracle'); +} + my $tr = SQL::Translator->new( parser => "MySQL", producer => "Oracle" diff --git a/t/04file,fh,string.t b/t/04file,fh,string.t index 9f1100b..ae8fd72 100644 --- a/t/04file,fh,string.t +++ b/t/04file,fh,string.t @@ -16,7 +16,6 @@ use Storable 'freeze'; use SQL::Translator; use Test::More tests => 3; - # The filename, holder for all the data, and the filehandle my $datafile = "t/data/mysql/Apache-Session-MySQL.sql"; my $data; diff --git a/t/05bgep-re.t b/t/05bgep-re.t index 435f8ce..1c55bc4 100644 --- a/t/05bgep-re.t +++ b/t/05bgep-re.t @@ -8,7 +8,8 @@ use File::Spec::Functions qw(catfile tmpdir); use File::Temp qw(tempfile); use FindBin qw($Bin); use SQL::Translator; -use Test::More tests => 2; +use Test::More; +use Test::SQL::Translator qw(maybe_plan); # This aggravates me; XML::Writer produces tons of warnings. local $SIG{__WARN__} = sub { @@ -16,6 +17,12 @@ local $SIG{__WARN__} = sub { unless $_[0] =~ m#XML/Writer#; }; +BEGIN { + maybe_plan(2, + 'SQL::Translator::Parser::MySQL', + 'SQL::Translator::Producer::XML::SQLFairy'); +} + my @data = qw(data mysql BGEP-RE-create.sql); my $test_data = (-d "t") ? catfile($Bin, @data) diff --git a/t/06xsv.t b/t/06xsv.t index 4c12665..125a1af 100644 --- a/t/06xsv.t +++ b/t/06xsv.t @@ -9,16 +9,11 @@ use SQL::Translator; use SQL::Translator::Schema; use SQL::Translator::Schema::Constants; use Test::More; +use Test::SQL::Translator qw(maybe_plan); -eval { - require SQL::Translator::Parser::xSV; +BEGIN { + maybe_plan(25, 'SQL::Translator::Parser::xSV'); SQL::Translator::Parser::xSV->import('parse'); -}; -if ($@) { - plan skip_all => "$@"; -} -else { - plan tests => 25; } my $tr = SQL::Translator->new; diff --git a/t/08postgres-to-mysql.t b/t/08postgres-to-mysql.t index 19a668b..c087a0e 100644 --- a/t/08postgres-to-mysql.t +++ b/t/08postgres-to-mysql.t @@ -2,9 +2,16 @@ # vim: set ft=perl: use strict; -use Test::More tests => 1; +use Test::More; use SQL::Translator; use Data::Dumper; +use Test::SQL::Translator qw(maybe_plan); + +BEGIN { + maybe_plan(1, + 'SQL::Translator::Parser::MySQL', + 'SQL::Translator::Producer::PostgreSQL'); +} my $create = q| diff --git a/t/09sqlt-diagram.t b/t/09sqlt-diagram.t index 9e47a36..c18488e 100644 --- a/t/09sqlt-diagram.t +++ b/t/09sqlt-diagram.t @@ -7,6 +7,13 @@ use File::Spec::Functions qw(catfile updir tmpdir); use File::Temp qw(mktemp); use FindBin qw($Bin); use Test; +use Test::SQL::Translator qw(maybe_plan); + +BEGIN { + maybe_plan(3, + 'SQL::Translator::Parser::MySQL', + 'SQL::Translator::Producer::Diagram'); +} my @script = qw(blib script sqlt-diagram); my @data = qw(data mysql Apache-Session-MySQL.sql); @@ -21,19 +28,9 @@ my $test_data = (-d "t") my $tmp = mktemp('sqlXXXXX'); -BEGIN { - plan tests => 3; -} - ok(-e $sqlt_diagram); -eval { require GD; }; -if ($@ && $@ =~ /locate GD.pm in /) { - skip($@, "GD not installed"); - skip($@, "GD not installed"); -} else { - my @cmd = ($sqlt_diagram, "-d", "MySQL", "-o", $tmp, $test_data); - eval { system(@cmd); }; - ok(!$@ && ($? == 0)); - ok(-e $tmp); - eval { unlink $tmp; }; -} +my @cmd = ($sqlt_diagram, "-d", "MySQL", "-o", $tmp, $test_data); +eval { system(@cmd); }; +ok(!$@ && ($? == 0)); +ok(-e $tmp); +eval { unlink $tmp; }; diff --git a/t/10excel.t b/t/10excel.t index 7bee0de..0414d94 100644 --- a/t/10excel.t +++ b/t/10excel.t @@ -4,18 +4,13 @@ use Test::More; use SQL::Translator; use SQL::Translator::Schema::Constants; +use Test::SQL::Translator qw(maybe_plan); -eval { - require SQL::Translator::Parser::Excel; +BEGIN { + maybe_plan(31, 'SQL::Translator::Parser::Excel'); SQL::Translator::Parser::Excel->import('parse'); -}; -if ($@) { - plan skip_all => "$@"; } -else { - plan tests => 31; -} - + my $tr = SQL::Translator->new(parser => "Excel"); my $t = $tr->translate(filename => "t/data/Excel/t.xls"); my $schema = $tr->schema; diff --git a/t/14postgres-parser.t b/t/14postgres-parser.t index 8d4586d..0c32dd0 100644 --- a/t/14postgres-parser.t +++ b/t/14postgres-parser.t @@ -5,16 +5,11 @@ use strict; use Test::More; use SQL::Translator; use SQL::Translator::Schema::Constants; +use Test::SQL::Translator qw(maybe_plan); -eval { - require SQL::Translator::Parser::PostgreSQL; +BEGIN { + maybe_plan(119, 'SQL::Translator::Parser::PostgreSQL'); SQL::Translator::Parser::PostgreSQL->import('parse'); -}; -if ($@) { - plan skip_all => "$@"; -} -else { - plan tests => 119; } my $t = SQL::Translator->new( trace => 0 ); diff --git a/t/15oracle-parser.t b/t/15oracle-parser.t index 6377ad2..786ecd9 100644 --- a/t/15oracle-parser.t +++ b/t/15oracle-parser.t @@ -5,17 +5,10 @@ use strict; use Test::More; use SQL::Translator; use SQL::Translator::Schema::Constants; +use Test::SQL::Translator qw(maybe_plan); -eval { - require SQL::Translator::Parser::Oracle; - SQL::Translator::Parser::Oracle->import('parse'); -}; -if ($@) { - plan skip_all => "$@"; -} -else { - plan tests => 76; -} +maybe_plan(76, 'SQL::Translator::Parser::Oracle'); +SQL::Translator::Parser::Oracle->import('parse'); my $t = SQL::Translator->new( trace => 0 ); my $sql = q[ diff --git a/t/16xml-parser.t b/t/16xml-parser.t index 0661c98..a407d2c 100644 --- a/t/16xml-parser.t +++ b/t/16xml-parser.t @@ -25,8 +25,10 @@ use constant DEBUG => (exists $opt{d} ? 1 : 0); # Testing 1,2,3,4... #============================================================================= - -plan tests => 284; + +BEGIN { + maybe_plan(284, 'SQL::Translator::Parser::XML::SQLFairy'); +} foreach ( "$Bin/data/xml/schema-basic.xml", diff --git a/t/17sqlfxml-producer.t b/t/17sqlfxml-producer.t index 4e7af3c..54ccf8a 100644 --- a/t/17sqlfxml-producer.t +++ b/t/17sqlfxml-producer.t @@ -9,6 +9,7 @@ local $^W = 0; use strict; use Test::More; use Test::Exception; +use Test::SQL::Translator qw(maybe_plan); use Data::Dumper; my %opt; @@ -28,17 +29,14 @@ local $SIG{__WARN__} = sub { # Testing 1,2,3,4... #============================================================================= -eval { require XML::Writer; }; -if ($@ && $@ =~ m!locate XML::Writer.pm in!) { - plan skip_all => "You need XML::Writer to use XML::SQLFairy."; +BEGIN { + maybe_plan(18, + 'XML::Writer', + 'Test::Differences', + 'SQL::Translator::Producer::XML::SQLFairy'); } -eval { require Test::Differences; }; -if ($@ && $@ =~ m!locate Test/Differences.pm in!) { - plan skip_all => "You need Test::Differences for this test."; -} -use Test::Differences; -plan tests => 18; +use Test::Differences; use SQL::Translator; use SQL::Translator::Producer::XML::SQLFairy; diff --git a/t/18ttschema-producer.t b/t/18ttschema-producer.t index afe5025..ab13c31 100644 --- a/t/18ttschema-producer.t +++ b/t/18ttschema-producer.t @@ -7,6 +7,7 @@ use strict; use Test::More; use Test::Exception; +use Test::SQL::Translator qw(maybe_plan); use Data::Dumper; use vars '%opt'; @@ -19,16 +20,10 @@ use FindBin qw/$Bin/; # Testing 1,2,3,4... #============================================================================= -eval { require Template; }; -if ($@ && $@ =~ m!locate Template.pm in!) { - plan skip_all => "You need Template Toolkit to run this test."; -} -eval { require Test::Differences; }; -if ($@ && $@ =~ m!locate Test/Differences.pm in!) { - plan skip_all => "You need Test::Differences for this test."; +BEGIN { + maybe_plan(3, 'Template', 'Test::Differences') } use Test::Differences; -plan tests => 3; use SQL::Translator; use SQL::Translator::Producer::TTSchema; diff --git a/t/19sybase-parser.t b/t/19sybase-parser.t index 0324b1f..3a6e573 100644 --- a/t/19sybase-parser.t +++ b/t/19sybase-parser.t @@ -5,10 +5,15 @@ use strict; use FindBin qw/$Bin/; -use Test::More tests => 41; +use Test::More; +use Test::SQL::Translator qw(maybe_plan); use SQL::Translator; use SQL::Translator::Schema::Constants; -use SQL::Translator::Parser::Sybase qw(parse); + +BEGIN { + maybe_plan(41, 'SQL::Translator::Parser::Sybase'); + SQL::Translator::Parser::Sybase->import('parse'); +} my $file = "$Bin/data/sybase/create.sql"; diff --git a/t/21xml-xmi-parser.t b/t/21xml-xmi-parser.t index 15939c5..558252e 100644 --- a/t/21xml-xmi-parser.t +++ b/t/21xml-xmi-parser.t @@ -19,6 +19,7 @@ use constant DEBUG => (exists $opt{d} ? 1 : 0); use Test::More; use Test::Exception; +use Test::SQL::Translator qw(maybe_plan); use SQL::Translator; use SQL::Translator::Schema::Constants; @@ -78,7 +79,9 @@ sub test_table { # Testing 1,2,3,.. #============================================================================= -plan tests => 103; +maybe_plan(103, + 'SQL::Translator::Parser::XML::XMI', + 'SQL::Translator::Producer::MySQL'); my $testschema = "$Bin/data/xmi/Foo.poseidon2.xmi"; die "Can't find test schema $testschema" unless -e $testschema; diff --git a/t/22xml-xmi-parser-visibility.t b/t/22xml-xmi-parser-visibility.t index acad644..0502234 100644 --- a/t/22xml-xmi-parser-visibility.t +++ b/t/22xml-xmi-parser-visibility.t @@ -19,11 +19,14 @@ use constant DEBUG => (exists $opt{d} ? 1 : 0); use Test::More; use Test::Exception; +use Test::SQL::Translator qw(maybe_plan); use SQL::Translator; use SQL::Translator::Schema::Constants; -plan tests => 8; +maybe_plan(8, + 'SQL::Translator::Parser::XML::XMI', + 'SQL::Translator::Producer::MySQL'); my $testschema = "$Bin/data/xmi/Foo.poseidon2.xmi"; die "Can't find test schema $testschema" unless -e $testschema; diff --git a/t/23xml-xmi-parser-rational.t b/t/23xml-xmi-parser-rational.t index f1adb59..688b97a 100644 --- a/t/23xml-xmi-parser-rational.t +++ b/t/23xml-xmi-parser-rational.t @@ -15,9 +15,16 @@ use constant DEBUG => (exists $opt{d} ? 1 : 0); use Test::More; use Test::Exception; +use Test::SQL::Translator qw(maybe_plan); use SQL::Translator; use SQL::Translator::Schema::Constants; +BEGIN { + maybe_plan(92, + 'SQL::Translator::Parser::XML::XMI::Rational', + 'SQL::Translator::Producer::MySQL'); +} + # Usefull test subs for the schema objs #============================================================================= @@ -128,8 +135,6 @@ sub test_table { # Testing 1,2,3,.. #============================================================================= -plan tests => 92; - my $testschema = "$Bin/data/xmi/OrderDB.rationalprofile.poseidon2.xmi"; die "Can't find test schema $testschema" unless -e $testschema; diff --git a/t/24yaml.t b/t/24yaml.t index 5aa41ee..e578e18 100644 --- a/t/24yaml.t +++ b/t/24yaml.t @@ -2,11 +2,18 @@ # vim: set ft=perl: use strict; -use Test::More tests => 2; +use Test::More; use Test::Differences; +use Test::SQL::Translator qw(maybe_plan); use SQL::Translator; use FindBin '$Bin'; +BEGIN { + maybe_plan(2, + 'SQL::Translator::Parser::SQLite', + 'SQL::Translator::Producer::YAML'); +} + my $yaml = q/--- #YAML:1.0 schema: procedures: {} diff --git a/t/27sqlite-parser.t b/t/27sqlite-parser.t index 1b10e8a..8f1eac5 100644 --- a/t/27sqlite-parser.t +++ b/t/27sqlite-parser.t @@ -2,13 +2,19 @@ # vim: set ft=perl: use strict; -use Test::More tests => 5; +use Test::More; +use Test::SQL::Translator qw(maybe_plan); use FindBin qw/$Bin/; use SQL::Translator; -use SQL::Translator::Parser::SQLite 'parse'; use SQL::Translator::Schema::Constants; +BEGIN { + maybe_plan(5, + 'SQL::Translator::Parser::SQLite'); +} +SQL::Translator::Parser::SQLite->import('parse'); + my $file = "$Bin/data/sqlite/create.sql"; { diff --git a/t/28xml-xmi-parser-sqlfairy.t b/t/28xml-xmi-parser-sqlfairy.t index 3dd7f18..b6071cd 100644 --- a/t/28xml-xmi-parser-sqlfairy.t +++ b/t/28xml-xmi-parser-sqlfairy.t @@ -21,7 +21,11 @@ use SQL::Translator::Schema::Constants; # Testing 1,2,3,.. #============================================================================= -plan tests => 321; +BEGIN { + maybe_plan(321, + 'SQL::Translator::Parser::XML::XMI::SQLFairy', + 'SQL::Translator::Producer::MySQL'); +} my $testschema = "$Bin/data/xmi/OrderDB.sqlfairy.poseidon2.xmi"; die "Can't find test schema $testschema" unless -e $testschema; diff --git a/t/29html.t b/t/29html.t index b39cff2..f1f48fc 100644 --- a/t/29html.t +++ b/t/29html.t @@ -9,18 +9,20 @@ use strict; use vars qw(%HANDLERS); use Test::More; +use Test::SQL::Translator qw(maybe_plan); use SQL::Translator; -my ($p, $tables, $classes); -eval { - require HTML::Parser; - $p = HTML::Parser->new(api_version => 3); - $p->strict_names(1); -}; -if ($@) { - plan skip_all => "Missing HTML::Parser"; +BEGIN { + maybe_plan(5, + 'HTML::Parser', + 'SQL::Translator::Parser::MySQL', + 'SQL::Translator::Producer::HTML'); } +my ($p, $tables, $classes); +$p = HTML::Parser->new(api_version => 3); +$p->strict_names(1); + my $create = q| CREATE TABLE foo ( int id PRIMARY KEY AUTO_INCREMENT NOT NULL, @@ -36,13 +38,9 @@ eval { $status = $p->parse($parsed); }; if ($@) { - plan tests => 1; fail("Unable to parse the output!"); - exit 1; } -plan tests => 5; - # General ok($parsed, "Parsed table OK"); ok($status, "Parsed HTML OK"); diff --git a/t/30sqlt-diff.t b/t/30sqlt-diff.t index 4cba646..c745dae 100644 --- a/t/30sqlt-diff.t +++ b/t/30sqlt-diff.t @@ -6,6 +6,7 @@ use strict; use File::Spec::Functions qw(catfile updir tmpdir); use FindBin qw($Bin); use Test::More; +use Test::SQL::Translator qw(maybe_plan); my @script = qw(blib script sqlt-diff); my @create1 = qw(data sqlite create.sql); @@ -23,7 +24,12 @@ my $create2 = (-d "t") ? catfile($Bin, @create2) : catfile($Bin, "t", @create2); -plan tests => 3; +BEGIN { + maybe_plan(3, + 'SQL::Translator::Parser::SQLite', + 'SQL::Translator::Producer::YAML', + ); +} ok(-e $sqlt_diff, 'Found sqlt-diff script'); my @cmd = ($sqlt_diff, "$create1=SQLite", "$create2=SQLite");