Skip to content

add broken test for a return that uses //#1

Open
2shortplanks wants to merge 1 commit into
shadow-dot-cat:masterfrom
2shortplanks:2shortplanks/defined-or-return-broken
Open

add broken test for a return that uses //#1
2shortplanks wants to merge 1 commit into
shadow-dot-cat:masterfrom
2shortplanks:2shortplanks/defined-or-return-broken

Conversation

@2shortplanks

Copy link
Copy Markdown

No description provided.

@2shortplanks

Copy link
Copy Markdown
Author

When I run this test I currently get:

$ prove -l -v t/plugin-definedor.t
t/plugin-definedor.t ..
ok 1 - my $x = $y // $z;
ok 2 - my $x = ($y //= $z);
ok 3 - my $x; my $y = 3; $x //= $y; say $x;
ok 4 - my $x; my $y = 3; $x //= $y if $z; say $x;
Match failed at /tmp/Babble/lib/Babble/Match.pm line 41.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 255 just after 4.
Dubious, test returned 255 (wstat 65280, 0xff00)
All 4 subtests passed

Test Summary Report
-------------------
t/plugin-definedor.t (Wstat: 65280 Tests: 4 Failed: 0)
  Non-zero exit status: 255
  Parse errors: No plan found in TAP output

Comment thread t/plugin-definedor.t
[ 'my $x; my $y = 3; $x //= $y if $z; say $x;',
'my $x; my $y = 3; do { defined($_) or $_ = $y for $x } if $z; say $x;', ],
[ 'sub foo { return $x // 3 }',
'sub foo { return (map +(defined($_) ? $_ : 3)[0], $x) }', ],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be:

return (map +(defined($_) ? $_ : 3), $x)[0]

@zmughal

zmughal commented Mar 31, 2022

Copy link
Copy Markdown

I've done a little debugging here and I noticed that the $tf coderef gets called twice on the example you gave. Logging $m->text gives me:

"$x // 3"

then

"(map +(defined($_) ? $_ : 3), $x)[0]"

With the second run, the call to $m->subtexts fails.

A simple fix is to add the line

return unless $m->text =~ m,//,;

at the beginning of the $tf coderef.

@zmughal

zmughal commented Mar 31, 2022

Copy link
Copy Markdown

@shadowcat-mst, I believe that this is due to duplicates returned by Babble::Match::match_positions_of()?

@zmughal zmughal mentioned this pull request Mar 31, 2022
@zmughal

zmughal commented Mar 31, 2022

Copy link
Copy Markdown

@2shortplanks, I have added your commit (after the correction) to #6.

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

Successfully merging this pull request may close these issues.

2 participants