r75671 - in /trunk/libtest-spec-perl: Changes MANIFEST META.yml Makefile.PL README debian/changelog debian/control lib/Test/Spec.pm t/shared_examples.t t/shared_examples_spec.pl t/test_helper.pl

ghedo-guest at users.alioth.debian.org ghedo-guest at users.alioth.debian.org
Tue Jun 14 08:49:28 UTC 2011


Author: ghedo-guest
Date: Tue Jun 14 08:49:20 2011
New Revision: 75671

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=75671
Log:
* New upstream release
* Add libtap-parser-perl to Build-Depends-Indep

Added:
    trunk/libtest-spec-perl/t/shared_examples.t
      - copied unchanged from r75670, branches/upstream/libtest-spec-perl/current/t/shared_examples.t
    trunk/libtest-spec-perl/t/shared_examples_spec.pl
      - copied unchanged from r75670, branches/upstream/libtest-spec-perl/current/t/shared_examples_spec.pl
Modified:
    trunk/libtest-spec-perl/Changes
    trunk/libtest-spec-perl/MANIFEST
    trunk/libtest-spec-perl/META.yml
    trunk/libtest-spec-perl/Makefile.PL
    trunk/libtest-spec-perl/README
    trunk/libtest-spec-perl/debian/changelog
    trunk/libtest-spec-perl/debian/control
    trunk/libtest-spec-perl/lib/Test/Spec.pm
    trunk/libtest-spec-perl/t/test_helper.pl

Modified: trunk/libtest-spec-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtest-spec-perl/Changes?rev=75671&op=diff
==============================================================================
--- trunk/libtest-spec-perl/Changes (original)
+++ trunk/libtest-spec-perl/Changes Tue Jun 14 08:49:20 2011
@@ -1,4 +1,8 @@
 Revision history for Perl extension Test::Spec.
+
+0.33 Mon Jun 13 15:03:03 UTC 2011
+  - Added shared_examples_for/it_should_behave_like to allow
+    factorization of tests.
 
 0.32 Thu Jun  9 16:09:55 UTC 2011
   - Fixed a problem with the tests that occurred only when

Modified: trunk/libtest-spec-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtest-spec-perl/MANIFEST?rev=75671&op=diff
==============================================================================
--- trunk/libtest-spec-perl/MANIFEST (original)
+++ trunk/libtest-spec-perl/MANIFEST Tue Jun 14 08:49:20 2011
@@ -14,6 +14,8 @@
 t/mocks.t
 t/mocks_imports.t
 t/perl_warning_spec.pl
+t/shared_examples.t
+t/shared_examples_spec.pl
 t/show_exeptions.t
 t/strict_violating_spec.pl
 t/test_helper.pl

Modified: trunk/libtest-spec-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtest-spec-perl/META.yml?rev=75671&op=diff
==============================================================================
--- trunk/libtest-spec-perl/META.yml (original)
+++ trunk/libtest-spec-perl/META.yml Tue Jun 14 08:49:20 2011
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:               Test-Spec
-version:            0.32
+version:            0.33
 abstract:           Write tests in a declarative specification style
 author:
     - Philip Garrett <philip.garrett at icainformatics.com>
@@ -17,6 +17,7 @@
     List::Util:      0
     Package::Stash:  0.23
     Scalar::Util:    0
+    TAP::Parser:     0
     Test::Deep:      0.103
     Test::More:      0
     Test::Trap:      0
@@ -25,7 +26,7 @@
     directory:
         - t
         - inc
-generated_by:       ExtUtils::MakeMaker version 6.56
+generated_by:       ExtUtils::MakeMaker version 6.54
 meta-spec:
     url:      http://module-build.sourceforge.net/META-spec-v1.4.html
     version:  1.4

Modified: trunk/libtest-spec-perl/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtest-spec-perl/Makefile.PL?rev=75671&op=diff
==============================================================================
--- trunk/libtest-spec-perl/Makefile.PL (original)
+++ trunk/libtest-spec-perl/Makefile.PL Tue Jun 14 08:49:20 2011
@@ -11,6 +11,7 @@
       'List::Util'     => 0,
       'Package::Stash' => 0.23,
       'Scalar::Util'   => 0,
+      'TAP::Parser'    => 0,
       'Test::Deep'     => 0.103, # earlier versions clash with UNIVERSAL::isa
       'Test::More'     => 0,
       'Test::Trap'     => 0,

Modified: trunk/libtest-spec-perl/README
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtest-spec-perl/README?rev=75671&op=diff
==============================================================================
--- trunk/libtest-spec-perl/README (original)
+++ trunk/libtest-spec-perl/README Tue Jun 14 08:49:20 2011
@@ -30,6 +30,7 @@
  * List::Util
  * Package::Stash (>= 0.23)
  * Scalar::Util (XS version)
+ * TAP::Parser
  * Test::Deep (>= 0.103)
  * Test::More
  * Test::Trap

Modified: trunk/libtest-spec-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtest-spec-perl/debian/changelog?rev=75671&op=diff
==============================================================================
--- trunk/libtest-spec-perl/debian/changelog (original)
+++ trunk/libtest-spec-perl/debian/changelog Tue Jun 14 08:49:20 2011
@@ -1,3 +1,10 @@
+libtest-spec-perl (0.33-1) UNRELEASED; urgency=low
+
+  * New upstream release
+  * Add libtap-parser-perl to Build-Depends-Indep
+
+ -- Alessandro Ghedini <al3xbio at gmail.com>  Tue, 14 Jun 2011 10:44:10 +0200
+
 libtest-spec-perl (0.32-1) unstable; urgency=low
 
   * Initial Release. (Closes: #629642)

Modified: trunk/libtest-spec-perl/debian/control
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtest-spec-perl/debian/control?rev=75671&op=diff
==============================================================================
--- trunk/libtest-spec-perl/debian/control (original)
+++ trunk/libtest-spec-perl/debian/control Tue Jun 14 08:49:20 2011
@@ -4,6 +4,7 @@
 Build-Depends: debhelper (>= 8)
 Build-Depends-Indep: perl,
  libpackage-stash-perl (>= 0.23),
+ perl (>= 5.10.1) | libtap-parser-perl,
  libtest-deep-perl,
  libtest-trap-perl,
  libtie-ixhash-perl

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=75671&op=diff
==============================================================================
--- trunk/libtest-spec-perl/lib/Test/Spec.pm (original)
+++ trunk/libtest-spec-perl/lib/Test/Spec.pm Tue Jun 14 08:49:20 2011
@@ -3,7 +3,7 @@
 use warnings;
 use Test::Trap ();        # load as early as possible to override CORE::exit
 
-our $VERSION = '0.32';
+our $VERSION = '0.33';
 
 use base qw(Exporter);
 
@@ -16,7 +16,8 @@
 our $TODO;
 our $Debug = $ENV{TEST_SPEC_DEBUG} || 0;
 
-our @EXPORT      = qw(runtests describe before after it they *TODO);
+our @EXPORT      = qw(runtests describe before after it they *TODO
+                      shared_examples_for it_should_behave_like);
 our @EXPORT_OK   = ( @EXPORT, qw(DEFINITION_PHASE EXECUTION_PHASE $Debug) );
 our %EXPORT_TAGS = ( all => \@EXPORT_OK,
                      constants => [qw(DEFINITION_PHASE EXECUTION_PHASE)] );
@@ -25,6 +26,8 @@
 our $_Package_Contexts = _ixhash();
 our %_Package_Phase;
 our %_Package_Tests;
+
+our $_Shared_Example_Groups = {};
 
 # Avoid polluting the Spec namespace by loading these other modules into
 # what's essentially a mixin class.  When you write "use Test::Spec",
@@ -179,7 +182,7 @@
   }
   my $name = shift || $package;
 
-  my ($parent,$context);
+  my $parent;
   if ($_Current_Context) {
     $parent = $_Current_Context->context_lookup;
   }
@@ -187,14 +190,58 @@
     $parent = $_Package_Contexts->{$package} ||= _ixhash();
   }
 
+  __PACKAGE__->_accumulate_examples({
+    parent => $parent,
+    name => $name,
+    class => $package,
+    code => $code,
+    label => $name,
+  });
+}
+
+# shared_examples_for DESC => CODE
+sub shared_examples_for($&) {
+  my $package = caller;
+  my ($name,$code) = @_;
+  if (not defined($name)) {
+    Carp::croak "expected example group name as first argument";
+  }
+  if (ref($code) ne 'CODE') {
+    Carp::croak "expected subroutine reference as last argument";
+  }
+
+  if ($_Current_Context) {
+    Carp::croak "shared_examples_for cannot be used inside any other context";
+  }
+
+  __PACKAGE__->_accumulate_examples({
+    parent => $_Shared_Example_Groups,
+    name => $name,
+    class => $package,
+    code => $code,
+    label => '',
+  });
+}
+
+# used by both describe() and shared_examples_for() to build example
+# groups in context
+sub _accumulate_examples {
+  my ($klass,$args) = @_;
+  my $parent = $args->{parent};
+  my $name = $args->{name};
+  my $class = $args->{class};
+  my $code = $args->{code};
+  my $label = $args->{label};
+
+  my $context;
   # Don't clobber contexts of the same name, aggregate them.
   if ($parent->{$name}) {
     $context = $parent->{$name};
   }
   else {
     $context = Test::Spec::Context->new;
-    $context->name( $name );
-    $context->class( $package );
+    $context->name( $label );
+    $context->class( $class );
     $context->parent( $_Current_Context ); # might be undef
     $parent->{$name} = $context;
   }
@@ -205,6 +252,23 @@
   # evaluate the context function, which will set up lexical variables and
   # define tests and other contexts
   $context->contextualize(sub { $code->() }); 
+}
+
+# it_should_behave_like DESC
+sub it_should_behave_like($) {
+  my ($name) = @_;
+  if (not defined($name)) {
+    Carp::croak "expected example_group_name as first argument";
+  }
+  if (!$_Current_Context) {
+    Carp::croak "it_should_behave_like can only be used inside a describe or shared_examples_for context";
+  }
+  my $context = $_Shared_Example_Groups->{$name} ||
+    Carp::croak "unrecognized example group \"$name\"";
+
+  # add our shared_examples_for context as if it had been written inline
+  # as a describe() block
+  $_Current_Context->context_lookup->{"__shared_examples__:$name"} = $context;
 }
 
 # before CODE
@@ -568,7 +632,98 @@
 C<after "all"> blocks run I<after> C<after "each"> blocks.
 
 
+=item shared_examples_for DESCRIPTION => CODE
+
+Defines a group of examples that can later be included in
+C<describe> blocks or other C<shared_examples_for> blocks. See
+L</Shared Example Groups>.
+
+Example group names are B<global>.
+
+  shared_examples_for "all browsers" => sub {
+    it "should open a URL";
+    ...
+  };
+  describe "Firefox" => sub {
+    it_should_behave_like "all browsers";
+    it "should have firefox features";
+  };
+  describe "Safari" => sub {
+    it_should_behave_like "all browsers";
+    it "should have safari features";
+  };
+
+=item it_should_behave_like DESCRIPTION
+
+Asserts that the thing currently being tested passes all the tests in
+the example group identified by DESCRIPTION (having previously been
+defined with a C<shared_examples_for> block). In essence, this is like
+copying all the tests from the named C<shared_examples_for> block into
+the current context. See L</Shared example groups> and
+L<shared_examples_for>.
+
 =back
+
+=head2 Shared example groups
+
+This feature comes straight out of RSpec, as does this documentation:
+
+You can create shared example groups and include those groups into other
+groups.
+
+Suppose you have some behavior that applies to all editions of your
+product, both large and small.
+
+First, factor out the "shared" behavior:
+
+  shared_examples_for "all editions" => sub {
+    it "should behave like all editions" => sub {
+      ...
+    };
+  };
+
+then when you need to define the behavior for the Large and Small
+editions, reference the shared behavior using the
+C<it_should_behave_like()> function.
+
+  describe "SmallEdition" => sub {
+    it_should_behave_like "all editions";
+  };
+
+  describe "LargeEdition" => sub {
+    it_should_behave_like "all editions";
+    it "should also behave like a large edition" => sub {
+      ...
+    };
+  };
+
+C<it_should_behave_like> will search for an example group by its
+description string, in this case, "all editions".
+
+Shared example groups may be included in other shared groups:
+
+  shared_examples_for "All Employees" => sub {
+    it "should be payable" => sub {
+      ...
+    };
+  };
+
+  shared_examples_for "All Managers" => sub {
+    it_should_behave_like "All Employees";
+    it "should be bonusable" => sub {
+      ...
+    };
+  };
+
+  describe Officer => sub {
+    it_should_behave_like "All Managers";
+    it "should be optionable";
+  };
+
+  # generates:
+  ok 1 - Officer should be optionable
+  ok 2 - Officer should be bonusable
+  ok 3 - Officer should be payable
 
 =head2 Order of execution
 

Modified: trunk/libtest-spec-perl/t/test_helper.pl
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtest-spec-perl/t/test_helper.pl?rev=75671&op=diff
==============================================================================
--- trunk/libtest-spec-perl/t/test_helper.pl (original)
+++ trunk/libtest-spec-perl/t/test_helper.pl Tue Jun 14 08:49:20 2011
@@ -1,5 +1,4 @@
 use strict;
-use File::Spec;
 use FindBin qw($Bin);
 
 {
@@ -22,6 +21,7 @@
 }
 
 sub capture_tap {
+  require File::Spec;
   my ($spec_name) = @_;
   my @incflags = map { "-I$_" } @INC;
   open(my $SPEC, '-|') || do {
@@ -33,4 +33,16 @@
   return $tap;
 }
 
+sub parse_tap {
+  require TAP::Parser;
+  my ($spec_name) = @_;
+  my $tap = capture_tap($spec_name);
+  my $parser = TAP::Parser->new({ tap => $tap });
+  my @results;
+  while (my $result = $parser->next) {
+    push @results, $result;
+  }
+  return @results;
+}
+
 1;




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