http://www.perlmonks.org?node_id=1136626

1nickt has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

Before I file an issue report I seek to check my sanity here. I just got a Fail from CPAN testers for a recent update to a module that implemented Test::Exception.

------------------------------ PROGRAM OUTPUT ------------------------------ Output from 'C:\strawberry5143\c\bin\dmake.exe test': C:\strawberry5143\perl\bin\perl.exe "-MExtUtils::Command::MM" "-e" "te +st_harness(0, 'blib\lib', 'blib\arch')" t/*.t t/10_obj_and_params.t ............... ok t/20_valid_drupal.t ................. ok t/30_build_and_validate_test_db.t ... ok Bareword "xception" not allowed while "strict subs" in use at C:/straw +berry5143/perl/vendor/lib/Test/Exception.pm line 4. Compilation failed in require at t/40_fetch_memberships.t line 14. BEGIN failed--compilation aborted at t/40_fetch_memberships.t line 14. t/40_fetch_memberships.t ............ Dubious, test returned 255 (wstat 65280, 0xff00) Failed 1/1 subtests t/50_term_object_params.t ........... ok t/55_term_object_functions.t ........ ok t/60_membership_object_params.t ..... ok t/65_membership_object_functions.t .. ok t/70_stats_object_parameters.t ...... ok t/75_stats_functions.t .............. ok t/release-pod-coverage.t ............ skipped: these tests are for rel +ease candidate testing t/release-pod-syntax.t .............. skipped: these tests are for rel +ease candidate testing Test Summary Report ------------------- t/40_fetch_memberships.t (Wstat: 65280 Tests: 0 Failed: 0) Non-zero exit status: 255 Parse errors: Bad plan. You planned 1 tests but ran 0. Files=12, Tests=36, 7 wallclock secs ( 0.04 usr + 0.12 sys = 0.16 C +PU) Result: FAIL Failed 1/12 test programs. 0/36 subtests failed. dmake.exe: Error code 255, while making 'test_dynamic'

Notes:

Any suggestions would be very welcome.

The way forward always starts with a minimal test.
  • Comment on Test::Exception error on Strawberry Perl 5.14.3 ('Bareword "xception" ...')
  • Download Code

Replies are listed 'Best First'.
Re: Test::Exception error on Strawberry Perl 5.14.3 ('Bareword "xception" ...')
by stevieb (Canon) on Jul 28, 2015 at 16:55 UTC

    Can you post the test file (or at least to just after line 14), or otherwise let us know which module you're speaking of?

    I need to troubleshoot some failing tests for Strawberry Perl as well today...

      Hi stevieb, test code is below. The dist in question is CMS::Drupal::Modules::MembershipEntity. As I mentioned I find it very odd since t/40_fetch_memberships.t failed whereas t/10_obj_and_params.t, t/20_valid_drupal.t, t/50_term_object_params.t and t/60_membership_object_params.t all passed. Also the error only occurred on Strawberry 5.14.3.

      It really looks like the interpreter had a hiccup!

      Error message:

      Bareword "xception" not allowed while "strict subs" in use at C:/straw +berry5143/perl/vendor/lib/Test/Exception.pm line 4. Compilation failed in require at t/40_fetch_memberships.t line 14. BEGIN failed--compilation aborted at t/40_fetch_memberships.t line 14.

      First 7 lines of Test/Exception.pm:

      1: use strict; 2: use warnings; 3: 4: package Test::Exception; # <-- line cited in error message 5: use Test::Builder; 6: use Sub::Uplevel qw( uplevel ); 7: use base qw( Exporter );

      This is t/40_fetch_memberships.t:

      #! perl use strict; use warnings; BEGIN { ## Make sure we don't connect to our real DB if we ## have given the credentials for it $ENV{'DRUPAL_IGNORE_TEST_CREDS'} = 1; } use open ':std', ':encoding(utf8)'; use Test::More tests => 1; use Test::Group; use Test::Exception; # <-- line cited in error message use CMS::Drupal; use CMS::Drupal::Modules::MembershipEntity; use CMS::Drupal::Modules::MembershipEntity::Test; my $drupal = CMS::Drupal->new; my $dbh = build_test_db( $drupal ); my $ME = CMS::Drupal::Modules::MembershipEntity->new( dbh => $dbh +); subtest 'Feed various things to fetch_memberships()', sub { plan tests => 2; subtest 'Various arrays of valid mids', sub { plan tests => 10; for ( [], [3694], [3694, 2966], [3694, 2966, 42], [3302, 3358, 3414, 3470, 3530, 3582, 3638, 3694, 3750, 3948, + 3974, 4006, 4030, 4086], ) { my @array = @{ $_ }; my $hashref; lives_ok { $hashref = $ME->fetch_memberships( @array ) } 'Called fetch_memberships().'; my $cmp_data = build_test_data( @array ); test 'Data comparison with '. @array .' mids', sub { is( (scalar keys %{ $hashref }), (scalar keys %{ $cmp_data }), 'One item returned for each mid passed in' ); is_deeply($hashref, $cmp_data, 'Data matches' ); }; } }; subtest 'Various arrays with invalid mids', sub { plan tests => 4; for ( [3694, 'foo'], [3694, $ME], [3694, chr(0x263a)], [3694, sub { print "Hello, world\n" }], ) { my @array = @{ $_ }; dies_ok { my $hashref = $ME->fetch_memberships( @array ) } $arra +y[1]; } }; }; __END__
      The way forward always starts with a minimal test.
        As I mentioned I find it very odd since t/40_fetch_memberships.t failed whereas t/10_obj_and_params.t, t/20_valid_drupal.t, t/50_term_object_params.t and t/60_membership_object_params.t all passed.

        In those test files, the one that fails is the only one that contains:
        use open ':std', ':encoding(utf8)';
        Could that be connected to the error ? (Comment it out and see whether the same error arises.)
        Does that line *have* to be situated before the loading of Test::Exception ?

        Cheers,
        Rob
        Did you try to reproduce the problem without all that extra CMS stuff?
Re: Test::Exception error on Strawberry Perl 5.14.3 ('Bareword "xception" ...')
by ikegami (Pope) on Jul 28, 2015 at 18:30 UTC
    The line endings of C:/strawberry5143/perl/vendor/lib/Test/Exception.pm (or  t/40_fetch_memberships.t?) need to be converted from LF to CRLF.

      Hi, ikegami. Thanks for your repy, but I don't understand it:

      • How would incorrect line ending characters cause this error?
      • If an incorrect line ending caused the code to be broken into two lines, why wouldn't the first resultant line throw an error first? (Presumably it would be package Test::E)
      • Why don't the previous tests that also use Test::Exception throw the same error?
      • Why doesn't the same combination of Test::Exception and this test (from the same tarball) cause the same error on two other versions of Strawberry Perl running on the same hardware?

        Update: I guess there will be a different copy of the library files for each installed version of Strawberry Perl. So this would suggest that the test machine has a corrupted version of Test::Exception for that one Perl version?

      Thanks for helping me figure this out. Note this is not on my machine but on chorny's at CPAN testers.

      Update 2: Added question #2
      The way forward always starts with a minimal test.

        It's part of the handling of #! lines. Perl reads a block, then tries to undo the read, but it doesn't have all the necessary information to do so, so it guesses. The end result is that it thinks the file is

        xception; use Test::Builder; use Sub::Uplevel qw( uplevel ); use base qw( Exporter ); ...
        instead of
        use strict; use warnings; package Test::Exception; use Test::Builder; use Sub::Uplevel qw( uplevel ); use base qw( Exporter ); ...

        Or something like that. There are holes in that explanation. For example, how could strict subs be on when it encountered "xception"? But while I can't quite explain the result in this specific case, I'm quite sure about the cause. If I'm wrong, well, I only wasted a minute of your time. Did you try my fix?

        How would incorrect line ending characters cause this error?

        It wouldn't because perl doesn't care about crlf or lf line endings

        ikegami is assuming a cause because of "xception" which suggests an "\r" got into the output stream .... its just causing your shell to hide more of the message

Solved: Re: Test::Exception error on Strawberry Perl 5.14.3 ('Bareword "xception" ...') [ Bug in Perl ]
by 1nickt (Abbot) on Jul 29, 2015 at 22:04 UTC

    Hi, replying to myself for the archives. Thanks to Alexandr Ciornii (chorny) of CPAN testers, I've narrowed this down to an apparent bug in Strawberry Perl 5.14.3 .

    I don't have a Win32 machine myself but chorny was kind enough to test a minimal script with only:

    use open ':std', ':encoding(utf8)'; use Test::Exception;

    and it threw the same error. Removing the 'use open' line fixed the problem as syphilis guessed.

    I installed 5.14.3 on my OS X machine and the test passes fine so it appears to be that particular version of Strawberry Perl.

    Not going to file a bug report because I can't provide any useful diagnostic info. If anyone with Strawberry Perl 5.14.3 wished to do so, the gods would smile upon her or him.

    The way forward always starts with a minimal test.
      This is funny first two loop forever high CPU (trace says at binmode STDERR), the last one doesn't
      perl -d:Trace -e " eval q{ use open qw/ :std :encoding(utf8) /; use T +est::Exception; }; warn $@ " 2>2 perl -MCarp::Always -e " use open qw/ :std :encoding(UTF-8) /; use Te +st::Exception; " perl -e " use open qw/ :std :encoding(UTF-8) /; use Test::Exception; +"
      happens on both v5.12.2 and v5.14.1, 5.14.1 has
      Encode 2.47 Encode::Alias 2.16 Encode::Config 2.05 Encode::Encoding 2.05 Exporter 5.66 Exporter::Heavy 5.66 PerlIO 1.07 PerlIO::encoding 0.14 Sub::Uplevel 0.24 Test::Builder 0.98 Test::Exception 0.31 XSLoader 0.15 base 2.18 bytes 1.04 constant 1.21 open 1.08 vars 1.02 warnings 1.12 warnings::register 1.02

      5.12.2 has

      Encode 2.43 Encode::Alias 2.14 Encode::Config 2.05 Encode::Encoding 2.05 Exporter 5.64_01 Exporter::Heavy 5.64_01 PerlIO 1.06 PerlIO::encoding 0.12 Sub::Uplevel 0.22 Test::Builder 0.98 Test::Exception 0.31 XSLoader 0.15 base 2.15 bytes 1.04 open 1.07 vars 1.01 warnings 1.09 warnings::register 1.01

      Definitely an perl/perlio/open/Encode bug ... here is why I think that

      $ set PERL_ENCODE_DEBUG=999 $ perl -e " use Devel::Modlist; use open qw/ :std :encoding(utf8) /; u +se Test::Exception; " Encode::utf8 XS on at C:/perl/5.14.1/lib/MSWin32-x86-multi-thread/Enco +de.pm line 298. Bareword "xception" not allowed while "strict subs" in use at C:/perl/ +site/5.14.1/lib/Test/Exception.pm line 4. Compilation failed in require at -e line 1. BEGIN failed--compilation aborted at -e line 1. $ perl -e " use Devel::Modlist; use open qw/ :std :encoding(UTF-8) /; +use Test::Exception; " Encode::utf8 XS on at C:/perl/5.14.1/lib/MSWin32-x86-multi-thread/Enco +de.pm line 298. eval "utf-8-strict" at C:/perl/5.14.1/lib/MSWin32-x86-multi-thread/Enc +ode/Alias.pm line 32. (?^i:\bUTF-8$), utf-8-strict at C:/perl/5.14.1/lib/MSWin32-x86-multi-t +hread/Encode/Alias.pm line 45. find_alias(Encode, UTF-8)->name = utf-8-strict at C:/perl/5.14.1/lib/M +SWin32-x86-multi-thread/Encode/Alias.pm line 75. find_alias(Encode, UTF-8)->name = utf-8-strict at C:/perl/5.14.1/lib/M +SWin32-x86-multi-thread/Encode/Alias.pm line 75. $ perl -e " use Devel::Modlist; use Test::Exception; use open qw/ :st +d :encoding(UTF-8) /; " Encode::utf8 XS on at C:/perl/5.14.1/lib/MSWin32-x86-multi-thread/Enco +de.pm line 298. eval "utf-8-strict" at C:/perl/5.14.1/lib/MSWin32-x86-multi-thread/Enc +ode/Alias.pm line 32. (?^i:\bUTF-8$), utf-8-strict at C:/perl/5.14.1/lib/MSWin32-x86-multi-t +hread/Encode/Alias.pm line 45. find_alias(Encode, UTF-8)->name = utf-8-strict at C:/perl/5.14.1/lib/M +SWin32-x86-multi-thread/Encode/Alias.pm line 75. find_alias(Encode, UTF-8)->name = utf-8-strict at C:/perl/5.14.1/lib/M +SWin32-x86-multi-thread/Encode/Alias.pm line 75. $ perl -e " use Devel::Modlist; use Test::Exception; use open qw/ :st +d :encoding(utf8) /; " Encode::utf8 XS on at C:/perl/5.14.1/lib/MSWin32-x86-multi-thread/Enco +de.pm line 298. Config Encode 2.47 Encode::Alias 2.16 Encode::Config 2.05 Encode::Encoding 2.05 Exporter 5.66 Exporter::Heavy 5.66 PerlIO 1.07 PerlIO::encoding 0.14 Sub::Uplevel 0.24 Test::Builder 0.98 Test::Exception 0.31 XSLoader 0.15 base 2.18 bytes 1.04 constant 1.21 open 1.08 vars 1.02 warnings 1.12 warnings::register 1.02

      Basically a serious bug is in there in XS land somewhere, will see what happens after upgrades