[vala/wip/valadate: 9/16] refactoring of TestExplorer, now generates working dummy TAP output
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/valadate: 9/16] refactoring of TestExplorer, now generates working dummy TAP output
- Date: Mon, 26 Sep 2016 07:46:01 +0000 (UTC)
commit 097718960873852439c9b71219fd13bc18f54a23
Author: Chris Daley <chebizarro gmail com>
Date: Sun Jul 24 09:43:15 2016 -0700
refactoring of TestExplorer, now generates working dummy TAP output
tests/valadatetests.vala | 4 ++
valadate/Makefile.am | 9 ++--
valadate/testcase.vala | 2 +-
valadate/testconfig.vala | 65 ++++++++++++------------------
valadate/testexplorer.vala | 96 +++++++++++++++-----------------------------
valadate/testrunner.vala | 50 +++++++++++++++--------
valadate/testsuite.vala | 25 +----------
7 files changed, 103 insertions(+), 148 deletions(-)
---
diff --git a/tests/valadatetests.vala b/tests/valadatetests.vala
index 693c54e..231b32a 100644
--- a/tests/valadatetests.vala
+++ b/tests/valadatetests.vala
@@ -25,5 +25,9 @@ public class Valadate.Tests.TestFixture : Valadate.TestCase {
public void test_testcase() {
}
+
+ public void test_testcase_two() {
+
+ }
}
diff --git a/valadate/Makefile.am b/valadate/Makefile.am
index 06a2d20..4b084d0 100644
--- a/valadate/Makefile.am
+++ b/valadate/Makefile.am
@@ -26,8 +26,7 @@ libvaladate_la_VALAFLAGS = \
--vapidir $(top_srcdir)/vala \
--pkg gio-2.0 \
--pkg gmodule-2.0 \
- --pkg vala \
- --pkg gee \
+ --pkg libvala@PACKAGE_SUFFIX@ \
--pkg config \
--library valadate \
--vapi valadate.vapi \
@@ -39,14 +38,15 @@ libvaladate_la_VALAFLAGS = \
libvaladate_la_CFLAGS = \
$(GLIB_CFLAGS) \
$(GMODULE_CFLAGS) \
- -I$(top_srcdir)/vala \
$(NULL)
libvaladate_la_CPPFLAGS = \
$(GLIB_CPPFLAGS) \
$(GMODULE_CPPFLAGS) \
+ -I$(top_srcdir)/codegen \
-I$(top_srcdir)/vala \
-I$(top_srcdir)/gee \
+ -I$(top_srcdir)/ccode \
$(NULL)
@@ -56,10 +56,11 @@ libvaladate_la_LDFLAGS = \
$(NULL)
libvaladate_la_LIBADD = \
- $(top_builddir)/vala/libvalacore.la \
+ $(top_builddir)/codegen/libvala@PACKAGE_SUFFIX@.la \
$(COVERAGE_LIBS) \
$(GLIB_LIBS) \
$(GMODULE_LIBS) \
+ -lgio-2.0 \
$(NULL)
libvaladateincludedir = $(includedir)/vala@PACKAGE_SUFFIX@
diff --git a/valadate/testcase.vala b/valadate/testcase.vala
index 8a4af80..7f969fd 100644
--- a/valadate/testcase.vala
+++ b/valadate/testcase.vala
@@ -65,7 +65,7 @@ public abstract class Valadate.TestCase : Object, Test, TestFixture {
private List<Test> _tests = new List<Test>();
public void add_test(string testname, owned TestMethod test) {
- var adaptor = new TestAdaptor (this.name + testname, (owned)test, this);
+ var adaptor = new TestAdaptor (testname, (owned)test, this);
_tests.append(adaptor);
}
diff --git a/valadate/testconfig.vala b/valadate/testconfig.vala
index db3b06c..06be074 100644
--- a/valadate/testconfig.vala
+++ b/valadate/testconfig.vala
@@ -22,30 +22,36 @@
public class Valadate.TestConfig : Object {
- public static string seed;
- public static string testplan;
- public static string runtest;
- public static string format = "tap";
- public static bool fatal_warnings;
- public static bool list;
- public static bool quiet;
- public static bool timed;
- public static bool verbose;
- public static bool version;
- public static bool vala_version;
+ private static string _seed;
+ private static string testplan;
+ private static string runtest;
+ private static string format = "tap";
+ private static bool fatal_warnings;
+ private static bool list;
+ private static bool quiet;
+ private static bool timed;
+ private static bool verbose;
+ private static bool version;
+ private static bool vala_version;
[CCode (array_length = false, array_null_terminated = true)]
- public static string[] paths;
+ private static string[] paths;
[CCode (array_length = false, array_null_terminated = true)]
- public static string[] skip;
- [CCode (array_length = false, array_null_terminated = true)]
- public static string[] testplans;
+ private static string[] skip;
+
+ public string seed {
+ get {
+ return _seed;
+ }
+ }
public string binary {get;set;}
public TestSuite root {get;set;}
+ public int test_count {get;set;default=0;}
+
public OptionContext opt_context;
private Vala.CodeContext context;
@@ -53,7 +59,7 @@ public class Valadate.TestConfig : Object {
public const OptionEntry[] options = {
- { "seed", 0, 0, OptionArg.STRING, ref seed, "Start tests with random seed", "SEEDSTRING" },
+ { "seed", 0, 0, OptionArg.STRING, ref _seed, "Start tests with random seed", "SEEDSTRING" },
{ "format", 'f', 0, OptionArg.STRING, ref format, "Output test results using format",
"FORMAT" },
{ "g-fatal-warnings", 0, 0, OptionArg.NONE, ref fatal_warnings, "Make all warnings fatal",
null },
{ "list", 'l', 0, OptionArg.NONE, ref list, "List test cases available in a test executable",
null },
@@ -79,31 +85,17 @@ public class Valadate.TestConfig : Object {
}
private void setup_context() {
- File currdir = File.new_for_path(GLib.Environment.get_current_dir());
- File valadatedir = currdir.get_parent().get_child("valadate");
- File vapidir = currdir.get_parent().get_child("vapi");
-
-
context = new Vala.CodeContext ();
Vala.CodeContext.push (context);
context.report.enable_warnings = false;
context.report.set_verbose_errors (false);
context.verbose_mode = false;
-
- context.vapi_directories = {valadatedir.get_path(), vapidir.get_path()};
-
- context.add_external_package ("glib-2.0");
- context.add_external_package ("gobject-2.0");
- context.add_external_package ("gio-2.0");
- context.add_external_package ("gmodule-2.0");
- context.add_external_package ("valadate");
-
}
public int parse(string[] args) {
binary = args[0];
GLib.Environment.set_prgname(binary);
- root.name = binary;
+ //root.name = binary;
try {
opt_context.parse (ref args);
@@ -121,8 +113,8 @@ public class Valadate.TestConfig : Object {
return 0;
}
- if(seed == null)
- seed = "R02S%08x%08x%08x%08x".printf(
+ if(_seed == null)
+ _seed = "R02S%08x%08x%08x%08x".printf(
GLib.Random.next_int(),
GLib.Random.next_int(),
GLib.Random.next_int(),
@@ -166,12 +158,7 @@ public class Valadate.TestConfig : Object {
var parser = new Vala.Parser ();
parser.parse (context);
-
- context.check ();
-
- if (context.report.get_errors () > 0)
- throw new ConfigError.TESTPLAN("Error parsing testplan %s", path);
-
+
var testexplorer = new TestExplorer(this);
context.accept(testexplorer);
}
diff --git a/valadate/testexplorer.vala b/valadate/testexplorer.vala
index 9718dfc..974340e 100644
--- a/valadate/testexplorer.vala
+++ b/valadate/testexplorer.vala
@@ -23,9 +23,6 @@
internal class Valadate.TestExplorer : Vala.CodeVisitor {
private TestConfig config;
- private Vala.Class testcase;
- private Vala.Class testsuite;
-
private TestSuite current;
internal delegate void* Constructor(string? name = null);
@@ -39,44 +36,40 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor {
public override void visit_class(Vala.Class class) {
- if (class.get_full_name() == "Valadate.TestCase") {
- testcase = class;
- return;
- }
-
- if (class.get_full_name() == "Valadate.TestSuite") {
- testsuite = class;
- return;
- }
-
try {
-
- if (testcase != null &&
- class.is_subtype_of(testcase) &&
- class.is_abstract != true )
+ if (is_subtype_of(class, "Valadate.TestCase") &&
+ class.is_abstract != true)
current.add_test(visit_testcase(class));
- else if (testsuite != null &&
- class.is_subtype_of(testsuite) &&
- class.is_abstract != true )
+
+ else if (is_subtype_of(class, "Valadate.TestSuite") &&
+ class.is_abstract != true)
current.add_test(visit_testsuite(class));
} catch (ModuleError e) {
- stderr.puts(e.message);
+ error(e.message);
}
class.accept_children(this);
}
- public TestCase visit_testcase(Vala.Class testclass) throws ModuleError {
- string cname = Vala.Symbol.camel_case_to_lower_case(
- testclass.default_construction_method.get_full_name().replace(".","_"));
+ private bool is_subtype_of(Vala.Class class, string typename) {
+ foreach(var basetype in class.get_base_types())
+ if(((Vala.UnresolvedType)basetype).to_qualified_string() == typename)
+ return true;
+ return false;
+ }
- string tname = Vala.Symbol.camel_case_to_lower_case(
- testclass.get_full_name().replace(".","/"));
+ private unowned Constructor get_constructor(Vala.Class class) throws ModuleError {
+ var attr = new Vala.CCodeAttribute (class.default_construction_method);
+ return (Constructor)config.module.get_method(attr.name);
+ }
- unowned Constructor meth = (Constructor)config.module.get_method(cname);
- var current_test = meth("%s%s/".printf(config.root.name, tname)) as TestCase;
+ public TestCase visit_testcase(Vala.Class testclass) throws ModuleError {
+
+ unowned Constructor meth = get_constructor(testclass);
+ var current_test = meth() as TestCase;
+ current_test.name = testclass.name;
foreach(var method in testclass.get_methods()) {
if( method.name.has_prefix("test_") &&
@@ -84,58 +77,35 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor {
method.get_parameters().size == 0
) {
unowned TestMethod testmethod = null;
- string mname = Vala.Symbol.camel_case_to_lower_case(
- method.get_full_name()
- .replace(".","_")
- );
-
- testmethod = (TestMethod)config.module.get_method(mname);
+ var attr = new Vala.CCodeAttribute(method);
+ testmethod = (TestMethod)config.module.get_method(attr.name);
- if (testmethod != null)
+ if (testmethod != null) {
current_test.add_test(method.name.substring(5), ()=> {
testmethod(current_test);
});
+ }
}
}
+ config.test_count += current_test.count;
return current_test;
}
public TestSuite visit_testsuite(Vala.Class testclass) throws ModuleError {
- string cname = Vala.Symbol.camel_case_to_lower_case(
- testclass.default_construction_method.get_full_name().replace(".","_"));
-
- string tname = Vala.Symbol.camel_case_to_lower_case(
- testclass.get_full_name().replace(".","/"));
-
- unowned Constructor meth = (Constructor)config.module.get_method(cname);
- var current_test = meth("%s%s/".printf(config.root.name, tname)) as TestSuite;
-
+ unowned Constructor meth = get_constructor(testclass);
+ var current_test = meth(testclass.name) as TestSuite;
+ current_test.name = testclass.get_full_name();
return current_test;
}
public override void visit_namespace(Vala.Namespace ns) {
-
- if (ns.name == "GLib")
- return;
-
- if (ns.name == "Valadate") {
- ns.accept_children(this);
- return;
- }
if (ns.name != null) {
-
- string testname = Vala.Symbol.camel_case_to_lower_case(
- ns.get_full_name().replace(".","/"));
-
- var nstest = new TestSuite("%s%s/".printf(config.root.name, testname));
-
- if (current != null)
- current.add_test(nstest);
-
- current = nstest;
+ var testsuite = new TestSuite(ns.name);
+ current.add_test(testsuite);
+ current = testsuite;
}
-
+ ns.accept_children(this);
}
diff --git a/valadate/testrunner.vala b/valadate/testrunner.vala
index 0256fa2..97b6f4a 100644
--- a/valadate/testrunner.vala
+++ b/valadate/testrunner.vala
@@ -38,37 +38,56 @@ public class Valadate.TestRunner : Object {
this.result = result;
+ /*
if (TestConfig.runtest != null && config.root.count == 1) {
config.root.run(result);
return;
- }
+ }*/
- run_test(config.root);
+ stdout.printf("# random seed: %s\n", config.seed);
+ stdout.printf("%d..%d\n", (config.test_count > 0) ? 1 : 0, config.test_count);
+
+ run_test(config.root, "");
}
+ private static int testno = 0;
- private void run_test(Test test) {
+ private void run_test(Test test, string path) {
+
+
- message(test.count.to_string());
- if (test.count > 1) {
+ //if (test.count > 1) {
+ //message(test.name);
+
foreach(var subtest in test) {
- run_test(subtest);
+ if(subtest is TestCase || subtest is TestSuite) {
+ if(subtest is TestCase)
+ stdout.printf("# Start of %s/%s tests\n", path, subtest.name);
+ run_test(subtest, "%s/%s".printf(path, subtest.name));
+ if(subtest is TestCase)
+ stdout.printf("# End of %s/%s tests\n", path, subtest.name);
+ } else {
+ testno++;
+ stdout.printf("ok %d %s/%s\n", testno, path, subtest.name);
+ }
}
- } else {
- string command = "%s -r ".printf(config.binary);
+ //} else {
+ // message(test.name);
+ // string command = "%s -r ".printf(config.binary);
- string[] args;
- Shell.parse_argv(command, out args);
+ // 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);
-
- }
+ */
+ //}
}
@@ -83,12 +102,7 @@ public class Valadate.TestRunner : Object {
var runner = new TestRunner(config);
var testresult = new TestResult();
- try {
- runner.run(testresult);
- } catch (ConfigError err) {
- stderr.puts(err.message);
- return 1;
- }
+ runner.run(testresult);
return 0;
}
diff --git a/valadate/testsuite.vala b/valadate/testsuite.vala
index aaf4b72..37ca8b9 100644
--- a/valadate/testsuite.vala
+++ b/valadate/testsuite.vala
@@ -35,11 +35,7 @@ public class Valadate.TestSuite : Object, Test {
*/
public int count {
get {
- int testcount = 0;
- _tests.foreach((t) => {
- testcount += t.count;
- });
- return testcount;
+ return (int)_tests.length();
}
}
@@ -74,24 +70,7 @@ public class Valadate.TestSuite : Object, Test {
}
public Test get_test(int index) {
- int testcount = 0;
- Test test = null;
-
- _tests.foreach((t) => {
-
- if (t.count + testcount >= index) {
-
- int offset = index - testcount;
-
- test = t.get_test(offset);
-
-
- } else {
- testcount += t.count;
- }
- });
-
- return test;
+ return _tests.nth_data((uint)index);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]