[vala/wip/valadate: 31/71] added testfailure class
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/valadate: 31/71] added testfailure class
- Date: Sun, 19 Nov 2017 11:43:52 +0000 (UTC)
commit 450e0c83ada6ec8e9de2cff40a58e9073cf2b373
Author: Chris Daley <chebizarro gmail com>
Date: Tue Jul 19 12:37:05 2016 -0400
added testfailure class
valadate/Makefile.am | 1 +
valadate/test.vala | 2 +-
valadate/testcase.vala | 20 ++++++++------
valadate/testfailure.vala | 33 ++++++++++++++++++++++++
valadate/testresult.vala | 60 +++++++++++++++++++++++++++++++++++++++------
valadate/testrunner.vala | 20 +++++++++++++++
valadate/testsuite.vala | 38 ++++++++++++++++++++++------
7 files changed, 148 insertions(+), 26 deletions(-)
---
diff --git a/valadate/Makefile.am b/valadate/Makefile.am
index 76e2a7a..301998a 100644
--- a/valadate/Makefile.am
+++ b/valadate/Makefile.am
@@ -16,6 +16,7 @@ libvaladate_la_SOURCES = \
testexplorer.vala \
testfixture.vala \
testresult.vala \
+ testfailure.vala \
testresultfactory.vala \
testrunner.vala \
testsuite.vala \
diff --git a/valadate/test.vala b/valadate/test.vala
index ba7b3e6..356a1e7 100644
--- a/valadate/test.vala
+++ b/valadate/test.vala
@@ -30,7 +30,7 @@ public interface Valadate.Test : Object {
*
* @param result the TestResult object used to store the results of the Test
*/
- public abstract void run (TestResult? result = null);
+ public abstract void run (TestResult result);
/**
* Returns the number of tests that will be run by this test
diff --git a/valadate/testcase.vala b/valadate/testcase.vala
index ee623d5..b2eb212 100644
--- a/valadate/testcase.vala
+++ b/valadate/testcase.vala
@@ -31,12 +31,6 @@ public errordomain Valadate.TestError {
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; }
@@ -63,6 +57,17 @@ public abstract class Valadate.TestCase : Object, Test, TestFixture {
}
+ public virtual void set_up() {}
+
+ public virtual void tear_down() {}
+
+
+
+
+
+
+
+
private HashTable<string, TestAdaptor> _tests =
new HashTable<string, TestAdaptor> (str_hash, str_equal);
@@ -97,9 +102,6 @@ public abstract class Valadate.TestCase : Object, Test, TestFixture {
- public virtual void set_up() {}
-
- public virtual void tear_down() {}
diff --git a/valadate/testfailure.vala b/valadate/testfailure.vala
new file mode 100644
index 0000000..14f645a
--- /dev/null
+++ b/valadate/testfailure.vala
@@ -0,0 +1,33 @@
+/*
+ * Valadate - Unit testing library for GObject-based libraries.
+ * Copyright (C) 2016 Chris Daley <chebizarro gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Chris Daley <chebizarro gmail com>
+ */
+public class Valadate.TestFailure : Object {
+
+ public unowned Test failed_test {get;private set;}
+ public string message {get;private set;}
+
+
+ public TestFailure(Test test, string message) {
+ this.test = test;
+ this.message = message;
+ }
+
+}
diff --git a/valadate/testresult.vala b/valadate/testresult.vala
index af377b2..2eae581 100644
--- a/valadate/testresult.vala
+++ b/valadate/testresult.vala
@@ -19,18 +19,62 @@
* Authors:
* Chris Daley <chebizarro gmail com>
*/
-public interface Valadate.TestResult : Object {
+public class Valadate.TestResult : Object {
- public abstract int error_count {get;internal set;}
- public abstract int failure_count {get;internal set;}
- public abstract int run_count {get;internal set;}
+ public signal void test_error(Test test, string error);
+ public signal void test_failure(Test test, string error);
+ public signal void test_complete(Test test);
+ public signal void test_start(Test test);
+
+ internal List<TestFailure> errors = new List<TestFailure>();
+ internal List<TestFailure> failures = new List<TestFailure>();
- public abstract void add_test(Test test);
+ public bool should_stop {get;set;default=false;}
+
+ public int error_count {
+ get {
+ return (int)errors.length();
+ }
+ }
- public abstract void add_error(Test test);
+ public int failure_count {
+ get {
+ return (int)failures.length();
+ }
+ }
- public abstract void add_failure(Test test);
+ public int run_count {get;private set;default=0;}
+
+ public bool success {
+ get {
+ return (failure_count == 0 && error_count == 0);
+ }
+ }
+
+ public void add_error(Test test, string error) {
+ errors.append(new TestFailure(test, error);
+ test_error(test, error);
+ }
- public abstract void report();
+ public void add_failure(Test test, string failure) {
+ failures.append(new TestFailure(test, failure);
+ test_failure(test, failure);
+ }
+ public void start_test(Test test) {
+ run_count += test.count;
+ test_start(test);
+ }
+
+ /**
+ * Runs a {@link Valadate.Test}
+ */
+ public void run(Test test) {
+
+ test_start(test);
+
+ test.run();
+
+ test_complete(test);
+ }
}
diff --git a/valadate/testrunner.vala b/valadate/testrunner.vala
index 63b1acc..553f2c6 100644
--- a/valadate/testrunner.vala
+++ b/valadate/testrunner.vala
@@ -24,6 +24,10 @@ public class Valadate.TestRunner : Object {
private TestConfig config;
+ private SubprocessLauncher launcher =
+ new SubprocessLauncher(GLib.SubprocessFlags.STDOUT_PIPE | GLib.SubprocessFlags.STDERR_PIPE);
+
+
private string path;
private Test[] _tests;
@@ -47,6 +51,22 @@ public class Valadate.TestRunner : Object {
}
+ private void run_test() {
+ string command = "";
+
+ string[] args;
+ Shell.parse_argv(command, out args);
+
+ var process = launcher.spawnv(args);
+ var stderr_pipe = process.get_stderr_pipe();
+
+ uint8 buffer[1028];
+ var err = stderr_pipe.read(buffer);
+
+ }
+
+
+
public static int main (string[] args) {
var config = new TestConfig();
diff --git a/valadate/testsuite.vala b/valadate/testsuite.vala
index 003af6a..c041c31 100644
--- a/valadate/testsuite.vala
+++ b/valadate/testsuite.vala
@@ -22,7 +22,14 @@
public class Valadate.TestSuite : Object, Test {
- private HashTable<string, Test> tests =
+ /**
+ * The TestMethod delegate represents a {@link Valadate.Test} method
+ * that can be added to a TestCase and run
+ */
+ public delegate void TestMethod ();
+
+
+ private HashTable<string, Test> _tests =
new HashTable<string, Test> (str_hash, str_equal);
/**
@@ -36,7 +43,17 @@ public class Valadate.TestSuite : Object, Test {
*/
public int count {
get {
- return (int)tests.size();
+ return (int)_tests.size();
+ }
+ }
+
+ /**
+ * Returns a {@link GLib.List} of {@link Valadate.Test}s that will be
+ * run by this TestSuite
+ */
+ public List<weak Test> tests {
+ get {
+ return _tests.get_values();
}
}
@@ -49,21 +66,26 @@ public class Valadate.TestSuite : Object, Test {
}
/**
- * Adds a test to the suite.
- */
+ * Adds a test to the suite.
+ */
public void add_test(string name, Test test) {
- tests.set(name, test);
+ _tests.set(name, test);
}
-
public void run(TestResult result) {
- tests.foreach((k,t) => { run_test(t, result); });
+ _tests.foreach((k,t) => { run_test(t, result); });
}
public void run_test(Test test, TestResult result) {
result.run(test);
}
+
+ public new unowned Test? get(string name) {
+ return _tests.lookup(name);
+ }
-
+ public void set(string name, Test test) {
+ _tests.set(name, test);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]