Permalink
Browse files

create t_dbic test directory, for new tests using DBIC test schema

  • Loading branch information...
1 parent 401b514 commit 2d4b00e0ec324a795af677100ef864db0f8ac60e @gshank gshank committed Jun 22, 2012
Showing with 3,754 additions and 0 deletions.
  1. +518 −0 t_dbic/lib/DBICTest.pm
  2. +35 −0 t_dbic/lib/DBICTest/BaseResult.pm
  3. +16 −0 t_dbic/lib/DBICTest/BaseResultSet.pm
  4. +12 −0 t_dbic/lib/DBICTest/BaseSchema.pm
  5. +7 −0 t_dbic/lib/DBICTest/Cursor.pm
  6. +16 −0 t_dbic/lib/DBICTest/DeployComponent.pm
  7. +8 −0 t_dbic/lib/DBICTest/ErrorComponent.pm
  8. +7 −0 t_dbic/lib/DBICTest/FakeComponent.pm
  9. +11 −0 t_dbic/lib/DBICTest/ForeignComponent.pm
  10. +9 −0 t_dbic/lib/DBICTest/ForeignComponent/TestComp.pm
  11. +7 −0 t_dbic/lib/DBICTest/OptionalComponent.pm
  12. +7 −0 t_dbic/lib/DBICTest/ResultSetManager.pm
  13. +10 −0 t_dbic/lib/DBICTest/ResultSetManager/Foo.pm
  14. +184 −0 t_dbic/lib/DBICTest/RunMode.pm
  15. +229 −0 t_dbic/lib/DBICTest/Schema.pm
  16. +162 −0 t_dbic/lib/DBICTest/Schema/Artist.pm
  17. +35 −0 t_dbic/lib/DBICTest/Schema/ArtistGUID.pm
  18. +8 −0 t_dbic/lib/DBICTest/Schema/ArtistSourceName.pm
  19. +8 −0 t_dbic/lib/DBICTest/Schema/ArtistSubclass.pm
  20. +21 −0 t_dbic/lib/DBICTest/Schema/ArtistUndirectedMap.pm
  21. +49 −0 t_dbic/lib/DBICTest/Schema/Artwork.pm
  22. +66 −0 t_dbic/lib/DBICTest/Schema/Artwork_to_Artist.pm
  23. +33 −0 t_dbic/lib/DBICTest/Schema/BindType.pm
  24. +31 −0 t_dbic/lib/DBICTest/Schema/Bookmark.pm
  25. +36 −0 t_dbic/lib/DBICTest/Schema/BooksInLibrary.pm
  26. +132 −0 t_dbic/lib/DBICTest/Schema/CD.pm
  27. +25 −0 t_dbic/lib/DBICTest/Schema/CD_to_Producer.pm
  28. +30 −0 t_dbic/lib/DBICTest/Schema/Collection.pm
  29. +24 −0 t_dbic/lib/DBICTest/Schema/CollectionObject.pm
  30. +34 −0 t_dbic/lib/DBICTest/Schema/ComputedColumn.pm
  31. +17 −0 t_dbic/lib/DBICTest/Schema/CustomSql.pm
  32. +26 −0 t_dbic/lib/DBICTest/Schema/Dummy.pm
  33. +51 −0 t_dbic/lib/DBICTest/Schema/Employee.pm
  34. +41 −0 t_dbic/lib/DBICTest/Schema/Encoded.pm
  35. +36 −0 t_dbic/lib/DBICTest/Schema/Event.pm
  36. +18 −0 t_dbic/lib/DBICTest/Schema/EventSmallDT.pm
  37. +24 −0 t_dbic/lib/DBICTest/Schema/EventTZ.pm
  38. +25 −0 t_dbic/lib/DBICTest/Schema/EventTZDeprecated.pm
  39. +30 −0 t_dbic/lib/DBICTest/Schema/EventTZPg.pm
  40. +32 −0 t_dbic/lib/DBICTest/Schema/ForceForeign.pm
  41. +29 −0 t_dbic/lib/DBICTest/Schema/FourKeys.pm
  42. +33 −0 t_dbic/lib/DBICTest/Schema/FourKeys_to_TwoKeys.pm
  43. +25 −0 t_dbic/lib/DBICTest/Schema/Genre.pm
  44. +28 −0 t_dbic/lib/DBICTest/Schema/Image.pm
  45. +21 −0 t_dbic/lib/DBICTest/Schema/LinerNotes.pm
  46. +32 −0 t_dbic/lib/DBICTest/Schema/Link.pm
  47. +25 −0 t_dbic/lib/DBICTest/Schema/LyricVersion.pm
  48. +21 −0 t_dbic/lib/DBICTest/Schema/Lyrics.pm
  49. +21 −0 t_dbic/lib/DBICTest/Schema/Money.pm
  50. +15 −0 t_dbic/lib/DBICTest/Schema/NoPrimaryKey.pm
  51. +6 −0 t_dbic/lib/DBICTest/Schema/NoSuchClass.pm
  52. +22 −0 t_dbic/lib/DBICTest/Schema/OneKey.pm
  53. +23 −0 t_dbic/lib/DBICTest/Schema/Owners.pm
  54. +24 −0 t_dbic/lib/DBICTest/Schema/Producer.pm
  55. +31 −0 t_dbic/lib/DBICTest/Schema/PunctuatedColumnName.pm
  56. +21 −0 t_dbic/lib/DBICTest/Schema/SelfRef.pm
  57. +20 −0 t_dbic/lib/DBICTest/Schema/SelfRefAlias.pm
  58. +37 −0 t_dbic/lib/DBICTest/Schema/SequenceTest.pm
  59. +13 −0 t_dbic/lib/DBICTest/Schema/Serialized.pm
  60. +35 −0 t_dbic/lib/DBICTest/Schema/Tag.pm
  61. +17 −0 t_dbic/lib/DBICTest/Schema/TimestampPrimaryKey.pm
  62. +106 −0 t_dbic/lib/DBICTest/Schema/Track.pm
  63. +28 −0 t_dbic/lib/DBICTest/Schema/TreeLike.pm
  64. +21 −0 t_dbic/lib/DBICTest/Schema/TwoKeyTreeLike.pm
  65. +30 −0 t_dbic/lib/DBICTest/Schema/TwoKeys.pm
  66. +28 −0 t_dbic/lib/DBICTest/Schema/TypedObject.pm
  67. +34 −0 t_dbic/lib/DBICTest/Schema/VaryingMAX.pm
  68. +39 −0 t_dbic/lib/DBICTest/Schema/Year1999CDs.pm
  69. +19 −0 t_dbic/lib/DBICTest/Schema/Year2000CDs.pm
  70. +63 −0 t_dbic/lib/DBICTest/Stats.pm
  71. +9 −0 t_dbic/lib/DBICTest/SyntaxErrorComponent1.pm
  72. +9 −0 t_dbic/lib/DBICTest/SyntaxErrorComponent2.pm
  73. +5 −0 t_dbic/lib/DBICTest/SyntaxErrorComponent3.pm
  74. +7 −0 t_dbic/lib/DBICTest/Taint/Classes/Auto.pm
  75. +7 −0 t_dbic/lib/DBICTest/Taint/Classes/Manual.pm
  76. +7 −0 t_dbic/lib/DBICTest/Taint/Namespaces/Result/Test.pm
  77. +135 −0 t_dbic/lib/DBICTest/Util.pm
  78. +134 −0 t_dbic/lib/DBICTest/Util/OverrideRequire.pm
  79. +466 −0 t_dbic/lib/sqlite.sql
  80. +38 −0 t_dbic/might_have.t
View
Oops, something went wrong.
@@ -0,0 +1,35 @@
+package #hide from pause
+ DBICTest::BaseResult;
+
+use strict;
+use warnings;
+
+# must load before any DBIx::Class* namespaces
+use DBICTest::RunMode;
+
+use base 'DBIx::Class::Core';
+
+#use base qw/DBIx::Class::Relationship::Cascade::Rekey DBIx::Class::Core/;
+
+__PACKAGE__->table ('bogus');
+__PACKAGE__->resultset_class ('DBICTest::BaseResultSet');
+
+#sub add_relationship {
+# my $self = shift;
+# my $opts = $_[3] || {};
+# if (grep { $_ eq $_[0] } qw/
+# cds_90s cds_80s cds_84 artist_undirected_maps mapped_artists last_track
+# /) {
+# # nothing - join-dependent or non-cascadeable relationship
+# }
+# elsif ($opts->{is_foreign_key_constraint}) {
+# $opts->{on_update} ||= 'cascade';
+# }
+# else {
+# $opts->{cascade_rekey} = 1
+# unless ref $_[2] eq 'CODE';
+# }
+# $self->next::method(@_[0..2], $opts);
+#}
+
+1;
@@ -0,0 +1,16 @@
+package #hide from pause
+ DBICTest::BaseResultSet;
+
+use strict;
+use warnings;
+
+# must load before any DBIx::Class* namespaces
+use DBICTest::RunMode;
+
+use base 'DBIx::Class::ResultSet';
+
+sub all_hri {
+ return [ shift->search ({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' })->all ];
+}
+
+1;
@@ -0,0 +1,12 @@
+package #hide from pause
+ DBICTest::BaseSchema;
+
+use strict;
+use warnings;
+
+# must load before any DBIx::Class* namespaces
+use DBICTest::RunMode;
+
+use base 'DBIx::Class::Schema';
+
+1;
@@ -0,0 +1,7 @@
+package DBICTest::Cursor;
+
+use strict;
+use warnings;
+use base qw/DBIx::Class::Storage::DBI::Cursor/;
+
+1;
@@ -0,0 +1,16 @@
+# belongs to t/86sqlt.t
+package # hide from PAUSE
+ DBICTest::DeployComponent;
+use warnings;
+use strict;
+
+our $hook_cb;
+
+sub sqlt_deploy_hook {
+ my $class = shift;
+
+ $hook_cb->($class, @_) if $hook_cb;
+ $class->next::method(@_) if $class->next::can;
+}
+
+1;
@@ -0,0 +1,8 @@
+# belongs to t/run/90ensure_class_loaded.tl
+package # hide from PAUSE
+ DBICTest::ErrorComponent;
+use warnings;
+use strict;
+
+# this is missing on purpose
+# 1;
@@ -0,0 +1,7 @@
+# belongs to t/run/90ensure_class_loaded.tl
+package # hide from PAUSE
+ DBICTest::FakeComponent;
+use warnings;
+use strict;
+
+1;
@@ -0,0 +1,11 @@
+# belongs to t/05components.t
+package # hide from PAUSE
+ DBICTest::ForeignComponent;
+use warnings;
+use strict;
+
+use base qw/ DBIx::Class /;
+
+__PACKAGE__->load_components( qw/ +DBICTest::ForeignComponent::TestComp / );
+
+1;
@@ -0,0 +1,9 @@
+# belongs to t/05components.t
+package # hide from PAUSE
+ DBICTest::ForeignComponent::TestComp;
+use warnings;
+use strict;
+
+sub foreign_test_method { 1 }
+
+1;
@@ -0,0 +1,7 @@
+# belongs to t/run/90ensure_class_loaded.tl
+package # hide from PAUSE
+ DBICTest::OptionalComponent;
+use warnings;
+use strict;
+
+1;
@@ -0,0 +1,7 @@
+package # hide from PAUSE
+ DBICTest::ResultSetManager;
+use base 'DBICTest::BaseSchema';
+
+__PACKAGE__->load_classes("Foo");
+
+1;
@@ -0,0 +1,10 @@
+package # hide from PAUSE
+ DBICTest::ResultSetManager::Foo;
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->load_components(qw/ ResultSetManager /);
+__PACKAGE__->table('foo');
+
+sub bar : ResultSet { 'good' }
+
+1;
@@ -0,0 +1,184 @@
+package # hide from PAUSE
+ DBICTest::RunMode;
+
+use strict;
+use warnings;
+
+BEGIN {
+ if ($INC{'DBIx/Class.pm'}) {
+ my ($fr, @frame) = 1;
+ while (@frame = caller($fr++)) {
+ last if $frame[1] !~ m|^t/lib/DBICTest|;
+ }
+
+ die __PACKAGE__ . " must be loaded before DBIx::Class (or modules using DBIx::Class) at $frame[1] line $frame[2]\n";
+ }
+}
+
+use Path::Class qw/file dir/;
+use File::Spec;
+
+_check_author_makefile() unless $ENV{DBICTEST_NO_MAKEFILE_VERIFICATION};
+
+# PathTools has a bug where on MSWin32 it will often return / as a tmpdir.
+# This is *really* stupid and the result of having our lockfiles all over
+# the place is also rather obnoxious. So we use our own heuristics instead
+# https://rt.cpan.org/Ticket/Display.html?id=76663
+my $tmpdir;
+sub tmpdir {
+ dir ($tmpdir ||= do {
+
+ my $dir = dir(File::Spec->tmpdir);
+
+ my @parts = File::Spec->splitdir($dir);
+ if (@parts == 2 and $parts[1] eq '') {
+ # This means we were give the root dir (C:\ or something equally unacceptable)
+ # Replace with our local project tmpdir. This will make multiple runs
+ # from different runs conflict with each other, but is much better than
+ # polluting the root dir with random crap
+ $dir = _find_co_root()->subdir('t')->subdir('var');
+ $dir->mkpath;
+ }
+
+ $dir->stringify;
+ });
+}
+
+
+# Die if the author did not update his makefile
+#
+# This is pretty heavy handed, so the check is pretty solid:
+#
+# 1) Assume that this particular module is loaded from -I <$root>/t/lib
+# 2) Make sure <$root>/Makefile.PL exists
+# 3) Make sure we can stat() <$root>/Makefile.PL
+#
+# If all of the above is satisfied
+#
+# *) die if <$root>/inc does not exist
+# *) die if no stat() results for <$root>/Makefile (covers no Makefile)
+# *) die if Makefile.PL mtime > Makefile mtime
+#
+sub _check_author_makefile {
+
+ my $root = _find_co_root()
+ or return;
+
+ my $optdeps = file('lib/DBIx/Class/Optional/Dependencies.pm');
+
+ # not using file->stat as it invokes File::stat which in turn breaks stat(_)
+ my ($mf_pl_mtime, $mf_mtime, $optdeps_mtime) = ( map
+ { (stat ($root->file ($_)) )[9] || undef } # stat returns () on nonexistent files
+ (qw|Makefile.PL Makefile|, $optdeps)
+ );
+
+ return unless $mf_pl_mtime; # something went wrong during co_root detection ?
+
+ my @fail_reasons;
+
+ if(not -d $root->subdir ('inc')) {
+ push @fail_reasons, "Missing ./inc directory";
+ }
+
+ if(not $mf_mtime) {
+ push @fail_reasons, "Missing ./Makefile";
+ }
+ else {
+ if($mf_mtime < $mf_pl_mtime) {
+ push @fail_reasons, "./Makefile.PL is newer than ./Makefile";
+ }
+ if($mf_mtime < $optdeps_mtime) {
+ push @fail_reasons, "./$optdeps is newer than ./Makefile";
+ }
+ }
+
+ if (@fail_reasons) {
+ print STDERR <<'EOE';
+
+
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+======================== FATAL ERROR ===========================
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+We have a number of reasons to believe that this is a development
+checkout and that you, the user, did not run `perl Makefile.PL`
+before using this code. You absolutely _must_ perform this step,
+to ensure you have all required dependencies present. Not doing
+so often results in a lot of wasted time for other contributors
+trying to assit you with spurious "its broken!" problems.
+
+By default DBICs Makefile.PL turns all optional dependenciess into
+*HARD REQUIREMENTS*, in order to make sure that the entire test
+suite is executed, and no tests are skipped due to missing modules.
+If you for some reason need to disable this behavior - supply the
+--skip_author_deps option when running perl Makefile.PL
+
+If you are seeing this message unexpectedly (i.e. you are in fact
+attempting a regular installation be it through CPAN or manually),
+please report the situation to either the mailing list or to the
+irc channel as described in
+
+http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class.pm#GETTING_HELP/SUPPORT
+
+The DBIC team
+
+
+Reasons you received this message:
+
+EOE
+
+ foreach my $r (@fail_reasons) {
+ print STDERR " * $r\n";
+ }
+ print STDERR "\n\n\n";
+
+ exit 1;
+ }
+}
+
+# Mimic $Module::Install::AUTHOR
+sub is_author {
+
+ my $root = _find_co_root()
+ or return undef;
+
+ return (
+ ( not -d $root->subdir ('inc') )
+ or
+ ( -e $root->subdir ('inc')->subdir ($^O eq 'VMS' ? '_author' : '.author') )
+ );
+}
+
+sub is_smoker {
+ return ( $ENV{AUTOMATED_TESTING} && ! $ENV{PERL5_CPANM_IS_RUNNING} && ! $ENV{RELEASE_TESTING} )
+}
+
+sub is_plain {
+ return (! __PACKAGE__->is_smoker && ! __PACKAGE__->is_author && ! $ENV{RELEASE_TESTING} )
+}
+
+# Try to determine the root of a checkout/untar if possible
+# or return undef
+sub _find_co_root {
+
+ my @mod_parts = split /::/, (__PACKAGE__ . '.pm');
+ my $rel_path = join ('/', @mod_parts); # %INC stores paths with / regardless of OS
+
+ return undef unless ($INC{$rel_path});
+
+ # a bit convoluted, but what we do here essentially is:
+ # - get the file name of this particular module
+ # - do 'cd ..' as many times as necessary to get to t/lib/../..
+
+ my $root = dir ($INC{$rel_path});
+ for (1 .. @mod_parts + 2) {
+ $root = $root->parent;
+ }
+
+ return (-f $root->file ('Makefile.PL') )
+ ? $root
+ : undef
+ ;
+}
+
+1;
Oops, something went wrong.

0 comments on commit 2d4b00e

Please sign in to comment.