r76664 - in /trunk/libtest-spec-perl: MANIFEST META.yml debian/changelog lib/Test/Spec.pm t/helper_test.pl t/spec_helper.t

carnil at users.alioth.debian.org carnil at users.alioth.debian.org
Tue Jun 28 09:32:53 UTC 2011


Author: carnil
Date: Tue Jun 28 09:32:51 2011
New Revision: 76664

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=76664
Log:
* Team upload.
* New upstream release

Added:
    trunk/libtest-spec-perl/t/helper_test.pl
      - copied unchanged from r76663, branches/upstream/libtest-spec-perl/current/t/helper_test.pl
    trunk/libtest-spec-perl/t/spec_helper.t
      - copied unchanged from r76663, branches/upstream/libtest-spec-perl/current/t/spec_helper.t
Modified:
    trunk/libtest-spec-perl/MANIFEST
    trunk/libtest-spec-perl/META.yml
    trunk/libtest-spec-perl/debian/changelog
    trunk/libtest-spec-perl/lib/Test/Spec.pm

Modified: trunk/libtest-spec-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtest-spec-perl/MANIFEST?rev=76664&op=diff
==============================================================================
--- trunk/libtest-spec-perl/MANIFEST (original)
+++ trunk/libtest-spec-perl/MANIFEST Tue Jun 28 09:32:51 2011
@@ -9,6 +9,7 @@
 t/define.t
 t/dying_spec.pl
 t/empty.t
+t/helper_test.pl
 t/import_strict.t
 t/import_warnings.t
 t/mocks.t
@@ -17,6 +18,7 @@
 t/shared_examples.t
 t/shared_examples_spec.pl
 t/show_exeptions.t
+t/spec_helper.t
 t/strict_violating_spec.pl
 t/test_helper.pl
 META.yml                                 Module meta-data (added by MakeMaker)

Modified: trunk/libtest-spec-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtest-spec-perl/META.yml?rev=76664&op=diff
==============================================================================
--- trunk/libtest-spec-perl/META.yml (original)
+++ trunk/libtest-spec-perl/META.yml Tue Jun 28 09:32:51 2011
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:               Test-Spec
-version:            0.33
+version:            0.34
 abstract:           Write tests in a declarative specification style
 author:
     - Philip Garrett <philip.garrett at icainformatics.com>

Modified: trunk/libtest-spec-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtest-spec-perl/debian/changelog?rev=76664&op=diff
==============================================================================
--- trunk/libtest-spec-perl/debian/changelog (original)
+++ trunk/libtest-spec-perl/debian/changelog Tue Jun 28 09:32:51 2011
@@ -1,3 +1,10 @@
+libtest-spec-perl (0.34-1) UNRELEASED; urgency=low
+
+  * Team upload.
+  * New upstream release
+
+ -- Salvatore Bonaccorso <carnil at debian.org>  Tue, 28 Jun 2011 11:32:29 +0200
+
 libtest-spec-perl (0.33-1) unstable; urgency=low
 
   * New upstream release

Modified: trunk/libtest-spec-perl/lib/Test/Spec.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtest-spec-perl/lib/Test/Spec.pm?rev=76664&op=diff
==============================================================================
--- trunk/libtest-spec-perl/lib/Test/Spec.pm (original)
+++ trunk/libtest-spec-perl/lib/Test/Spec.pm Tue Jun 28 09:32:51 2011
@@ -3,12 +3,13 @@
 use warnings;
 use Test::Trap ();        # load as early as possible to override CORE::exit
 
-our $VERSION = '0.33';
+our $VERSION = '0.34';
 
 use base qw(Exporter);
 
 use Carp ();
 use Exporter ();
+use File::Spec ();
 use Tie::IxHash ();
 
 use constant { DEFINITION_PHASE => 0, EXECUTION_PHASE => 1 };
@@ -17,7 +18,8 @@
 our $Debug = $ENV{TEST_SPEC_DEBUG} || 0;
 
 our @EXPORT      = qw(runtests describe before after it they *TODO
-                      shared_examples_for it_should_behave_like);
+                      shared_examples_for it_should_behave_like
+                      spec_helper);
 our @EXPORT_OK   = ( @EXPORT, qw(DEFINITION_PHASE EXECUTION_PHASE $Debug) );
 our %EXPORT_TAGS = ( all => \@EXPORT_OK,
                      constants => [qw(DEFINITION_PHASE EXECUTION_PHASE)] );
@@ -305,6 +307,30 @@
   push @{ $context->after_blocks }, { type => $type, code => $code };
 }
 
+# spec_helper FILESPEC
+sub spec_helper ($) {
+  my $filespec = shift;
+  my ($callpkg,$callfile) = caller;
+  my $load_path;
+  if (File::Spec->file_name_is_absolute($filespec)) {
+    $load_path = $filespec;
+  }
+  else {
+    my ($callvol,$calldir,undef)  = File::Spec->splitpath($callfile);
+    my (undef,$filedir,$filename) = File::Spec->splitpath($filespec);
+    my $newdir = File::Spec->catdir($calldir,$filedir);
+    $load_path = File::Spec->catpath($callvol,$newdir,$filename);
+  }
+  my $sub = eval "package $callpkg;\n" . q[sub {
+    my ($file,$origpath) = @_;
+    if (not defined(do $file)) {
+      my $err = $! || $@;
+      die "could not load spec_helper '$origpath': $err";
+    }
+  }];
+  $sub->($load_path,$filespec);
+}
+
 sub _materialize_tests {
   my $class = shift;
   my $contexts = $_Package_Contexts->{$class};
@@ -662,6 +688,19 @@
 the current context. See L</Shared example groups> and
 L<shared_examples_for>.
 
+=item spec_helper FILESPEC
+
+Loads the Perl source in C<FILESPEC> into the current spec's package. If
+C<FILESPEC> is relative (no leading slash), it is treated as relative to
+the spec file (i.e. B<not> the currently running script). This lets you
+keep helper scripts near the specs they are used by without exercising
+your File::Spec skills in your specs.
+
+  # in foo/spec.t
+  spec_helper "helper.pl";          # loads foo/helper.pl
+  spec_helper "helpers/helper.pl";  # loads foo/helpers/helper.pl
+  spec_helper "/path/to/helper.pl"; # loads /path/to/helper.pl
+
 =back
 
 =head2 Shared example groups




More information about the Pkg-perl-cvs-commits mailing list