From: Dagfinn Ilmari Mannsåker Date: Sat, 9 Aug 2014 19:30:49 +0000 (+0100) Subject: Fix unescaped left braces in regexes in tests X-Git-Tag: 0.07042~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7c304e590cd0eac21aed4c62266e43129d6ff9ce;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Fix unescaped left braces in regexes in tests They cause deprecation warnings in perl 5.21.x. --- diff --git a/Changes b/Changes index 53159ef..7f6066b 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - Fix unescaped left braces in regexes in tests + 0.07041 2014-08-09 - Fix many_to_many bridges going back to the same table - Don't disconnect after ->load in static mode diff --git a/t/23dumpmore.t b/t/23dumpmore.t index dd52596..9490b2f 100644 --- a/t/23dumpmore.t +++ b/t/23dumpmore.t @@ -189,7 +189,7 @@ $t->dump_test( qr/\n=head1 TABLE: C\n\n=cut\n\n__PACKAGE__->table\("foo"\);\n\n/, qr/\n=head1 ACCESSORS\n\n/, qr/\n=head2 fooid\n\n data_type: 'integer'\n is_auto_increment: 1\n is_nullable: 0\n\n/, - qr/\n=head2 footext\n\n data_type: 'text'\n default_value: 'footext'\n extra: {is_footext => 1}\n is_nullable: 1\n\n/, + qr/\n=head2 footext\n\n data_type: 'text'\n default_value: 'footext'\n extra: \{is_footext => 1\}\n is_nullable: 1\n\n/, qr/\n=head1 PRIMARY KEY\n\n=over 4\n\n=item \* L<\/fooid>\n\n=back\n\n=cut\n\n__PACKAGE__->set_primary_key\("fooid"\);\n/, qr/\n=head1 RELATIONS\n\n/, qr/\n=head2 bars\n\nType: has_many\n\nRelated object: L\n\n=cut\n\n/, @@ -580,7 +580,7 @@ $t->dump_test( generated_results => [qw(Foo Bar)], regexes => { 'Result/Foo' => [ - qr/sub custom_method { 'custom_method works' }\n0;\n\n# You can replace.*\n1;\n\z/, + qr/sub custom_method \{ 'custom_method works' \}\n0;\n\n# You can replace.*\n1;\n\z/, ], }, ); diff --git a/t/25backcompat.t b/t/25backcompat.t index 57a9c04..2243144 100644 --- a/t/25backcompat.t +++ b/t/25backcompat.t @@ -19,18 +19,19 @@ my $SCHEMA_CLASS = 'DBIXCSL_Test::Schema'; my $RESULT_COUNT = 7; -sub class_content_like; +sub class_content_contains; +sub contains; # test dynamic schema in 0.04006 mode { my $res = run_loader(); my $warning = $res->{warnings}[0]; - like $warning, qr/dynamic schema/i, + contains $warning, 'Dynamic schema', 'dynamic schema in backcompat mode detected'; - like $warning, qr/run in 0\.04006 mode/i, + contains $warning, 'run in 0.04006 mode', 'dynamic schema in 0.04006 mode warning'; - like $warning, qr/DBIx::Class::Schema::Loader::Manual::UpgradingFromV4/, + contains $warning, 'DBIx::Class::Schema::Loader::Manual::UpgradingFromV4', 'warning refers to upgrading doc'; run_v4_tests($res); @@ -66,7 +67,7 @@ sub class_content_like; 'content for unsingularized Result.'; my $warning = $res->{warnings}[0]; - like $warning, qr/Detected external content/i, + contains $warning, 'Detected external content', 'detected external content warning'; lives_and { is $schema->resultset('Quux')->find(1)->a_method, 'hlagh' } @@ -103,7 +104,7 @@ sub class_content_like; 'content for unsingularized Result with use_namespaces.'; my $warning = $res->{warnings}[0]; - like $warning, qr/Detected external content/i, + contains $warning, "Detected external content", 'detected external content warning'; lives_and { is $schema->resultset('Quux')->find(1)->a_method, 'hlagh' } @@ -151,10 +152,10 @@ sub class_content_like; 'unsingularized class names in external content from unchanged Result class ' . 'names are translated in static schema'; - class_content_like $schema, $res->{classes}{quuxs}, qr/package ${SCHEMA_CLASS}::Quux;/, + class_content_contains $schema, $res->{classes}{quuxs}, "package ${SCHEMA_CLASS}::Quux;", 'package line translated correctly from external custom content in static dump'; - class_content_like $schema, $res->{classes}{quuxs}, qr/sub a_method { 'hlagh' }/, + class_content_contains $schema, $res->{classes}{quuxs}, "sub a_method { 'hlagh' }", 'external custom content loaded into static dump correctly'; } @@ -165,11 +166,11 @@ sub class_content_like; my $res = run_loader(static => 1); my $warning = $res->{warnings}[1]; - like $warning, qr/static schema/i, + contains $warning, "static schema", 'static schema in backcompat mode detected'; - like $warning, qr/0.04006/, + contains $warning, "0.04006", 'correct version detected'; - like $warning, qr/DBIx::Class::Schema::Loader::Manual::UpgradingFromV4/, + contains $warning, "DBIx::Class::Schema::Loader::Manual::UpgradingFromV4", 'refers to upgrading doc'; is scalar @{ $res->{warnings} }, 4, @@ -194,10 +195,10 @@ sub class_content_like; ); my $schema = $res->{schema}; - like $res->{warnings}[0], qr/Dumping manual schema/i, + contains $res->{warnings}[0], "Dumping manual schema", 'correct warnings on upgrading static schema (with "naming" set)'; - like $res->{warnings}[1], qr/dump completed/i, + contains $res->{warnings}[1], "dump completed", 'correct warnings on upgrading static schema (with "naming" set)'; is scalar @{ $res->{warnings} }, 2, @@ -217,7 +218,7 @@ sub class_content_like; $res->{classes}{bazs} } 'unsingularized class names in custom content are translated'; - class_content_like $schema, $res->{classes}{quuxs}, qr/sub b_method { 'dongs' }/, + class_content_contains $schema, $res->{classes}{quuxs}, "sub b_method { 'dongs' }", 'custom content from unsingularized Result loaded into static dump correctly'; } @@ -229,11 +230,11 @@ sub class_content_like; my $res = run_loader(static => 1); my $warning = $res->{warnings}[1]; - like $warning, qr/static schema/i, + contains $warning, "static schema", 'static schema in backcompat mode detected'; - like $warning, qr/0.04006/, + contains $warning, "0.04006", 'correct version detected'; - like $warning, qr/DBIx::Class::Schema::Loader::Manual::UpgradingFromV4/, + contains $warning, "DBIx::Class::Schema::Loader::Manual::UpgradingFromV4", 'refers to upgrading doc'; is scalar @{ $res->{warnings} }, 4, @@ -252,15 +253,15 @@ sub class_content_like; ); my $schema = $res->{schema}; - like $res->{warnings}[0], qr/load_classes/i, + contains $res->{warnings}[0], "load_classes", 'correct warnings on upgrading static schema (with "naming" set and ' . 'use_namespaces not set)'; - like $res->{warnings}[1], qr/Dumping manual schema/i, + contains $res->{warnings}[1], "Dumping manual schema", 'correct warnings on upgrading static schema (with "naming" set and ' . 'use_namespaces not set)'; - like $res->{warnings}[2], qr/dump completed/i, + contains $res->{warnings}[2], "dump completed", 'correct warnings on upgrading static schema (with "naming" set and ' . 'use_namespaces not set)'; @@ -281,7 +282,7 @@ sub class_content_like; $res->{classes}{bazs} } 'unsingularized class names in custom content are translated'; - class_content_like $schema, $res->{classes}{quuxs}, qr/sub b_method { 'dongs' }/, + class_content_contains $schema, $res->{classes}{quuxs}, "sub b_method { 'dongs' }", 'custom content from unsingularized Result loaded into static dump correctly'; } @@ -300,11 +301,11 @@ sub class_content_like; my $res = run_loader(static => 1); my $warning = $res->{warnings}[0]; - like $warning, qr/static schema/i, + contains $warning, "static schema", 'static schema in backcompat mode detected'; - like $warning, qr/0.04006/, + contains $warning, "0.04006", 'correct version detected'; - like $warning, qr/DBIx::Class::Schema::Loader::Manual::UpgradingFromV4/, + contains $warning, "DBIx::Class::Schema::Loader::Manual::UpgradingFromV4", 'refers to upgrading doc'; is scalar @{ $res->{warnings} }, 3, @@ -330,11 +331,11 @@ sub class_content_like; ); my $schema = $res->{schema}; - like $res->{warnings}[0], qr/Dumping manual schema/i, + contains $res->{warnings}[0], "Dumping manual schema", 'correct warnings on upgrading static schema (with "naming" set and ' . 'use_namespaces => 0)'; - like $res->{warnings}[1], qr/dump completed/i, + contains $res->{warnings}[1], "dump completed", 'correct warnings on upgrading static schema (with "naming" set and ' . 'use_namespaces => 0)'; @@ -373,10 +374,10 @@ sub class_content_like; 'unsingularized class names in external content from unchanged Result class ' . 'names are translated in static schema'; - class_content_like $schema, $res->{classes}{quuxs}, qr/sub a_method { 'hlagh' }/, + class_content_contains $schema, $res->{classes}{quuxs}, "sub a_method { 'hlagh' }", 'external content from unsingularized Result loaded into static dump correctly'; - class_content_like $schema, $res->{classes}{quuxs}, qr/sub b_method { 'dongs' }/, + class_content_contains $schema, $res->{classes}{quuxs}, "sub b_method { 'dongs' }", 'custom content from unsingularized Result loaded into static dump correctly'; } @@ -390,10 +391,10 @@ sub class_content_like; naming => 'current', ); - like $res->{warnings}[0], qr/Dumping manual schema/i, + contains $res->{warnings}[0], "Dumping manual schema", 'correct warnings on dumping static schema with use_namespaces => 0'; - like $res->{warnings}[1], qr/dump completed/i, + contains $res->{warnings}[1], "dump completed", 'correct warnings on dumping static schema with use_namespaces => 0'; is scalar @{ $res->{warnings} }, 2, @@ -411,13 +412,13 @@ sub class_content_like; # load_classes is preserved $res = run_loader(static => 1, naming => 'current'); - like $res->{warnings}[0], qr/load_classes/i, + contains $res->{warnings}[0], "load_classes", 'correct warnings on re-dumping static schema with load_classes'; - like $res->{warnings}[1], qr/Dumping manual schema/i, + contains $res->{warnings}[1], "Dumping manual schema", 'correct warnings on re-dumping static schema with load_classes'; - like $res->{warnings}[2], qr/dump completed/i, + contains $res->{warnings}[2], "dump completed", 'correct warnings on re-dumping static schema with load_classes'; is scalar @{ $res->{warnings} }, 3, @@ -437,10 +438,10 @@ sub class_content_like; ); $schema = $res->{schema}; - like $res->{warnings}[0], qr/Dumping manual schema/i, + contains $res->{warnings}[0], "Dumping manual schema", 'correct warnings on upgrading to use_namespaces'; - like $res->{warnings}[1], qr/dump completed/i, + contains $res->{warnings}[1], "dump completed", 'correct warnings on upgrading to use_namespaces'; is scalar @{ $res->{warnings} }, 2, @@ -465,7 +466,7 @@ sub class_content_like; $res->{classes}{bazs} } 'un-namespaced class names in custom content are translated'; - class_content_like $schema, $res->{classes}{quuxs}, qr/sub b_method { 'dongs' }/, + class_content_contains $schema, $res->{classes}{quuxs}, "sub b_method { 'dongs' }", 'custom content from un-namespaced Result loaded into static dump correctly'; } @@ -474,10 +475,10 @@ sub class_content_like; { my $res = run_loader(clean_dumpdir => 1, static => 1, naming => 'current'); - like $res->{warnings}[0], qr/Dumping manual schema/i, + contains $res->{warnings}[0], "Dumping manual schema", 'correct warnings on dumping static schema'; - like $res->{warnings}[1], qr/dump completed/i, + contains $res->{warnings}[1], "dump completed", 'correct warnings on dumping static schema'; is scalar @{ $res->{warnings} }, 2, @@ -494,10 +495,10 @@ sub class_content_like; # test that with no use_namespaces option, use_namespaces is preserved $res = run_loader(static => 1, naming => 'current'); - like $res->{warnings}[0], qr/Dumping manual schema/i, + contains $res->{warnings}[0], "Dumping manual schema", 'correct warnings on re-dumping static schema'; - like $res->{warnings}[1], qr/dump completed/i, + contains $res->{warnings}[1], "dump completed", 'correct warnings on re-dumping static schema'; is scalar @{ $res->{warnings} }, 2, @@ -517,10 +518,10 @@ sub class_content_like; ); my $schema = $res->{schema}; - like $res->{warnings}[0], qr/Dumping manual schema/i, + contains $res->{warnings}[0], "Dumping manual schema", 'correct warnings on downgrading to load_classes'; - like $res->{warnings}[1], qr/dump completed/i, + contains $res->{warnings}[1], "dump completed", 'correct warnings on downgrading to load_classes'; is scalar @{ $res->{warnings} }, 2, @@ -547,7 +548,7 @@ sub class_content_like; 'namespaced class names in custom content are translated during load_classes '. 'downgrade'; - class_content_like $schema, $res->{classes}{quuxs}, qr/sub b_method { 'dongs' }/, + class_content_contains $schema, $res->{classes}{quuxs}, "sub b_method { 'dongs' }", 'custom content from namespaced Result loaded into static dump correctly '. 'during load_classes downgrade'; } @@ -562,10 +563,10 @@ sub class_content_like; naming => 'current', ); - like $res->{warnings}[0], qr/Dumping manual schema/i, + contains $res->{warnings}[0], "Dumping manual schema", 'correct warnings on dumping static schema'; - like $res->{warnings}[1], qr/dump completed/i, + contains $res->{warnings}[1], "dump completed", 'correct warnings on dumping static schema'; is scalar @{ $res->{warnings} }, 2, @@ -583,10 +584,10 @@ sub class_content_like; # the custom result_namespace is preserved $res = run_loader(static => 1, naming => 'current'); - like $res->{warnings}[0], qr/Dumping manual schema/i, + contains $res->{warnings}[0], "Dumping manual schema", 'correct warnings on re-dumping static schema'; - like $res->{warnings}[1], qr/dump completed/i, + contains $res->{warnings}[1], "dump completed", 'correct warnings on re-dumping static schema'; is scalar @{ $res->{warnings} }, 2, @@ -606,10 +607,10 @@ sub class_content_like; ); my $schema = $res->{schema}; - like $res->{warnings}[0], qr/Dumping manual schema/i, + contains $res->{warnings}[0], "Dumping manual schema", 'correct warnings on downgrading to load_classes'; - like $res->{warnings}[1], qr/dump completed/i, + contains $res->{warnings}[1], "dump completed", 'correct warnings on downgrading to load_classes'; is scalar @{ $res->{warnings} }, 2, @@ -636,7 +637,7 @@ sub class_content_like; 'namespaced class names in custom content are translated during load_classes '. 'downgrade'; - class_content_like $schema, $res->{classes}{quuxs}, qr/sub b_method { 'dongs' }/, + class_content_contains $schema, $res->{classes}{quuxs}, "sub b_method { 'dongs' }", 'custom content from namespaced Result loaded into static dump correctly '. 'during load_classes downgrade'; } @@ -676,7 +677,7 @@ sub class_content_like; $res->{classes}{bazs} } 'class names in custom content are translated when rewriting result_namespace'; - class_content_like $schema, $res->{classes}{quuxs}, qr/sub b_method { 'dongs' }/, + class_content_contains $schema, $res->{classes}{quuxs}, "sub b_method { 'dongs' }", 'custom content from namespaced Result loaded into static dump correctly '. 'when rewriting result_namespace'; @@ -718,11 +719,11 @@ sub class_content_like; 'class names in external content are translated when rewriting '. 'result_namespace'; - class_content_like $schema, $res->{classes}{quuxs}, qr/sub b_method { 'dongs' }/, + class_content_contains $schema, $res->{classes}{quuxs}, "sub b_method { 'dongs' }", 'custom content from namespaced Result loaded into static dump correctly '. 'when rewriting result_namespace'; - class_content_like $schema, $res->{classes}{quuxs}, qr/sub a_method { 'hlagh' }/, + class_content_contains $schema, $res->{classes}{quuxs}, "sub a_method { 'hlagh' }", 'external content from unsingularized Result loaded into static dump correctly'; } @@ -770,7 +771,7 @@ sub class_content_like; 'unsingularized class names in custom content from Result with unchanged ' . 'name are translated'; - class_content_like $schema, $res->{classes}{bar}, qr/sub b_method { 'dongs' }/, + class_content_contains $schema, $res->{classes}{bar}, "sub b_method { 'dongs' }", 'custom content from Result with unchanged name loaded into static dump ' . 'correctly'; } @@ -784,7 +785,7 @@ sub class_content_like; my $res = run_loader(static => 1); - like $res->{warnings}[0], qr/0.05003 static schema/, 'backcompat warning'; + contains $res->{warnings}[0], "0.05003 static schema", 'backcompat warning'; run_v5_tests($res); @@ -830,7 +831,7 @@ sub class_content_like; my $res = run_loader(static => 1); - like $res->{warnings}[0], qr/0.06001 static schema/, 'backcompat warning'; + contains $res->{warnings}[0], "0.06001 static schema", 'backcompat warning'; run_v6_tests($res); @@ -1298,13 +1299,23 @@ sub _rel_condition { }->{_rel_key($from, $to)}; } -sub class_content_like { - my ($schema, $class, $re, $test_name) = @_; +sub class_content_contains { + my ($schema, $class, $substr, $test_name) = @_; my $file = $schema->loader->get_dump_filename($class); my $code = slurp_file $file; - like $code, $re, $test_name; + local $Test::Builder::Level = $Test::Builder::Level + 1; + + contains $code, $substr, $test_name; +} + +sub contains { + my ($haystack, $needle, $test_name) = @_; + + local $Test::Builder::Level = $Test::Builder::Level + 1; + + like $haystack, qr/\Q$needle\E/, $test_name; } sub add_custom_content {