Hello community, here is the log from the commit of package perl-Test-Spec for openSUSE:Factory checked in at 2013-06-06 13:56:24 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/perl-Test-Spec (Old) and /work/SRC/openSUSE:Factory/.perl-Test-Spec.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-Test-Spec" Changes: -------- --- /work/SRC/openSUSE:Factory/perl-Test-Spec/perl-Test-Spec.changes 2012-03-12 08:54:02.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.perl-Test-Spec.new/perl-Test-Spec.changes 2013-06-06 13:56:26.000000000 +0200 @@ -1,0 +2,16 @@ +Tue Jun 4 15:08:18 UTC 2013 - [email protected] + +- updated to 0.46 + - with() enables argument matching on mocked methods + - raises() makes mocked methods raise exceptions + Contributed by Kjell-Magne Øierud (issue #12) + + - Add support for TAP version 13. + Contributed by Michael G. Schwern (issue #11) + + - Allow shared_examples_for to be defined in any context. + + - Fixed runtests() to honor its contract to run only the examples specified + in its @patterns parameter or SPEC environment variable. + +------------------------------------------------------------------- Old: ---- Test-Spec-0.42.tar.gz New: ---- Test-Spec-0.46.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-Test-Spec.spec ++++++ --- /var/tmp/diff_new_pack.FJN6Ct/_old 2013-06-06 13:56:27.000000000 +0200 +++ /var/tmp/diff_new_pack.FJN6Ct/_new 2013-06-06 13:56:27.000000000 +0200 @@ -1,7 +1,7 @@ # # spec file for package perl-Test-Spec # -# Copyright (c) 2012 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,7 +17,7 @@ Name: perl-Test-Spec -Version: 0.42 +Version: 0.46 Release: 0 %define cpan_name Test-Spec Summary: Write tests in a declarative specification style @@ -66,10 +66,8 @@ %{__perl} Makefile.PL INSTALLDIRS=vendor %{__make} %{?_smp_mflags} -%if 0%{?suse_version} == 0 || 0%{?suse_version} > 1120 %check %{__make} test -%endif %install %perl_make_install ++++++ Test-Spec-0.42.tar.gz -> Test-Spec-0.46.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Test-Spec-0.42/Changes new/Test-Spec-0.46/Changes --- old/Test-Spec-0.42/Changes 2012-03-06 04:21:04.000000000 +0100 +++ new/Test-Spec-0.46/Changes 2012-10-02 19:26:36.000000000 +0200 @@ -1,5 +1,21 @@ Revision history for Perl extension Test::Spec. +0.46 Tue Oct 2 13:23:00 EDT 2012 + - with() enables argument matching on mocked methods + - raises() makes mocked methods raise exceptions + Contributed by Kjell-Magne Øierud (issue #12) + +0.45 Mon May 7 10:08:13 EDT 2012 + - Add support for TAP version 13. + Contributed by Michael G. Schwern (issue #11) + +0.44 Mon Apr 30 11:04:00 CST 2012 + - Allow shared_examples_for to be defined in any context. + +0.43 Sat Apr 14 16:22:00 EST 2012 + - Fixed runtests() to honor its contract to run only the examples specified + in its @patterns parameter or SPEC environment variable. + 0.42 Mon Mar 05 21:18:00 CST 2012 - Added context() and xcontext() aliases for describe/xdescribe (reported by intrigeri) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Test-Spec-0.42/MANIFEST new/Test-Spec-0.46/MANIFEST --- old/Test-Spec-0.42/MANIFEST 2012-03-06 04:21:16.000000000 +0100 +++ new/Test-Spec-0.46/MANIFEST 2012-10-02 19:29:05.000000000 +0200 @@ -20,11 +20,13 @@ t/mocks.t t/mocks_imports.t t/perl_warning_spec.pl +t/runtests_subset.t t/shared_examples.t t/shared_examples_spec.pl t/show_exceptions.t t/spec_helper.t t/strict_violating_spec.pl +t/subset_spec.pl t/test_helper.pl t/uncompilable_spec.pl META.yml Module meta-data (added by MakeMaker) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Test-Spec-0.42/META.yml new/Test-Spec-0.46/META.yml --- old/Test-Spec-0.42/META.yml 2012-03-06 04:21:16.000000000 +0100 +++ new/Test-Spec-0.46/META.yml 2012-10-02 19:29:05.000000000 +0200 @@ -1,6 +1,6 @@ --- #YAML:1.0 name: Test-Spec -version: 0.42 +version: 0.46 abstract: Write tests in a declarative specification style author: - Philip Garrett <[email protected]> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Test-Spec-0.42/lib/Test/Spec/Mocks.pm new/Test-Spec-0.46/lib/Test/Spec/Mocks.pm --- old/Test-Spec-0.42/lib/Test/Spec/Mocks.pm 2012-01-31 00:36:05.000000000 +0100 +++ new/Test-Spec-0.46/lib/Test/Spec/Mocks.pm 2012-10-02 19:26:31.000000000 +0200 @@ -224,6 +224,8 @@ sub _called { my $self = shift; + my @args = @_; + $self->_given_args(\@args); $self->{__call_count} = $self->_call_count + 1; } @@ -258,6 +260,75 @@ } # + # ARGUMENT MATCHING + # + + sub with { + my $self = shift; + $self->_args(\@_); + return $self; + } + + sub _args { + my $self = shift; + $self->{__args} = shift if @_; + return $self->{__args} ||= undef; + } + + sub _given_args { + my $self = shift; + $self->{__given_args} = shift if @_; + return $self->{__given_args} ||= undef; + } + + sub _check_arguments { + my $self = shift; + return unless defined $self->_args; + + if (!defined $self->_given_args || scalar(@{$self->_args}) != scalar(@{$self->_given_args})) { + return "Number of arguments don't match expectation"; + } + my @problems = (); + for my $i (0..$#{$self->_args}) { + my $a = $self->_args->[$i]; + my $b = $self->_given_args->[$i]; + unless ($self->_match_arguments($a, $b)) { + $a = 'undef' unless defined $a; + $b = 'undef' unless defined $b; + push @problems, sprintf("Expected argument in position %d to be '%s', but it was '%s'", $i, $a, $b); + } + } + return @problems; + } + + sub _match_arguments { + my $self = shift; + my ($a, $b) = @_; + return 1 if !defined $a && !defined $b; + return unless defined $a && defined $b; + return $a eq $b; + } + + # + # EXCEPTIONS + # + + sub raises { + my $self = shift; + my ($message) = @_; + $self->_exception($message); + return $self; + } + + sub _exception { + my $self = shift; + $self->{__exception} = shift if @_; + return $self->{__exception} ||= undef; + } + + + + # # CALL COUNT CHECKS # @@ -374,6 +445,9 @@ $self->_method, $message, $self->_call_count, ); } + for my $message ($self->_check_arguments()) { + push @prob, $message; + } return @prob; } @@ -445,10 +519,15 @@ $self->_original_code($original_method); $self->_install($dest => sub { - if ($_[0] == $target) { + # Use refaddr() to prevent an overridden equality operator from + # making two objects appear equal when they are only equivalent. + if (Scalar::Util::refaddr($_[0]) == Scalar::Util::refaddr($target)) { # do extreme late binding here, so calls to returns() after the # mock has already been installed will take effect. - $self->_called(); + my @args = @_; + shift @args; + $self->_called(@args); + die $self->_exception if $self->_exception; return $self->_retval->(@_); } elsif (!$original_method) { @@ -476,7 +555,10 @@ $self->_install($dest => sub { # do extreme late binding here, so calls to returns() after the # mock has already been installed will take effect. - $self->_called(); + my @args = @_; + shift @args; + $self->_called(@args); + die $self->_exception if $self->_exception; $self->_retval->(@_); }); } @@ -886,6 +968,18 @@ I<This method is alpha and will probably change in a future release.> +=item with(@arguments) + +Configures the mocked method so that it must be called with arguments as +specified. The arguments will be compared using the "eq" operator, so it works +for most scalar values with no problem. If you want to check objects here, +they must be the exact same instance or you must overload the "eq" operator to +provide the behavior you desire. + +=item raises($exception) + +Configures the mocked method so that it raises C<$exception> when called. + =back =head1 OTHER EXPECTATION METHODS diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Test-Spec-0.42/lib/Test/Spec.pm new/Test-Spec-0.46/lib/Test/Spec.pm --- old/Test-Spec-0.42/lib/Test/Spec.pm 2012-03-06 04:21:04.000000000 +0100 +++ new/Test-Spec-0.46/lib/Test/Spec.pm 2012-10-02 19:26:36.000000000 +0200 @@ -3,7 +3,7 @@ use warnings; use Test::Trap (); # load as early as possible to override CORE::exit -our $VERSION = '0.42'; +our $VERSION = '0.46'; use base qw(Exporter); @@ -131,7 +131,7 @@ my @which = @_ ? @_ : $ENV{SPEC} ? ($ENV{SPEC}) : (); - return $class->_execute_tests( $class->_pick_tests(@_) ); + return $class->_execute_tests( $class->_pick_tests(@which) ); } sub builder { @@ -143,9 +143,7 @@ my ($class,@matchers) = @_; my @tests = $class->tests; for my $pattern (@matchers) { - # ignore case unless uppercase is present, i.e. "smartcase" - my $expr = ($pattern =~ /[[:upper:]]/) ? qr/$pattern/ : qr/$pattern/i; - @tests = grep { $_ =~ $expr } @tests; + @tests = grep { $_ =~ /$pattern/i } @tests; } return @tests; } @@ -246,10 +244,6 @@ 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({ container => $_Shared_Example_Groups, name => $name, @@ -553,9 +547,10 @@ =item runtests(@patterns) -Runs all the examples whose descriptions match one of the regular expressions -in C<@patterns>. If C<@patterns> is not provided, runs I<all> examples. The -environment variable "SPEC" will be used as a default pattern if present. +Runs all the examples whose descriptions match one of the (non case-sensitive) +regular expressions in C<@patterns>. If C<@patterns> is not provided, +runs I<all> examples. The environment variable "SPEC" will be used as a +default pattern if present. If called as a function (i.e. I<not> a method call with "->"), C<runtests> will autodetect the package from which it is called and run that @@ -740,7 +735,9 @@ C<describe> blocks or other C<shared_examples_for> blocks. See L</Shared example groups>. -Example group names are B<global>. +Example group names are B<global>, but example groups can be defined at any +level (i.e. they can be defined in the global context, or inside a "describe" +block). my $browser; shared_examples_for "all browsers" => sub { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Test-Spec-0.42/t/mocks.t new/Test-Spec-0.46/t/mocks.t --- old/Test-Spec-0.42/t/mocks.t 2012-01-18 23:35:08.000000000 +0100 +++ new/Test-Spec-0.46/t/mocks.t 2012-10-02 19:26:31.000000000 +0200 @@ -36,6 +36,7 @@ { package TestProduct; our @ISA = qw(TestORM); + use overload eq => sub { 1 }; # stub for with() test sub prices { 'ORIGINAL' } sub desc { # normally "bottom middle top" @@ -252,6 +253,97 @@ }; + describe "raising exceptions" => sub { + it "raises the exception" => sub { + my $stub = stub(); + my $expectation = $stub->expects('run'); + $expectation->cancel; # don't verify + $expectation->raises("Foo\n"); + eval { + $stub->run; + }; + if ($@ eq "Foo\n") { + pass("As expected"); + } + else { + fail("Told the mock to raise an exception, but it didn't happen"); + } + }; + }; + + describe "argument matching" => sub { + my ($stub, $expectation); + + before each => sub { + $stub = stub(); + $expectation = $stub->expects('run'); + $expectation->cancel; # don't verify + }; + + it "passes when expecting no arguments" => sub { + $expectation->with(); + $stub->run(); + is(scalar($expectation->problems), 0); + }; + + it "fails when expecting no arguments and one argument given" => sub { + $expectation->with(); + $stub->run(1); + contains_ok([$expectation->problems], qr/^Number of arguments don't match expectation$/); + }; + + it "passes when expecting one String('Foo') argument" => sub { + $expectation->with("Foo"); + $stub->run("Foo"); + is(scalar($expectation->problems), 0); + }; + + it "fails when expecting one String('Foo') argument but given none" => sub { + $expectation->with("Foo"); + $stub->run(); + contains_ok([$expectation->problems], qr/^Number of arguments don't match expectation$/); + }; + + it "fails when expecting one String('Foo') argument but given two" => sub { + $expectation->with("Foo"); + $stub->run("Foo", "Bar"); + contains_ok([$expectation->problems], qr/^Number of arguments don't match expectation$/); + }; + + it "fails when expecting one String('Foo') argument but given a different String" => sub { + $expectation->with("Foo"); + $stub->run("Bar"); + contains_ok([$expectation->problems], qr/^Expected argument in position 0 to be 'Foo', but it was 'Bar'$/); + }; + + it "passes when expecting an object argument that was given" => sub { + my $obj = TestOO->new; + $expectation->with($obj); + $stub->run($obj); + is(scalar($expectation->problems), 0); + }; + + it "fails when expecting an object argument but given none" => sub { + my $obj = TestOO->new; + $expectation->with($obj); + $stub->run(); + contains_ok([$expectation->problems], qr/^Number of arguments don't match expectation$/); + }; + + it "fails when expecting an object argument but given a different one" => sub { + $expectation->with(TestOO->new); + $stub->run(TestOO->new); + contains_ok([$expectation->problems], qr/^Expected argument in position 0 to be 'TestOO=HASH.+ but it was 'TestOO=HASH/); + }; + + it "passes when expecting an object argument and given a different one that compares with eq operator" => sub { + $expectation->with(TestProduct->new); + $stub->run(TestProduct->new); + is(scalar($expectation->problems), 0); + }; + + }; + describe "call count expectation" => sub { my $stub = stub(); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Test-Spec-0.42/t/runtests_subset.t new/Test-Spec-0.46/t/runtests_subset.t --- old/Test-Spec-0.42/t/runtests_subset.t 1970-01-01 01:00:00.000000000 +0100 +++ new/Test-Spec-0.46/t/runtests_subset.t 2012-05-07 16:14:31.000000000 +0200 @@ -0,0 +1,71 @@ +#!/usr/bin/env perl +# +# runtests_subset.t +# +######################################################################## +# + +package Testcase::Spec::RuntestsSubset; +use Test::Spec; +use FindBin qw($Bin); +BEGIN { require "$Bin/test_helper.pl" }; + +describe "Test::Spec" => sub { + + describe "when no specific examples are requested" => sub { + my $tap; + before all => sub { + $tap = capture_tap("subset_spec.pl"); + }; + it "should run all the examples" => sub { + like $tap, qr/^ok \d+ - Test One.*ok \d+ - Test Two/ms; + }; + }; + + describe "when specific examples are requested explicitly" => sub { + my $tap; + before all => sub { + # case insensitivity is baked in + $tap = capture_tap("subset_spec.pl", "oNe"); + }; + it "should run the requested examples" => sub { + like $tap, qr/^ok \d+ - Test One/m; + }; + it "should run ONLY the requested examples" => sub { + unlike $tap, qr/^ok \d+ - Test Two/; + }; + }; + + describe "when specific examples are requested via SPEC environment var" => sub { + my $tap; + before all => sub { + # case insensitivity is baked in + local $ENV{SPEC} = "oNe"; + $tap = capture_tap("subset_spec.pl"); + }; + it "should run the requested examples" => sub { + like $tap, qr/^ok \d+ - Test One/m; + }; + it "should run ONLY the requested examples" => sub { + unlike $tap, qr/^ok \d+ - Test Two/; + }; + }; + + describe "when examples are requested via both SPEC and explicit parameter" => sub { + my $tap; + before all => sub { + # case insensitivity is baked in + local $ENV{SPEC} = "oNe"; + $tap = capture_tap("subset_spec.pl","tWo"); + }; + it "should run the explicit example" => sub { + like $tap, qr/^ok \d+ - Test Two/m; + }; + it "should *not* run the SPEC example" => sub { + unlike $tap, qr/^ok \d+ - Test One/; + }; + }; + +}; + +runtests unless caller; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Test-Spec-0.42/t/shared_examples.t new/Test-Spec-0.46/t/shared_examples.t --- old/Test-Spec-0.42/t/shared_examples.t 2011-07-07 19:56:53.000000000 +0200 +++ new/Test-Spec-0.46/t/shared_examples.t 2012-04-30 18:07:11.000000000 +0200 @@ -29,6 +29,7 @@ test_passed("A context importing an example group with an inner block nests properly"); test_passed("A context importing an example group can have custom behavior"); test_passed("A context importing an example group can be reopened"); +test_passed("A context importing an example group executes"); test_passed("Another context importing an example group can take at least one example"); test_passed("Another context importing an example group can take more than one example"); test_passed("Another context importing an example group with an inner block nests properly"); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Test-Spec-0.42/t/shared_examples_spec.pl new/Test-Spec-0.46/t/shared_examples_spec.pl --- old/Test-Spec-0.42/t/shared_examples_spec.pl 2012-03-04 01:06:07.000000000 +0100 +++ new/Test-Spec-0.46/t/shared_examples_spec.pl 2012-04-30 18:07:11.000000000 +0200 @@ -20,8 +20,16 @@ }; }; +describe "A context" => sub { + # can define an example group. + shared_examples_for "example group defined in context" => sub { + it "executes"; + }; +}; + describe "A context importing an example group" => sub { it_should_behave_like "example group"; + it_should_behave_like "example group defined in context"; it "can have custom behavior"; }; @@ -48,5 +56,6 @@ # A context importing an example group can take more than one example # A context importing an example group can be reopened # A context importing an example group with an inner block nests properly +# A context importing an example group executes runtests unless caller; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Test-Spec-0.42/t/subset_spec.pl new/Test-Spec-0.46/t/subset_spec.pl --- old/Test-Spec-0.42/t/subset_spec.pl 1970-01-01 01:00:00.000000000 +0100 +++ new/Test-Spec-0.46/t/subset_spec.pl 2012-04-14 22:23:58.000000000 +0200 @@ -0,0 +1,19 @@ +#!/usr/bin/env perl +# +# subset_spec.pl +# +# Helper for testing arguments to runtests(@patterns). +# +######################################################################## +# + +use Test::Spec; +use FindBin qw($Bin); +BEGIN { require "$Bin/test_helper.pl" }; + +describe "Test" => sub { + it "One" => sub { pass }; + it "Two" => sub { pass }; +}; + +runtests(@ARGV) unless caller; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Test-Spec-0.42/t/test_helper.pl new/Test-Spec-0.46/t/test_helper.pl --- old/Test-Spec-0.42/t/test_helper.pl 2012-03-04 01:06:07.000000000 +0100 +++ new/Test-Spec-0.46/t/test_helper.pl 2012-04-14 22:23:58.000000000 +0200 @@ -32,7 +32,7 @@ } sub capture_tap { - my ($spec_name) = @_; + my ($spec_name,@args) = @_; require File::Spec; require File::Temp; @@ -44,7 +44,7 @@ open(STDOUT, ">", $filename) || die "can't open '$filename' for out: $!"; open(STDERR, ">&STDOUT") || die "can't reopen stderr on stdout: $!"; - system($^X, (map { "-I$_" } @INC), File::Spec->catfile($Bin, $spec_name)); + system($^X, (map { "-I$_" } @INC), File::Spec->catfile($Bin, $spec_name), @args); open(STDERR, ">&", $olderr) || do { print {$olderr} "can't reopen stderr: $! " . "at " . __FILE__ . " line " . __LINE__ . "\n"; @@ -59,8 +59,8 @@ sub parse_tap { require TAP::Parser; - my ($spec_name) = @_; - my $tap = capture_tap($spec_name); + my ($spec_name,@args) = @_; + my $tap = capture_tap($spec_name,@args); my $parser = TAP::Parser->new({ tap => $tap }); my @results; while (my $result = $parser->next) { -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
