[vala/wip/valadate: 68/71] removed TestGatherer, TestPlan now does single pass



commit a4115fbb82b977f5cc76d99528f2154927775798
Author: Chris Daley <chebizarro gmail com>
Date:   Mon May 1 08:40:18 2017 -0700

    removed TestGatherer, TestPlan now does single pass

 tests/valadatetests.vala   |   12 +++++
 valadate/Makefile.am       |    1 -
 valadate/testgatherer.vala |  108 --------------------------------------------
 valadate/testplan.vala     |   56 +++++++++++++----------
 4 files changed, 43 insertions(+), 134 deletions(-)
---
diff --git a/tests/valadatetests.vala b/tests/valadatetests.vala
index 5578b4a..7f20041 100644
--- a/tests/valadatetests.vala
+++ b/tests/valadatetests.vala
@@ -62,3 +62,15 @@ public class Valadate.Tests.TestFixtureTwo : Valadate.TestCase {
                assert(true);
        }
 }
+
+public abstract class Valadate.Tests.AbstractTests : Valadate.TestCase {
+
+       public virtual void test_virtual () {
+               stdout.printf ("This is an abstract test %s", Type.from_instance(this).name());
+       }
+       
+}
+
+public class Valadate.Tests.ConcreteTests : AbstractTests {
+
+}
diff --git a/valadate/Makefile.am b/valadate/Makefile.am
index fe5b764..0979ed6 100644
--- a/valadate/Makefile.am
+++ b/valadate/Makefile.am
@@ -33,7 +33,6 @@ libvaladate_la_VALASOURCES = \
        testcase.vala \
        testconfig.vala \
        testmodule.vala \
-       testgatherer.vala \
        testplan.vala \
        testresult.vala \
        testreport.vala \
diff --git a/valadate/testplan.vala b/valadate/testplan.vala
index 1f2e095..2895752 100644
--- a/valadate/testplan.vala
+++ b/valadate/testplan.vala
@@ -24,11 +24,10 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
 
        [CCode (has_target = false)]
        public delegate void TestMethod (TestCase self) throws Error;
-
        public delegate void AsyncTestMethod (TestCase self, AsyncReadyCallback cb);
        public delegate void AsyncTestMethodResult (TestCase self, AsyncResult res) throws Error;
-
        public delegate Type GetType ();
+       public delegate TestCase Constructor ();
 
        public File plan { get; set; }
 
@@ -43,11 +42,12 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
        public TestSuite root { get; set; }
 
        private Vala.CodeContext context;
-       private TestGatherer gatherer;
-       private delegate TestCase Constructor ();
        private TestSuite testsuite;
        private TestCase testcase;
 
+       private HashTable<Type, Vala.Class> classes =
+               new HashTable<Type, Vala.Class> (direct_hash, direct_equal);
+
        public TestPlan (TestAssembly assembly) throws Error {
 
                this.assembly = assembly;
@@ -87,8 +87,6 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
                        context, Vala.SourceFileType.PACKAGE, plan.get_path ()));
                var parser = new Vala.Parser ();
                parser.parse (context);
-               gatherer = new TestGatherer (assembly);
-               context.accept (gatherer);
                context.accept (this);
        }
 
@@ -110,7 +108,6 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
        }
 
        public override void visit_class (Vala.Class cls) {
-
                var label = "/%s".printf (cls.get_full_name ().replace (".","/"));
 
                if(!in_testpath (label))
@@ -153,12 +150,21 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
        }
 
        private bool is_subtype_of (Vala.Class cls, Type type) {
-               var t = Type.from_name (cls.get_full_name ().replace (".",""));
+               var t = find_type (cls);
                if (t.is_a (type))
                        return true;
                return false;
        }
 
+       private Type find_type (Vala.Class cls) throws Error {
+               unowned TestPlan.GetType node_get_type = (TestPlan.GetType)assembly.get_method 
("%sget_type".printf (get_ccode_lower_case_prefix (cls)));
+               var classtype = node_get_type ();
+               if (classtype.is_a (typeof (TestCase)) || classtype.is_a (typeof (TestSuite)))
+                       classes.insert (classtype, cls);
+
+               return classtype;
+       }
+
        private unowned Constructor get_constructor (Vala.Class cls) throws Error {
                return (Constructor)assembly.get_method (get_symbol_name (cls.default_construction_method));
        }
@@ -168,7 +174,7 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
                var t = Type.from_name (cls.get_full_name ().replace (".",""));
                var p = t.parent ();
                if (p != typeof (TestCase)) {
-                       var basecls = gatherer.classes.get (p);
+                       var basecls = classes.get (p);
                        if (basecls != null)
                                visit_testcase (basecls);
                }
@@ -341,39 +347,39 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
 
        private string get_ccode_lower_case_prefix (Vala.Symbol sym) {
                var ccode = sym.get_attribute ("CCode");
-               string _lower_case_prefix = null;
+               string lower_case_prefix = null;
 
                if (ccode != null) {
-                       _lower_case_prefix = ccode.get_string ("lower_case_cprefix");
-                       if (_lower_case_prefix == null && (sym is Vala.ObjectTypeSymbol)) {
-                               _lower_case_prefix = ccode.get_string ("cprefix");
+                       lower_case_prefix = ccode.get_string ("lower_case_cprefix");
+                       if (lower_case_prefix == null && (sym is Vala.ObjectTypeSymbol)) {
+                               lower_case_prefix = ccode.get_string ("cprefix");
                        }
                }
-               if (_lower_case_prefix == null) {
+               if (lower_case_prefix == null) {
                        if (sym is Vala.Namespace) {
                                if (sym.name == null) {
-                                       _lower_case_prefix = "";
+                                       lower_case_prefix = "";
                                } else {
-                                       _lower_case_prefix = "%s%s_".printf (get_ccode_lower_case_prefix 
(sym.parent_symbol), Vala.Symbol.camel_case_to_lower_case (sym.name));
+                                       lower_case_prefix = "%s%s_".printf (get_ccode_lower_case_prefix 
(sym.parent_symbol), Vala.Symbol.camel_case_to_lower_case (sym.name));
                                }
                        } else if (sym is Vala.Method) {
                                // for lambda expressions
-                               _lower_case_prefix = "";
+                               lower_case_prefix = "";
                        } else {
-                               _lower_case_prefix = "%s%s_".printf (get_ccode_lower_case_prefix 
(sym.parent_symbol), get_ccode_lower_case_suffix (sym));
+                               lower_case_prefix = "%s%s_".printf (get_ccode_lower_case_prefix 
(sym.parent_symbol), get_ccode_lower_case_suffix (sym));
                        }
                }
-               return _lower_case_prefix;
+               return lower_case_prefix;
        }
 
        private string get_ccode_lower_case_suffix (Vala.Symbol sym) {
                var ccode = sym.get_attribute ("CCode");
-               string _lower_case_suffix = null;
+               string lower_case_suffix = null;
 
                if (ccode != null) {
-                       _lower_case_suffix = ccode.get_string ("lower_case_csuffix");
+                       lower_case_suffix = ccode.get_string ("lower_case_csuffix");
                }
-               if (_lower_case_suffix == null) {
+               if (lower_case_suffix == null) {
                        if (sym is Vala.ObjectTypeSymbol) {
                                var csuffix = Vala.Symbol.camel_case_to_lower_case (sym.name);
                                // remove underscores in some cases to avoid conflicts of type macros
@@ -385,11 +391,11 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
                                if (csuffix.has_suffix ("_class")) {
                                        csuffix = csuffix.substring (0, csuffix.length - "_class".length) + 
"class";
                                }
-                               _lower_case_suffix = csuffix;
+                               lower_case_suffix = csuffix;
                        } else if (sym.name != null) {
-                               _lower_case_suffix = Vala.Symbol.camel_case_to_lower_case (sym.name);
+                               lower_case_suffix = Vala.Symbol.camel_case_to_lower_case (sym.name);
                        }
                }
-               return _lower_case_suffix;
+               return lower_case_suffix;
        }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]