diff --git a/Changes b/Changes index 4bffd2b..de518b9 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,11 @@ Revision history for Perl extension Test::Spec. -0.38 Wed Aug 31 00:52:00 EST 2011 +0.40 Mon Jan 30 18:38:00 EST 2012 + - Fixed problem that caused Test::Spec usage errors (e.g. 'describe "foo";' + without a subroutine argument) to be reported from inside the library, + instead of the caller's perspective where the actual error is. + +0.39 Wed Aug 31 00:52:00 EST 2011 - Added xit/xthey/xdescribe to mark TODO tests, inspired by the Jasmine JavaScript framework. Contributed by Marian Schubert (issue #10). diff --git a/MANIFEST b/MANIFEST index 628812c..f12d58e 100644 --- a/MANIFEST +++ b/MANIFEST @@ -26,3 +26,4 @@ t/show_exceptions.t t/spec_helper.t t/strict_violating_spec.pl t/test_helper.pl +t/uncompilable_spec.pl diff --git a/lib/Test/Spec.pm b/lib/Test/Spec.pm index cb66af8..b516251 100644 --- a/lib/Test/Spec.pm +++ b/lib/Test/Spec.pm @@ -3,7 +3,7 @@ use strict; use warnings; use Test::Trap (); # load as early as possible to override CORE::exit -our $VERSION = '0.39'; +our $VERSION = '0.40'; use base qw(Exporter); @@ -68,7 +68,12 @@ sub import { return; } - eval "package $callpkg; use base 'Test::Spec';"; + eval qq{ + package $callpkg; + use base 'Test::Spec'; + # allow Test::Spec usage errors to be reported via Carp + our \@CARP_NOT = qw($callpkg); + }; die $@ if $@; Test::Spec::ExportProxy->export_to_level(1, $callpkg); $class->export_to_level(1, $callpkg); diff --git a/t/show_exceptions.t b/t/show_exceptions.t index a231980..0a2f65b 100755 --- a/t/show_exceptions.t +++ b/t/show_exceptions.t @@ -25,6 +25,11 @@ describe "Test::Spec" => sub { it "should continue running tests after an exception is encountered" => sub { like($tap, qr/^ok \d+ - Test::Spec should continue testing/m); }; + + it "should report usage errors from the location of the error" => sub { + my ($utap) = split /[\r\n]+/, capture_tap("uncompilable_spec.pl"); + like($utap, qr/at .*uncompilable_spec.pl line \d+/); + }; }; runtests unless caller; diff --git a/t/uncompilable_spec.pl b/t/uncompilable_spec.pl new file mode 100755 index 0000000..f12da48 --- /dev/null +++ b/t/uncompilable_spec.pl @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +# +# uncompilable_spec.pl +# +# Expected to fail and report Test::Spec usage error from the correct stack +# frame (i.e. "at uncompilable_spec.pl line 13"). +# +######################################################################## +# + +use Test::Spec; + +describe "Test::Spec"; + +runtests unless caller;