model: tag groups as tests
[nit.git] / src / model / model_visitor.nit
index da881a0..9244055 100644 (file)
@@ -104,13 +104,20 @@ abstract class ModelVisitor
        # Should we accept nitunit test suites?
        #
        # Default is `false`.
-       var include_test_suite = false is writable
+       var include_test = false is writable
 
        # Can we accept this `mentity` regarding its test suite status?
-       fun accept_test_suite(mentity: MEntity): Bool do
-               if include_test_suite then return true
-               if not mentity isa MModule then return true
-               return not mentity.is_test_suite
+       fun accept_test(mentity: MEntity): Bool do
+               if include_test then return true
+               if mentity isa MProperty then
+                       if mentity.is_before or mentity.is_before_all then return false
+                       if mentity.is_after or mentity.is_after_all then return false
+               end
+               if mentity isa MPropDef then
+                       if mentity.is_before or mentity.is_before_all then return false
+                       if mentity.is_after or mentity.is_after_all then return false
+               end
+               return not mentity.is_test
        end
 
        # Should we accept `MAttribute` instances?
@@ -131,7 +138,7 @@ abstract class ModelVisitor
                if not accept_visibility(mentity) then return false
                if not accept_fictive(mentity) then return false
                if not accept_empty_doc(mentity) then return false
-               if not accept_test_suite(mentity) then return false
+               if not accept_test(mentity) then return false
                if not accept_attribute(mentity) then return false
                return true
        end
@@ -144,7 +151,10 @@ redef class MEntity
        # See the specific implementation in the subclasses.
        fun visit_all(v: ModelVisitor) do end
 
-       private fun accept_visibility(min_visibility: nullable MVisibility): Bool do return true
+       private fun accept_visibility(min_visibility: nullable MVisibility): Bool do
+               if min_visibility == null then return true
+               return visibility >= min_visibility
+       end
 end
 
 redef class Model
@@ -183,13 +193,6 @@ redef class MModule
        end
 end
 
-redef class MClass
-       redef fun accept_visibility(min_visibility) do
-               if min_visibility == null then return true
-               return visibility >= min_visibility
-       end
-end
-
 redef class MClassDef
        # Visit all the classes and class definitions of the module.
        #
@@ -202,23 +205,4 @@ redef class MClassDef
                        v.enter_visit(x)
                end
        end
-
-       redef fun accept_visibility(min_visibility) do
-               if min_visibility == null then return true
-               return mclass.visibility >= min_visibility
-       end
-end
-
-redef class MProperty
-       redef fun accept_visibility(min_visibility) do
-               if min_visibility == null then return true
-               return visibility >= min_visibility
-       end
-end
-
-redef class MPropDef
-       redef fun accept_visibility(min_visibility) do
-               if min_visibility == null then return true
-               return mproperty.visibility >= min_visibility
-       end
 end