Avoid duplication in running the same tests with and without immutable
Shawn M Moore [Tue, 21 Apr 2009 06:24:12 +0000 (02:24 -0400)]
t/030_roles/019_build.t

index 03b149a..fc4bb0e 100644 (file)
@@ -33,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',
-]);
-
-ClassWithoutBUILD->new;
-
-is_deeply([splice @CALLS], [
-    'TestRole::BUILD:before',
-    'TestRole::BUILD',
-    'TestRole::BUILD:after',
-]);
-
-ClassWithBUILD->meta->make_immutable;
-ClassWithoutBUILD->meta->make_immutable;
-
-is_deeply([splice @CALLS], [], "no calls to BUILD yet");
-
-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',
-]);
+{
+    is_deeply([splice @CALLS], [], "no calls to BUILD yet");
+
+    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;
+    }
+}