develooper Front page | perl.perl5.porters | Postings from March 2011

Re: [perl #87064] Semi-Semicolons test suite is broken since perl5.13.7

Thread Previous | Thread Next
From:
Zefram
Date:
March 29, 2011 04:16
Subject:
Re: [perl #87064] Semi-Semicolons test suite is broken since perl5.13.7
Message ID:
20110329111633.GA19184@lake.fysh.org
Father Chrysostomos via RT wrote:
>Test::More implements use_ok with a ???use??? statement inside a string
>eval, so that line is a bit like:

It occurred to me that not only does this now run into trouble with source
filters but it'll also, regardless of the recent source filter change,
run into trouble with anything that interacts with the compilation
context.  Any import method that sets up a lexically-scoped effect will
influence the lexical scope of the string eval, not the lexical scope
of the BEGIN{use_ok}.  Likewise, any source injection into the parsing
context, triggered from the import method, will affect the eval rather
than the main code.  Example:

$ perl -le 'use Test::More tests => 2; BEGIN { use_ok("strict", "vars"); } $z; ok 1;'
1..2
ok 1 - use strict;
ok 2

That ought to fail at compile time, like this:

$ perl -le 'use Test::More tests => 2; use strict "vars"; BEGIN { ok 1; } $z; ok 1;'
1..2
ok 1
Global symbol "$z" requires explicit package name at -e line 1.
Execution of -e aborted due to compilation errors.
# Looks like you planned 2 tests but ran 1.
# Looks like your test exited with 255 just after 1.

So I reckon use_ok is seriously broken, and the core change has just
made this brokenness show up in a new situation.  use_ok needs to do the
require and import itself, without any string eval.  The core of it is
something like:

	sub my_use($;@) {
		my $module = $_[0];
		(my $filename = $module.".pm") =~ s!::!/!g;
		require($filename);
		goto &{$module->can("import")};
	}

-zefram

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About