fREWdiculous!
7 Sep
I’ve taken care of a significant portion of the refactoring that I’m doing to disable meta-tests for the Moose test suite. I’ve done all the tests up until the 100 series (which are examples.) The following is an example of how it’s done:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #!/usr/bin/perl use strict; use warnings; use lib 't/lib'; use Test::More tests => 23; use Test::Exception; use MetaTest; { package Foo; use Moose; use Moose::Util::TypeConstraints; } skip_meta { can_ok('Foo', 'meta'); isa_ok(Foo->meta, 'Moose::Meta::Class'); } 2; meta_can_ok('Foo', 'meta', '... we got the &meta method'); ok(Foo->isa('Moose::Object'), '... Foo is automagically a Moose::Object'); skip_meta { dies_ok { Foo->meta->has_method() } '... has_method requires an arg'; dies_ok { Foo->meta->has_method('') } '... has_method requires an arg'; } 2; can_ok('Foo', 'does'); skip_meta { foreach my $function (qw( extends has before after around blessed confess type subtype as where coerce from via find_type_constraint )) { ok(!Foo->meta->has_method($function), '... the meta does not treat "' . $function . '" as a method'); } } 15; |
Typically there will be some skip_meta blocks scattered throughout a test. As it stands the skip_meta (and skip_all_meta variant) will skip if the SKIP_META_TESTS environment variable is set. As I said before, if people want to change that it’s only defined in one place so we can change how it’s done fairly easily.
There are a few places I’m not sure I need to skip yet, like things in the Moose::*::Meta namespace. But I know for sure to skip the ->meta stuff, so that’s what I’ve been doing. The 100 tests are quite a bit more complex, which is why I haven’t finished any yet. I certainly plan to, and hope to take care of them soon. But in the meantime mst can get started on Antlers as a good amount of the tests should work for him now.
If anyone wants to help out let me know, and we can make Moose faster sooner!
5 Responses for "Moose Test Refactoring"
Awesome! This is a great push forward on the Antlers effort.
You kept the plan => N.
Wouldn’t it be easier to just start using done_testing()?
Best regards,
A good way to see what needs to be skipped or not is to put a die() in the meta() method. If you reach it then it obviously needs to be skipped
@Pedro: that may be true, but I’ll let the Moose people be the deciders of that one.
@Michael: That’s a good idea! I’ll definitely use that for the 100+ tests; the problem is that I think there may be other tests we want to skip that don’t necessarily use meta but still use ::Meta. We’ll see though.
Thanks fREW! This is tedious but very much appreciated work.
Leave a reply