Test-Script für Relationship-Klassennamen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 6 Jun 2013 13:52:12 +0000 (15:52 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 13 Jun 2013 14:31:34 +0000 (16:31 +0200)
t/rdbo_relationship_consistency.t [new file with mode: 0644]

diff --git a/t/rdbo_relationship_consistency.t b/t/rdbo_relationship_consistency.t
new file mode 100644 (file)
index 0000000..db35e80
--- /dev/null
@@ -0,0 +1,38 @@
+use Test::More;
+use Test::Exception;
+
+use strict;
+
+use lib 't';
+use utf8;
+
+use Data::Dumper;
+use Support::TestSetup;
+use File::Slurp;
+use IO::Dir;
+
+my %dir;
+tie %dir, 'IO::Dir', 'SL/DB';
+my @pms = grep { m/\.pm$/ } keys %dir;
+
+foreach my $pm (sort @pms) {
+  my $content = read_file("SL/DB/${pm}");
+  next unless $content =~ m/__PACKAGE__->meta->add_relationships?\((.+?)\);/s;
+  my $code = $1;
+
+  my @not_existing;
+  while ($code =~ m/\b(?:map_)?class\s*=>\s*['"]SL::DB::(.+?)['"]/g) {
+    push @not_existing, $1 unless -f "SL/DB/${1}.pm";
+  }
+
+  if (@not_existing) {
+    fail("$pm: Non-existing relationship model(s) " . join(' ', @not_existing));
+  } else {
+    pass("$pm: all relationship model(s) exist");
+  }
+}
+
+# print Dumper(\@pms);
+
+
+done_testing();