Change 27356 by [EMAIL PROTECTED] on 2006/03/01 16:29:37
Upgrade to assertions-0.03
Affected files ...
... //depot/perl/lib/assertions.pm#8 edit
... //depot/perl/lib/assertions/activate.pm#8 edit
... //depot/perl/lib/assertions/compat.pm#2 edit
... //depot/perl/t/comp/assertions.t#4 edit
... //depot/perl/t/comp/asstcompat.t#2 edit
Differences ...
==== //depot/perl/lib/assertions.pm#8 (text) ====
Index: perl/lib/assertions.pm
--- perl/lib/assertions.pm#7~24832~ 2005-06-14 01:52:46.000000000 -0700
+++ perl/lib/assertions.pm 2006-03-01 08:29:37.000000000 -0800
@@ -1,6 +1,6 @@
package assertions;
-our $VERSION = '0.02';
+our $VERSION = '0.03';
# use strict;
# use warnings;
@@ -184,6 +184,10 @@
=head1 DESCRIPTION
+ *** WARNING: assertion support is only available from perl version
+ *** 5.9.0 and upwards. Check assertions::compat (also available from
+ *** this package) for an alternative backwards compatible module.
+
The C<assertions> pragma specifies the tags used to enable and disable
the execution of assertion subroutines.
==== //depot/perl/lib/assertions/activate.pm#8 (text) ====
Index: perl/lib/assertions/activate.pm
--- perl/lib/assertions/activate.pm#7~24832~ 2005-06-14 01:52:46.000000000
-0700
+++ perl/lib/assertions/activate.pm 2006-03-01 08:29:37.000000000 -0800
@@ -27,7 +27,7 @@
This module is used internally by perl (and its C<-A> command-line switch) to
enable and disable assertions.
-It can also be used directly:
+Though it can also be explicetly used:
use assertions::activate qw(foo bar);
==== //depot/perl/lib/assertions/compat.pm#2 (text) ====
Index: perl/lib/assertions/compat.pm
--- perl/lib/assertions/compat.pm#1~24832~ 2005-06-14 01:52:46.000000000
-0700
+++ perl/lib/assertions/compat.pm 2006-03-01 08:29:37.000000000 -0800
@@ -1,5 +1,7 @@
package assertions::compat;
+our $VERSION = '0.02';
+
require assertions;
our @ISA = qw(assertions);
@@ -40,6 +42,18 @@
? \&_do_nothing_handler
: \&_compat_assertion_handler;
+*supported =
+ defined($assertion_ok)
+ ? \&_on
+ : \&_off;
+
+unless (defined $assertion_ok) {
+ package assertions;
+ require warnings::register;
+ warnings::register->import;
+}
+
+
1;
__END__
@@ -69,7 +83,7 @@
C<assertions::compat> allows to use assertions on perl versions prior
to 5.9.0 (that is the first one to natively support them). Though,
-it's not magic, do not expect it to allow for conditional executed
+it's not magic, do not expect it to allow for conditionally executed
subroutines.
This module provides support for two different functionalities:
@@ -89,11 +103,17 @@
declared as assertions will be B<unconditionally> called on perl without
native support for them.
+This module also provides the C<supported> function to check if
+assertions are supported or not:
+
+ my $supported = assertions::compat::supported();
+
+
=head2 Assertion execution status as a constant
-C<assertions::compat> also allows to create constant subs which value
+C<assertions::compat> also allows to create constant subs whose value
is the assertion execution status. That allows checking explicitly and
-efficiently if assertions have to be executed on perls without native
+efficiently when assertions have to be executed on perls without native
assertion support.
For instance...
@@ -123,7 +143,7 @@
the C<and> statement at compile time.
-When no assertion selection tags are passed to C<use
+If no assertion selection tags are passed to C<use
assertions::compat>, the current module name is used as the selection
tag, so...
@@ -146,8 +166,8 @@
ASST and assert_bar();
Finally, be aware that while assertion execution status is lexical
-scoped, defined constants are not. You should be careful on that to
-not write inconsistent code. For instance...
+scoped, the defined constants are not. You should be careful on that
+to not write inconsistent code. For instance...
package Foo;
==== //depot/perl/t/comp/assertions.t#4 (text) ====
Index: perl/t/comp/assertions.t
--- perl/t/comp/assertions.t#3~24832~ 2005-06-14 01:52:46.000000000 -0700
+++ perl/t/comp/assertions.t 2006-03-01 08:29:37.000000000 -0800
@@ -1,5 +1,9 @@
#!./perl
+BEGIN { $^W=0 }
+
+use base 'assertions::compat';
+
sub callme ($ ) : assertion {
return shift;
}
@@ -35,7 +39,9 @@
' ( 1 && 0 ) ' => 0,
'(( 1 && 1) && ( 1 || 0)) || _ && one && ( one || three)' => 1 );
-my [EMAIL PROTECTED]/2+10;
+my $supported = assertions::compat::supported();
+
+my [EMAIL PROTECTED]/2 + ($supported ? 10 : 0);
my $i=1;
print "1..$n\n";
@@ -63,100 +69,103 @@
print "ok ", $i++, "\n";
}
+if ($supported) {
-# @expr/2+1
-if (callme(1)) {
- print STDERR "assertions called by default\n";
- print "not ";
-}
-print "ok ", $i++, "\n";
-
-# 2
-use assertions::activate 'mine';
-{
- package mine;
- sub callme ($) : assertion {
- return shift;
- }
- use assertions;
- unless (callme(1)) {
- print STDERR "'use assertions;' doesn't active assertions based on package
name\n";
- print "not ";
- }
-}
-print "ok ", $i++, "\n";
-
-# 3
-use assertions 'foo';
-if (callme(1)) {
- print STDERR "assertion deselection doesn't work\n";
- print "not ";
-}
-print "ok ", $i++, "\n";
-
-# 4
-use assertions::activate 'bar', 'doz';
-use assertions 'bar';
-unless (callme(1)) {
- print STDERR "assertion selection doesn't work\n";
- print "not ";
-}
-print "ok ", $i++, "\n";
-
-# 5
-use assertions q(_ && doz);
-unless (callme(1)) {
- print STDERR "assertion activation filtering doesn't work\n";
- print "not ";
-}
-print "ok ", $i++, "\n";
-
-# 6
-use assertions q(_ && foo);
-if (callme(1)) {
- print STDERR "assertion deactivation filtering doesn't work\n";
- print "not ";
-}
-print "ok ", $i++, "\n";
-
-# 7
-if (1) {
- use assertions 'bar';
-}
-if (callme(1)) {
- print STDERR "assertion scoping doesn't work\n";
- print "not ";
-}
-print "ok ", $i++, "\n";
-
-# 8
-use assertions::activate 're.*';
-use assertions 'reassert';
-unless (callme(1)) {
- print STDERR "assertion selection with re failed\n";
- print "not ";
-}
-print "ok ", $i++, "\n";
-
-# 9
-my $b=12;
-{
+ # @expr/2+1
+ if (callme(1)) {
+ print STDERR "assertions called by default\n";
+ print "not ";
+ }
+ print "ok ", $i++, "\n";
+
+ # 2
+ use assertions::activate 'mine';
+ {
+ package mine;
+ use base 'assertions::compat';
+ sub callme ($) : assertion {
+ return shift;
+ }
+ use assertions;
+ unless (callme(1)) {
+ print STDERR "'use assertions;' doesn't active assertions based on
package name\n";
+ print "not ";
+ }
+ }
+ print "ok ", $i++, "\n";
+
+ # 3
+ use assertions 'foo';
+ if (callme(1)) {
+ print STDERR "assertion deselection doesn't work\n";
+ print "not ";
+ }
+ print "ok ", $i++, "\n";
+
+ # 4
+ use assertions::activate 'bar', 'doz';
use assertions 'bar';
- callme(my $b=45);
- unless ($b == 45) {
- print STDERR "this shouldn't fail ever (b=$b)\n";
+ unless (callme(1)) {
+ print STDERR "assertion selection doesn't work\n";
print "not ";
}
-}
-print "ok ", $i++, "\n";
+ print "ok ", $i++, "\n";
+
+ # 5
+ use assertions q(_ && doz);
+ unless (callme(1)) {
+ print STDERR "assertion activation filtering doesn't work\n";
+ print "not ";
+ }
+ print "ok ", $i++, "\n";
+
+ # 6
+ use assertions q(_ && foo);
+ if (callme(1)) {
+ print STDERR "assertion deactivation filtering doesn't work\n";
+ print "not ";
+ }
+ print "ok ", $i++, "\n";
+
+ # 7
+ if (1) {
+ use assertions 'bar';
+ }
+ if (callme(1)) {
+ print STDERR "assertion scoping doesn't work\n";
+ print "not ";
+ }
+ print "ok ", $i++, "\n";
-# 10
-{
- no assertions;
- callme(my $b=46);
- if (defined $b) {
- print STDERR "lexical declaration in assertion arg ignored (b=$b\n";
+ # 8
+ use assertions::activate 're.*';
+ use assertions 'reassert';
+ unless (callme(1)) {
+ print STDERR "assertion selection with re failed\n";
print "not ";
}
+ print "ok ", $i++, "\n";
+
+ # 9
+ my $b=12;
+ {
+ use assertions 'bar';
+ callme(my $b=45);
+ unless ($b == 45) {
+ print STDERR "this shouldn't fail ever (b=$b)\n";
+ print "not ";
+ }
+ }
+ print "ok ", $i++, "\n";
+
+ # 10
+ {
+ no assertions;
+ callme(my $b=46);
+ if (defined $b) {
+ print STDERR "lexical declaration in assertion arg ignored (b=$b\n";
+ print "not ";
+ }
+ }
+ print "ok ", $i++, "\n";
}
-print "ok ", $i++, "\n";
==== //depot/perl/t/comp/asstcompat.t#2 (text) ====
Index: perl/t/comp/asstcompat.t
--- perl/t/comp/asstcompat.t#1~24832~ 2005-06-14 01:52:46.000000000 -0700
+++ perl/t/comp/asstcompat.t 2006-03-01 08:29:37.000000000 -0800
@@ -1,5 +1,7 @@
#!./perl
+BEGIN { $^W = 0 }
+
my $i = 1;
sub ok {
my $ok = shift;
End of Patch.