Avoid duplication in running the same tests with and without immutable
[gitmo/Moose.git] / t / 030_roles / 019_build.t
index fe38736..fc4bb0e 100644 (file)
@@ -1,17 +1,13 @@
 #!/usr/bin/env perl
 use strict;
 use warnings;
-use Test::More tests => 7;
+use Test::More tests => 6;
 
 # this test script ensures that my idiom of:
 # role: sub BUILD, after BUILD
 # continues to work to run code after object initialization, whether the class
 # has a BUILD method or not
 
-BEGIN {
-    use_ok('Moose::Role');
-}
-
 my @CALLS;
 
 do {
@@ -37,42 +33,29 @@ do {
     with 'TestRole';
 };
 
-is_deeply([splice @CALLS], [], "no calls to BUILD yet");
-
-ClassWithBUILD->new;
-
-is_deeply([splice @CALLS], [
-    'TestRole::BUILD:before',
-    'ClassWithBUILD::BUILD',
-    'TestRole::BUILD:after',
-]);
+{
+    is_deeply([splice @CALLS], [], "no calls to BUILD yet");
 
-ClassWithoutBUILD->new;
+    ClassWithBUILD->new;
 
-is_deeply([splice @CALLS], [
-    'TestRole::BUILD:before',
-    'TestRole::BUILD',
-    'TestRole::BUILD:after',
-]);
+    is_deeply([splice @CALLS], [
+        'TestRole::BUILD:before',
+        'ClassWithBUILD::BUILD',
+        'TestRole::BUILD:after',
+    ]);
 
-ClassWithBUILD->meta->make_immutable;
-ClassWithoutBUILD->meta->make_immutable;
+    ClassWithoutBUILD->new;
 
-is_deeply([splice @CALLS], [], "no calls to BUILD yet");
+    is_deeply([splice @CALLS], [
+        'TestRole::BUILD:before',
+        'TestRole::BUILD',
+        'TestRole::BUILD:after',
+    ]);
 
-ClassWithBUILD->new;
-
-is_deeply([splice @CALLS], [
-    'TestRole::BUILD:before',
-    'ClassWithBUILD::BUILD',
-    'TestRole::BUILD:after',
-]);
-
-ClassWithoutBUILD->new;
-
-is_deeply([splice @CALLS], [
-    'TestRole::BUILD:before',
-    'TestRole::BUILD',
-    'TestRole::BUILD:after',
-]);
+    if (ClassWithBUILD->meta->is_mutable) {
+        ClassWithBUILD->meta->make_immutable;
+        ClassWithoutBUILD->meta->make_immutable;
+        redo;
+    }
+}