[vala/wip/valadate: 41/60] refactoring of testcase and testsuite



commit e9a0ecbebb19f9e764551a63ffb8246a05ed3e98
Author: Chris Daley <chebizarro gmail com>
Date:   Tue Jul 19 00:48:07 2016 -0400

    refactoring of testcase and testsuite

 valadate/Makefile.am    |    1 -
 valadate/test.vala      |   10 +++++---
 valadate/testcase.vala  |   52 ++++++++++++++++++++++++++++++++++------------
 valadate/testsuite.vala |   45 +++++++++++++++++++++++++++++++++++++++-
 4 files changed, 88 insertions(+), 20 deletions(-)
---
diff --git a/valadate/Makefile.am b/valadate/Makefile.am
index 900b648..76e2a7a 100644
--- a/valadate/Makefile.am
+++ b/valadate/Makefile.am
@@ -7,7 +7,6 @@ lib_LTLIBRARIES = \
 
 libvaladate_la_SOURCES = \
        assembly.vala \
-       compositetest.vala \
        module.vala \
        tap.vala \
        tapresult.vala \
diff --git a/valadate/test.vala b/valadate/test.vala
index be5882a..ba7b3e6 100644
--- a/valadate/test.vala
+++ b/valadate/test.vala
@@ -24,15 +24,17 @@
  * It is the base interface for all runnable Tests.
  */
 public interface Valadate.Test : Object {
+               
        /**
         * Runs the Tests and collects the results in a TestResult 
         *
         * @param result the TestResult object used to store the results of the Test
         */
-       public abstract TestResult? run (TestResult? result = null);
+       public abstract void run (TestResult? result = null);
 
-       public abstract string name {get;set;} 
-
-       public delegate void TestMethod ();
+       /**
+        * Returns the number of tests that will be run by this test
+        */
+       public abstract int count {get;}
 
 }
diff --git a/valadate/testcase.vala b/valadate/testcase.vala
index de65d1c..ee623d5 100644
--- a/valadate/testcase.vala
+++ b/valadate/testcase.vala
@@ -28,14 +28,45 @@ public errordomain Valadate.TestError {
        NOT_FOUND
 }
 
-public abstract class Valadate.TestCase : CompositeTest, TestFixture {
+public abstract class Valadate.TestCase : Object, Test, TestFixture {
+
+       /**
+        * The TestMethod delegate represents a {@link Valadate.Test} method
+        * that can be added to a TestCase and run
+        */
+       public delegate void TestMethod ();
+
+       /**
+        * the name of the TestCase
+        */
+       public string name { get; set; }
+
+       /**
+        * The public constructor takes an optional string parameter for the
+        * TestCase's name
+        */
+       public TestCase(string? name = null) {
+               this.name = name;
+       }
+
+       /**
+        * Returns the number of {@link Valadate.Test}s that will be run by this TestCase
+        */
+       public int count {get;set;}
+
+       
+       public void run(TestResult result) {
+
+               result.run(this);
+               
+               return result;
+       }
+
+
 
        private HashTable<string, TestAdaptor> _tests =
                new HashTable<string, TestAdaptor> (str_hash, str_equal);
 
-       public virtual void set_up() {}
-
-       public virtual void tear_down() {}
 
        private class TestAdaptor : Object, Test {
 
@@ -64,18 +95,11 @@ public abstract class Valadate.TestCase : CompositeTest, TestFixture {
 
 
 
-       public override TestResult? run_test(string testname, TestResult? result = null) throws TestError {
-               if(!_tests.contains(testname))
-                       throw new TestError.NOT_FOUND("The Test %s was not found", testname);
-               
-               var test = _tests.get(testname);
-               
-               test.run(result);
-               
-               return result;
-       }
 
 
+       public virtual void set_up() {}
+
+       public virtual void tear_down() {}
 
 
 
diff --git a/valadate/testsuite.vala b/valadate/testsuite.vala
index ab77558..003af6a 100644
--- a/valadate/testsuite.vala
+++ b/valadate/testsuite.vala
@@ -20,7 +20,50 @@
  *     Chris Daley <chebizarro gmail com>
  */
 
-public abstract class Valadate.TestSuite : CompositeTest {
+public class Valadate.TestSuite : Object, Test {
+
+       private HashTable<string, Test> tests =
+               new HashTable<string, Test> (str_hash, str_equal);
+       
+       /**
+        * the name of the TestSuite
+        */
+       public string name { get; set; }
+
+       /**
+        * Returns the number of {@link Valadate.Test}s that will be run by 
+        * this TestSuite
+        */
+       public int count {
+               get {
+                       return (int)tests.size();
+               }
+       }
+
+       /**
+        * The public constructor takes an optional string parameter for the
+        * TestSuite's name
+        */
+       public TestSuite(string? name = null) {
+               this.name = name;
+       }
+
+       /**
+       * Adds a test to the suite.
+       */
+       public void add_test(string name, Test test) {
+               tests.set(name, test);
+       }
+
+
+       public void run(TestResult result) {
+               tests.foreach((k,t) => { run_test(t, result); });
+       }
+
+       public void run_test(Test test, TestResult result) {
+               result.run(test);
+       }
+
 
        
 }


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