Permalink
Browse files

update counters to handle subtests; use subtest for attribute validat…

…ion during class validation
  • Loading branch information...
1 parent a34d489 commit 142bcd8201c01ecabebd24c1bee98fb7c2b0dd7c @RsrchBoy committed Oct 2, 2012
Showing with 26 additions and 8 deletions.
  1. +3 −1 lib/Test/Moose/More.pm
  2. +6 −5 t/funcs.pm
  3. +17 −2 t/validate_class.t
View
@@ -315,8 +315,10 @@ sub validate_thing {
skip 'Cannot examine attribute metaclass in roles', 1
if (find_meta($thing)->isa('Moose::Meta::Role'));
- local $THING_NAME = "${thing}'s attribute $name";
+ local $THING_NAME = "${thing}'s attribute $name";
+ $tb->subtest("[subtest] checking $THING_NAME" => sub {
_validate_attribute(find_meta($thing)->get_attribute($name), %$opts);
+ });
}
}
}
View
@@ -4,15 +4,16 @@ my ($_ok, $_nok, $_skip) = counters();
sub counters {
my $level = shift @_ || 0;
+ $level *= 4;
my $i = 0;
- my $indent = !$i ? q{} : $i x ' ';
+ my $indent = !$level ? q{} : (' ' x $level);
return (
- sub { 'ok ' . $i++ . " - $_[0]" },
- sub { 'not ok ' . $i++ . " - $_[0]" },
- sub { 'ok ' . $i++ . " # skip $_[0]" },
- sub { "1..$i" },
+ sub { $indent . 'ok ' . ++$i . " - $_[0]" },
+ sub { $indent . 'not ok ' . ++$i . " - $_[0]" },
+ sub { $indent . 'ok ' . ++$i . " # skip $_[0]" },
+ sub { $indent . "1..$i" },
);
}
View
@@ -101,11 +101,26 @@ note 'validate w/attribute validation';
test_out $_ok->('TestClass is a Moose class');
test_out $_ok->('TestClass has an attribute named bar');
test_out $_ok->('TestClass has an attribute named baz');
- test_out $_ok->(q{TestClass's attribute baz does TestRole::Two});
+ do {
+ my ($_ok, $_nok, $_skip, $_plan) = counters(1);
+ test_out $_ok->(q{TestClass's attribute baz does TestRole::Two});
+ test_out $_ok->(q{TestClass's attribute baz has a reader});
+ test_out $_ok->(q{TestClass's attribute baz option reader correct});
+ test_out $_plan->();
+ };
+ test_out $_ok->(q{[subtest] checking TestClass's attribute baz});
test_out $_ok->('TestClass has an attribute named foo');
validate_class 'TestClass' => (
- attributes => [ 'bar', baz => { -does => [ 'TestRole::Two' ] }, 'foo' ],
+ attributes => [
+ 'bar',
+ baz => {
+ -does => [ 'TestRole::Two' ],
+ reader => 'baz',
+ },
+ 'foo',
+ ],
);
test_test 'validate_class works correctly for attribute meta checking';
}
+
done_testing;

0 comments on commit 142bcd8

Please sign in to comment.