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

Add a test ensuring a Hash iterator misuse is not exploding #731

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion t/nqp/108-vmhash.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plan(54);
plan(55);

my $backend := nqp::getcomp('nqp').backend.name;

Expand Down Expand Up @@ -234,3 +234,16 @@ todo('Exceptions for iterators NYI on js', 2)
if $backend eq 'js';
ok($msg ne "", 'iterator throws after end');
is($msg, 'Iteration past end of iterator', 'iterator throws correct exception after end');

$msg := "";
try {
my $h := nqp::hash("a", 42);
my $i := nqp::iterator($h);
nqp::deletekey($h, "a");
nqp::shift($i);
CATCH {
$msg := nqp::getmessage($_);
}
}

ok($msg eq "", 'No SEGV on a misused hash iterator');
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not seeing $msg being changed? Is that just to create a valid ok test? If that was the intent, you can also say:

pass 'No SEGV on a misused hash iterator'

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, my bad as I did not add $msg = ... bit into CATCH, huh.
Also, given it is not directly an exception, but a SEGV is maybe a better option, let's see...

Copy link
Member Author

Choose a reason for hiding this comment

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

There is apparently no pass in nqp, so just corrected the bit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Altai-man: It looks like the test actually checks for both no SEGV (by happening at all) and no exception (by leaving $msg unchanged). Might be worth changing the test description to match that.