test-class icon indicating copy to clipboard operation
test-class copied to clipboard

Move the test aggregator to BEGIN so that it gets preload friendly

Open miyagawa opened this issue 13 years ago • 12 comments

This moves the test attribute collector to the BEGIN phase, so that even if Test::Class is loaded with eval() or after the fork, it should run fine.

All tests pass, and my sample test code that makes use of Test::Class runs fine as well. But I wouldn't be surprised if this breaks some obscure .t file with bunch of inline classes in it.

This patch is made per popular requests to make Test::Class forkprove friendly. I myself don't use Test::Class at all, but didn't want to add a special code to deal with Test::Class :) https://github.com/miyagawa/forkprove/pull/7

Review on Reviewable

miyagawa avatar Nov 09 '12 03:11 miyagawa

Guess we would have to update the documentation if this patch can be accepted, since require $some_test_class without BEGIN now works fine with the patch :)

I also tested a couple of CPAN modules with Test::Class - Poet, CHI, Reaction, Data::Model - all tests pass fine.

miyagawa avatar Nov 09 '12 04:11 miyagawa

Is this still good/still desired?

karenetheridge avatar Nov 17 '14 17:11 karenetheridge

I would say that it's definitely desired, but I would recommend a dev release first since it's a behavioral change. Test::Class has never been as popular as it should be, so I wouldn't be surprised if there's an impact, but if there's a long enough lead time on the dev release, it should forestall complaints.

(Edit: no, it won't forestall complaints if it breaks someone's code, but it will at least be a very reasonable defense).

Ovid avatar Nov 17 '14 17:11 Ovid

corollary: "this change needs a champion" :)

karenetheridge avatar Nov 17 '14 17:11 karenetheridge

Idea: find dists on CPAN with cpangrep that uses Test::Class and smoke them with this change?

miyagawa avatar Nov 17 '14 17:11 miyagawa

I've just release Test-Class-0.48-TRIAL to CPAN with these changes applied on top of the latest master branch, as well as with a small documentation update. I'm currently smoking various Test::Class users to see if I can observe any change in behaviour.

The code of the 0.48-TRIAL release is available at https://github.com/rafl/test-class.

rafl avatar Nov 18 '14 14:11 rafl

Turns out miyagawa's fix only works on perl version 5.12.0 and later. On older versions the attribute handler won't receive the typeglob for the symbol it's being called for, which prevents Test::Class from working.

https://gist.github.com/rafl/6fd2c8f0e669105d17ad shows an example of this.

I've uploaded Test-Class-0.49-TRIAL.tar.gz addressing this with a documentation change.

rafl avatar Nov 18 '14 15:11 rafl

I don't see the commits at https://github.com/rafl/test-class/commits/master

  • did you push?

On Tue, Nov 18, 2014 at 6:40 AM, Florian Ragwitz [email protected] wrote:

I've just release Test-Class-0.48-TRIAL to CPAN with these changes applied on top of the latest master branch, as well as with a small documentation update. I'm currently smoking various Test::Class users to see if I can observe any change in behaviour.

The code of the 0.48-TRIAL release is available at https://github.com/rafl/test-class.

— Reply to this email directly or view it on GitHub https://github.com/adrianh/test-class/pull/4#issuecomment-63480021.

karenetheridge avatar Nov 18 '14 17:11 karenetheridge

It also appears that the changes in the stable 0.48 were lost - https://metacpan.org/diff/file?target=FLORA/Test-Class-0.49-TRIAL/&source=ETHER/Test-Class-0.48/

On Tue, Nov 18, 2014 at 9:47 AM, Karen Etheridge [email protected] wrote:

I don't see the commits at https://github.com/rafl/test-class/commits/master - did you push?

On Tue, Nov 18, 2014 at 6:40 AM, Florian Ragwitz <[email protected]

wrote:

I've just release Test-Class-0.48-TRIAL to CPAN with these changes applied on top of the latest master branch, as well as with a small documentation update. I'm currently smoking various Test::Class users to see if I can observe any change in behaviour.

The code of the 0.48-TRIAL release is available at https://github.com/rafl/test-class.

— Reply to this email directly or view it on GitHub https://github.com/adrianh/test-class/pull/4#issuecomment-63480021.

karenetheridge avatar Nov 18 '14 17:11 karenetheridge

It also appears that the changes in the stable 0.48 were lost - https://metacpan.org/diff/file?target=FLORA/Test-Class-0.49-TRIAL/&source=ETHER/Test-Class-0.48/

Ah, that one is my fault - I didn't push the 0.48 release! (will do so when I can recover from my hard drive crash...)

On Tue, Nov 18, 2014 at 9:51 AM, Karen Etheridge [email protected] wrote:

It also appears that the changes in the stable 0.48 were lost - https://metacpan.org/diff/file?target=FLORA/Test-Class-0.49-TRIAL/&source=ETHER/Test-Class-0.48/

On Tue, Nov 18, 2014 at 9:47 AM, Karen Etheridge [email protected] wrote:

I don't see the commits at https://github.com/rafl/test-class/commits/master - did you push?

On Tue, Nov 18, 2014 at 6:40 AM, Florian Ragwitz < [email protected]> wrote:

I've just release Test-Class-0.48-TRIAL to CPAN with these changes applied on top of the latest master branch, as well as with a small documentation update. I'm currently smoking various Test::Class users to see if I can observe any change in behaviour.

The code of the 0.48-TRIAL release is available at https://github.com/rafl/test-class.

— Reply to this email directly or view it on GitHub https://github.com/adrianh/test-class/pull/4#issuecomment-63480021.

karenetheridge avatar Nov 18 '14 17:11 karenetheridge

It's pushed to the preload branch and there are tags for 0.49 as well https://github.com/rafl/test-class/tree/preload

miyagawa avatar Nov 18 '14 17:11 miyagawa

I am looking to merge this back into the main master stream as 0.50-stable, but it looks like tests are still failing pre-5.12, which isn't good: http://matrix.cpantesters.org/?dist=Test-Class%200.49-TRIAL

karenetheridge avatar Jun 06 '15 22:06 karenetheridge