Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gather/take + try/catch failure #9

Open
leonerd opened this issue Feb 11, 2019 · 2 comments
Open

gather/take + try/catch failure #9

leonerd opened this issue Feb 11, 2019 · 2 comments

Comments

@leonerd
Copy link

leonerd commented Feb 11, 2019

I've been testing out pairs of syntax-extension modules, and I have encountered the case that Syntax::Keyword::Gather + Syntax::Keyword::Try don't quite interact properly.

A take inside a try block appears to go unnoticed. Oddly though, take inside catch works fine.

I'm unsure yet if it's an issue with SKG or SKT, but I thought I'd report here so you're aware.

@leonerd
Copy link
Author

leonerd commented Feb 11, 2019

Test case:

#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

BEGIN {
   plan skip_all => "Syntax::Keyword::Gather >= 1.000 is not available"
      unless eval { require Syntax::Keyword::Gather;
                    Syntax::Keyword::Gather->VERSION( '1.000' ) };
   plan skip_all => "Syntax::Keyword::Try >= 0.07 is not available"
      unless eval { require Syntax::Keyword::Try;
                    Syntax::Keyword::Try->VERSION( '0.07' ) };

   Syntax::Keyword::Gather->import;
   Syntax::Keyword::Try->import;

   diag( "Syntax::Keyword::Gather $Syntax::Keyword::Gather::VERSION, " .
         "Syntax::Keyword::Try $Syntax::Keyword::Try::VERSION" );
}

# take inside try
{
   my @gathered = gather {
      take 1;
      try {
         take 2;
      }
      catch { }
      take 3;
   };
   is_deeply( \@gathered, [ 1 .. 3 ],
      'take inside try'
   );
}

# take inside catch
{
   my @gathered = gather {
      take 4;
      try {
         die "Oopsie";
      }
      catch {
         take 5;
      }
      take 6;
   };
   is_deeply( \@gathered, [ 4 .. 6 ],
      'take inside catch'
   );
}

done_testing;

@leonerd
Copy link
Author

leonerd commented Feb 11, 2019

Yields output:

t/80gather+try.t ....... # Syntax::Keyword::Gather 1.003002, Syntax::Keyword::Try 0.09_001t/80gather+try.t ....... 1/? 
#   Failed test 'take inside try'
#   at t/80gather+try.t line 33.
#     Structures begin differing at:
#          $got->[1] = '3'
#     $expected->[1] = '2'
# Looks like you failed 1 test of 2.
t/80gather+try.t ....... Dubious, test returned 1 (wstat 256, 0x100)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant