Skip to content
New issue

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

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

Already on GitHub? # to your account

Topic/demolish warnings #167

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jrubinator
Copy link

Fix for https://rt.cpan.org/Public/Bug/Display.html?id=124194

Single calls to demolish had the potential to emit warnings. This silences 'em.

Copy link
Member

@autarch autarch left a comment

Choose a reason for hiding this comment

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

This looks mostly good but could benefit from a few tweaks.

use lib 't/lib';
use Test::More tests => 1;

my @warnings;
Copy link
Member

Choose a reason for hiding this comment

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

We're using Test::Warnings in other tests. Might as well use it here too. That means you need to make it optional with Test::Requires but all the optional tests get run by travis so that's ok.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not entirely clear on how to write this test using Test::Warnings - some of this might be lack of familiarity on my end about when exactly Perl decides to display the warnings: when I replace use, with require, I don't see the DEMOLISH warning. And I don't see how to wrap warnings {} around a use statement - any suggestions?

Copy link
Member

Choose a reason for hiding this comment

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

There are a few ways, but the easiest is probably just to load Test::Warnings, load the module in question, and then use had_no_warnings() to do the actual test.

@@ -78,7 +78,10 @@ sub DEMOLISHALL {

foreach my $class (@isa) {
no strict 'refs';
my $demolish = *{"${class}::DEMOLISH"}{CODE};
my $demolish = do {
no warnings 'once';
Copy link
Member

Choose a reason for hiding this comment

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

A comment explaining why this is necessary would be good.

jrubinator added a commit to GrantStreetGroup/Moose that referenced this pull request Jun 27, 2018
Per pull request moose#167, add comments better explaining why these changes
are necessary, and use Test::Warnings
@jrubinator
Copy link
Author

Alright, made those tweaks. Sorry for the delay - as noted in our other thread I was spending some time away from computers in California and Yosemite :)

use warnings;

use lib 't/lib';
use Test::More tests => 2; # Test::Warnings re-tests had_no_warnings implicitly
Copy link
Member

Choose a reason for hiding this comment

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

There's no need to put in a test count.


use lib 't/lib';
use Test::More tests => 2; # Test::Warnings re-tests had_no_warnings implicitly
use Test::Requires qw(Test::Warnings);
Copy link
Member

Choose a reason for hiding this comment

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

I think if you add Test::Warnings->import(':no_end_test') here then it will only run one test.

# This variable is only in scope during the initial `use`
# As it leaves scope, Perl will call DESTROY on it
# (and Moose::Object will then go through its DEMOLISHALL method)
my $d = Demolition::Demolisher->new;
Copy link
Member

Choose a reason for hiding this comment

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

Could we move this into a block in the .t file? I think that'd make it a bit clearer.

jrubinator added a commit to GrantStreetGroup/Moose that referenced this pull request Jul 10, 2018
Per pull request moose#167, add comments better explaining why these changes
are necessary, and use Test::Warnings
Per pull request moose#167, add comments better explaining why these changes
are necessary, and use Test::Warnings
Again per pull request moose#167, move some comments around, and better use
Test::Warnings
@jrubinator
Copy link
Author

FYI I accidentally rewrote the commit history (I amended the first post-review commit), but realized that was silly and did some git surgery to put it back. The results should be what we want now.

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

Successfully merging this pull request may close these issues.

2 participants