[vala/wip/valadate: 69/101] removed original testrunner.sh
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/valadate: 69/101] removed original testrunner.sh
- Date: Sat, 7 Oct 2017 10:55:47 +0000 (UTC)
commit e990dd483028adb01df3f2cfed869d1559e5bee5
Author: chebizarro gmail com <chebizarro gmail com>
Date: Sun Jul 31 07:41:56 2016 -0700
removed original testrunner.sh
tests/valadatetests.vala | 13 ++++++---
tests/valatests.vala | 9 +-----
tests/valatestsfactory.vala | 61 ++++++++++++++++++-----------------------
valadate/module.vala | 4 +--
valadate/test.vala | 3 --
valadate/testconfig.vala | 55 +++----------------------------------
valadate/testexplorer.vala | 63 ++++++++++++++++++++++++++++++++++---------
valadate/testresult.vala | 28 +++++++++++-------
valadate/testrunner.vala | 11 +++-----
valadate/testsuite.vala | 1 -
10 files changed, 114 insertions(+), 134 deletions(-)
---
diff --git a/tests/valadatetests.vala b/tests/valadatetests.vala
index d301bdd..6a2abb0 100644
--- a/tests/valadatetests.vala
+++ b/tests/valadatetests.vala
@@ -32,15 +32,20 @@ public class Valadate.Tests.TestFixture : Valadate.TestCase {
}
public void test_testcase_1() {
- message("This is a test of the system");
- //skip("Because it broke");
- //fail("No particular reason");
+
+ string key = "XDG_DATA_DIRS";
+ var val = Environment.get_variable(key);
+ message("%s = %s",key, val);
+
+ foreach(var item in Environment.get_system_data_dirs())
+ message("%s",item);
+
}
public void test_testcase_2() {
- debug("This is a second test of the system");
message(Valadate.get_current_test_path());
skip("No reason");
+ debug("This is a second test of the system");
}
public void test_testcase_3() {
diff --git a/tests/valatests.vala b/tests/valatests.vala
index da04512..9ecc69b 100644
--- a/tests/valatests.vala
+++ b/tests/valatests.vala
@@ -8,10 +8,6 @@
* point), it will compile and run it. The test is deemed succesful if
* it compiles and runs without error.
*
- * If the test is a collection of {@ref Valadate.TestCase}s then it
- * compiles the test and runs it. The test results will be appeneded to
- * the TestFixture's. Not yet implemented.
- *
* If the test is a .test file it will be parsed, the components
* assembled, compiled and run. The test is deemed succesful if
* it compiles and runs without error.
@@ -99,13 +95,10 @@ public class Vala.Tests : Valadate.TestSuite {
bug(testname.substring(3));
var prog = factory.get_test_program(testfile);
prog.run();
+ factory.cleanup();
} catch (Error e) {
fail(e.message);
}});
}
-
- public override void tear_down() {
- factory.cleanup();
- }
}
}
diff --git a/tests/valatestsfactory.vala b/tests/valatestsfactory.vala
index 90dea8b..ebe140e 100644
--- a/tests/valatestsfactory.vala
+++ b/tests/valatestsfactory.vala
@@ -26,12 +26,25 @@ internal class Vala.TestsFactory : Object {
internal static File testdir;
internal static File buildir;
internal static File valac;
+ internal static File vapidir;
class construct {
currdir = File.new_for_path(GLib.Environment.get_current_dir());
testdir = currdir.get_child(".tests");
buildir = currdir.get_parent();
- valac = buildir.get_child("compiler").get_child("valac");
+
+ var usevalac = Environment.get_variable("VALAC");
+ if (usevalac != null && File.new_for_path(usevalac).query_exists())
+ valac = File.new_for_path(usevalac);
+ else
+ valac = buildir.get_child("compiler").get_child("valac");
+
+ var usevapidir = Environment.get_variable("VAPIDIR");
+ if (usevapidir != null && File.new_for_path(usevapidir).query_exists())
+ vapidir = File.new_for_path(usevapidir);
+ else
+ vapidir = buildir.get_child("vapi");
+
}
private static TestsFactory instance;
@@ -50,7 +63,7 @@ internal class Vala.TestsFactory : Object {
compiler = new ValaCompiler(valac);
}
- public void cleanup() {
+ public void cleanup() throws Error {
foreach (var file in tempfiles)
if(file.query_exists())
file.delete();
@@ -67,9 +80,7 @@ internal class Vala.TestsFactory : Object {
if(testfile.get_basename().has_suffix(".vala") || testfile.get_basename().has_suffix(".gs")) {
program = compiler.compile(testdir.get_child(testname), testfile, "--main main");
- }
-
- if(testfile.get_basename().has_suffix(".test")) {
+ } else if(testfile.get_basename().has_suffix(".test")) {
var stream = new DataInputStream(testfile.read());
string line = stream.read_line(null);
@@ -99,12 +110,10 @@ internal class Vala.TestsFactory : Object {
program = new TestProgram(testdir.get_child(testname));
break;
}
-
}
programs += program;
return program;
}
-
public abstract class Program : Object {
@@ -155,7 +164,7 @@ internal class Vala.TestsFactory : Object {
}
}
- public virtual void cleanup() {
+ public virtual void cleanup() throws Error {
foreach(File file in files)
if(file.query_exists())
file.delete();
@@ -202,12 +211,13 @@ internal class Vala.TestsFactory : Object {
public DBusTest(string testname, string packages, DataInputStream stream) throws Error {
base(testdir.get_child(testname + ".server"));
+ var factory = TestsFactory.get_instance();
var clientfile = testdir.get_child(testname + ".client.vala");
var serverfile = testdir.get_child(testname + ".server.vala");
add_file_from_stream(clientfile, stream, "Program: client", "Program: server");
add_file_from_stream(serverfile, stream, null, null);
- client = TestsFactory.get_instance().compiler.compile(testdir.get_child(testname +
".client"), clientfile, packages);
- server = TestsFactory.get_instance().compiler.compile(testdir.get_child(testname +
".server"), serverfile, packages);
+ client = factory.compiler.compile(testdir.get_child(testname + ".client"),
clientfile, packages);
+ server = factory.compiler.compile(testdir.get_child(testname + ".server"),
serverfile, packages);
}
public override void run(string? command = null) throws Error {
@@ -221,7 +231,7 @@ internal class Vala.TestsFactory : Object {
});
}
- public override void cleanup() {
+ public override void cleanup() throws Error {
server.cleanup();
client.cleanup();
base.cleanup();
@@ -254,11 +264,10 @@ internal class Vala.TestsFactory : Object {
testprogam = compiler.compile(program, source, packages);
}
- public override void cleanup() {
+ public override void cleanup() throws Error {
testprogam.cleanup();
base.cleanup();
}
-
}
public class GIRTestProgram : TestProgram {
@@ -302,7 +311,6 @@ internal class Vala.TestsFactory : Object {
var diff = new Diff();
diff.run("-Bw %s %s".printf(vapi.get_path(), vapifile.get_path()));
}
-
}
public class Diff : Program {
@@ -310,26 +318,17 @@ internal class Vala.TestsFactory : Object {
public Diff() {
base(File.new_for_path(Environment.find_program_in_path ("diff")));
}
-
}
public class VapiGen : Program {
- private string girdirs = "";
- private static File vapidir;
-
public VapiGen() {
base(buildir.get_child("vapigen").get_child("vapigen"));
- foreach(string dir in Environment.get_system_data_dirs())
- if(File.new_for_path(dir).get_child("gir-1.0").query_exists())
- girdirs +=
"--girdir=%s/gir-1.0".printf(File.new_for_path(dir).get_child("gir-1.0").get_path());
- vapidir = buildir.get_child("vapi");
}
public File compile(string testname, File girfile) throws Error {
- string command = "--vapidir %s %s --library %s %s".printf(
+ string command = "--vapidir %s --library %s %s".printf(
vapidir.get_path(),
- girdirs,
testname,
girfile.get_path());
run(command);
@@ -346,15 +345,10 @@ internal class Vala.TestsFactory : Object {
-X -Wno-deprecated-declarations -X -Werror=return-type
-X -Werror=init-self -X -Werror=implicit -X -Werror=sequence-point
-X -Werror=return-type -X -Werror=uninitialized -X -Werror=pointer-arith
- -X -Werror=int-to-pointer-cast -X -Werror=pointer-to-int-cast""";
-
- internal static File vapidir;
-
- class construct {
- vapidir = buildir.get_child("vapi");
- }
+ -X -Werror=int-to-pointer-cast -X -Werror=pointer-to-int-cast
+ -X -Wformat -X -Werror=format-security -X -Werror=format-nonliteral
+ -X -Werror=redundant-decls""";
-
public ValaCompiler(File compiler) {
base(compiler);
}
@@ -366,7 +360,6 @@ internal class Vala.TestsFactory : Object {
var prog = new TestProgram(binary);
prog.add_file(binary.get_parent().get_child(binary.get_basename() + ".c"));
return prog;
- }
-
+ }
}
}
diff --git a/valadate/module.vala b/valadate/module.vala
index c364c2f..80934c4 100644
--- a/valadate/module.vala
+++ b/valadate/module.vala
@@ -39,9 +39,7 @@ public class Valadate.Module : Object {
lib_path = libpath;
}
- public void load_module() throws ModuleError
- requires(lib_path != null)
- {
+ public void load_module() throws ModuleError {
if (!File.new_for_path(lib_path).query_exists())
throw new ModuleError.NOT_FOUND("Module: %s does not exist", lib_path);
diff --git a/valadate/test.vala b/valadate/test.vala
index 66201ae..a3d2669 100644
--- a/valadate/test.vala
+++ b/valadate/test.vala
@@ -70,13 +70,10 @@ public interface Valadate.Test : Object {
return true;
}
-
public int size {
get {
return this.test.count;
}
}
-
}
-
}
diff --git a/valadate/testconfig.vala b/valadate/testconfig.vala
index d61ac7e..525e6ae 100644
--- a/valadate/testconfig.vala
+++ b/valadate/testconfig.vala
@@ -69,18 +69,10 @@ public class Valadate.TestConfig : Object {
}
}
- 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;
- internal Module module;
-
-
public const OptionEntry[] options = {
{ "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" },
@@ -106,7 +98,7 @@ public class Valadate.TestConfig : Object {
}
public int parse(string[] args) {
- binary = args[0];
+ var binary = args[0];
GLib.Environment.set_prgname(binary);
try {
@@ -135,7 +127,7 @@ public class Valadate.TestConfig : Object {
root = new TestSuite("/");
try {
- load();
+ load(binary);
} catch (ConfigError e) {
stdout.printf ("%s\n", e.message);
return 1;
@@ -144,47 +136,10 @@ public class Valadate.TestConfig : Object {
return -1;
}
- private void load() throws ConfigError {
- string testdir = Path.get_dirname(binary).replace(".libs", "");
-
- string testplan = Path.get_basename(binary);
- if(testplan.has_prefix("lt-"))
- testplan = testplan.substring(3);
-
- string testplanfile = testdir + GLib.Path.DIR_SEPARATOR_S + testplan + ".vapi";
-
- if (!FileUtils.test (testplanfile, FileTest.EXISTS))
- throw new ConfigError.TESTPLAN("Test Plan %s Not Found!", testplanfile);
-
- try {
- module = new Module(binary);
- module.load_module();
- load_test_plan(testplanfile);
- } catch (ModuleError e) {
- throw new ConfigError.MODULE(e.message);
- }
- }
-
- internal void load_test_plan(string path) throws ConfigError {
- setup_context();
-
- context.add_source_file (new Vala.SourceFile (context, Vala.SourceFileType.PACKAGE, path));
-
- var parser = new Vala.Parser ();
- parser.parse (context);
-
- var testexplorer = new TestExplorer(this);
- context.accept(testexplorer);
+ private void load(string binary) throws ConfigError {
+ var testexplorer = new TestExplorer(binary, root);
+ testexplorer.load();
}
-
- private void setup_context() {
- context = new Vala.CodeContext ();
- Vala.CodeContext.push (context);
- context.report.enable_warnings = false;
- context.report.set_verbose_errors (false);
- context.verbose_mode = false;
- }
-
}
diff --git a/valadate/testexplorer.vala b/valadate/testexplorer.vala
index ac4dda3..d812340 100644
--- a/valadate/testexplorer.vala
+++ b/valadate/testexplorer.vala
@@ -22,18 +22,58 @@
internal class Valadate.TestExplorer : Vala.CodeVisitor {
- private TestConfig config;
- private TestSuite current;
-
internal delegate void* Constructor();
internal delegate void TestMethod(TestCase self);
+
+ private TestSuite current;
+ private Vala.CodeContext context;
+ private Module module;
+ private string binary;
+ private string? running;
- public TestExplorer(TestConfig config) {
+ public TestExplorer(string binary, TestSuite root) {
+ this.binary = binary;
+ this.current = root;
+ this.running = Valadate.get_current_test_path();
+ }
+
+ public void load() throws ConfigError {
+ string testdir = Path.get_dirname(binary).replace(".libs", "");
+
+ string testplan = Path.get_basename(binary);
+ if(testplan.has_prefix("lt-"))
+ testplan = testplan.substring(3);
+
+ string testplanfile = testdir + GLib.Path.DIR_SEPARATOR_S + testplan + ".vapi";
+
+ if (!FileUtils.test (testplanfile, FileTest.EXISTS))
+ throw new ConfigError.TESTPLAN("Test Plan %s Not Found!", testplanfile);
+
+ try {
+ module = new Module(binary);
+ module.load_module();
+ load_test_plan(testplanfile);
+ } catch (ModuleError e) {
+ throw new ConfigError.MODULE(e.message);
+ }
+ }
- this.config = config;
- this.current = config.root;
+ internal void load_test_plan(string path) throws ConfigError {
+ setup_context();
+ context.add_source_file (new Vala.SourceFile (context, Vala.SourceFileType.PACKAGE, path));
+ var parser = new Vala.Parser ();
+ parser.parse (context);
+ context.accept(this);
}
+ private void setup_context() {
+ context = new Vala.CodeContext ();
+ Vala.CodeContext.push (context);
+ context.report.enable_warnings = false;
+ context.report.set_verbose_errors (false);
+ context.verbose_mode = false;
+ }
+
public override void visit_class(Vala.Class class) {
try {
@@ -60,7 +100,7 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor {
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);
+ return (Constructor)module.get_method(attr.name);
}
public TestCase visit_testcase(Vala.Class testclass) throws ModuleError {
@@ -74,13 +114,13 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor {
method.has_result != true &&
method.get_parameters().size == 0) {
- if (config.runtest != null &&
- config.runtest != "/" + method.get_full_name().replace(".","/"))
+ if (running != null &&
+ running != "/" + method.get_full_name().replace(".","/"))
continue;
unowned TestMethod testmethod = null;
var attr = new Vala.CCodeAttribute(method);
- testmethod = (TestMethod)config.module.get_method(attr.name);
+ testmethod = (TestMethod)module.get_method(attr.name);
if (testmethod != null) {
current_test.add_test(method.name, ()=> {
@@ -89,7 +129,6 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor {
}
}
}
- config.test_count += current_test.count;
return current_test;
}
@@ -97,8 +136,6 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor {
unowned Constructor meth = get_constructor(testclass);
var current_test = meth() as TestSuite;
current_test.name = testclass.name;
- foreach(var test in current_test)
- config.test_count += test.count;
return current_test;
}
diff --git a/valadate/testresult.vala b/valadate/testresult.vala
index 73a6908..0795ce1 100644
--- a/valadate/testresult.vala
+++ b/valadate/testresult.vala
@@ -53,25 +53,23 @@ public class Valadate.TestResult : Object {
private Queue<TestReport> reports = new Queue<TestReport>();
private HashTable<Test, TestReport> tests = new HashTable<Test, TestReport>(direct_hash,
direct_equal);
- public string binary {
- get {
- return config.binary;
- }
- }
-
private TestConfig config;
private TestRunner runner;
private MainLoop loop;
+ public int testcount {get;private set;default=0;}
+
public TestResult(TestConfig config) {
this.config = config;
}
public void report() {
+
if (reports.is_empty()) {
loop.quit();
return;
}
+
var rpt = reports.peek_head();
if (rpt.status == TestStatus.PASSED ||
@@ -119,16 +117,18 @@ public class Valadate.TestResult : Object {
this.runner = runner;
+ count_tests(config.root);
+
if (!config.list_only && config.runtest == null) {
stdout.printf("# random seed: %s\n", config.seed);
- stdout.printf("1..%d\n", config.test_count);
+ stdout.printf("1..%d\n", testcount);
}
run_test(config.root, "");
if (config.runtest == null) {
loop = new MainLoop();
- var time = new TimeoutSource (30);
+ var time = new TimeoutSource (15);
time.set_callback (() => {
report();
return true;
@@ -138,13 +138,21 @@ public class Valadate.TestResult : Object {
}
}
+ private void count_tests(Test test) {
+ if(test is TestSuite)
+ foreach(var subtest in test)
+ count_tests(subtest);
+ else
+ testcount += test.count;
+ }
+
private int testno = 0;
private void run_test(Test test, string path) {
foreach(var subtest in test) {
string testpath = "%s/%s".printf(path, subtest.name);
if(subtest is TestCase) {
- if(config.runtest == null) {
+ if(config.runtest == null && !config.list_only) {
reports.push_tail(new TestReport(subtest, TestStatus.PASSED,-1,"#
Start of %s tests\n".printf(testpath)));
run_test(subtest, testpath);
reports.push_tail(new TestReport(subtest, TestStatus.PASSED,-1,"# End
of %s tests\n".printf(testpath)));
@@ -173,6 +181,4 @@ public class Valadate.TestResult : Object {
}
}
}
-
-
}
diff --git a/valadate/testrunner.vala b/valadate/testrunner.vala
index 8ff5363..6d7d78b 100644
--- a/valadate/testrunner.vala
+++ b/valadate/testrunner.vala
@@ -49,7 +49,6 @@ public class Valadate.TestRunner : Object {
private static void printerr_func_stack_trace (string? text) {
if (text == null || str_equal (text, ""))
return;
-
stderr.printf (text);
/* Print a stack trace since we've hit some major issue */
@@ -71,7 +70,6 @@ public class Valadate.TestRunner : Object {
}
}
-
public void run_test(Test test, TestResult result) {
test.run(result);
}
@@ -129,19 +127,18 @@ public class Valadate.TestRunner : Object {
}
public static int main (string[] args) {
- var config = new TestConfig();
+ var bin = args[0];
+ var config = new TestConfig();
int result = config.parse(args);
+
if(result >= 0)
return result;
- var runner = new TestRunner(config.binary);
+ var runner = new TestRunner(bin);
var testresult = new TestResult(config);
-
testresult.run(runner);
return 0;
}
-
-
}
diff --git a/valadate/testsuite.vala b/valadate/testsuite.vala
index 0c47872..94c19d3 100644
--- a/valadate/testsuite.vala
+++ b/valadate/testsuite.vala
@@ -64,7 +64,6 @@ public class Valadate.TestSuite : Object, Test {
_tests.append(test);
}
-
public void run(TestResult result) {
_tests.foreach((t) => { t.run(result); });
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]