[vala/wip/valadate: 39/71] added TestFactory - new runs all tests



commit 25e27d1578da540844d27b83eb3c9f77f17eb6b6
Author: chebizarro gmail com <chebizarro gmail com>
Date:   Sat Jul 30 00:52:49 2016 -0700

    added TestFactory - new runs all tests

 tests/Makefile.am           |    1 +
 tests/valatests.vala        |  335 ++------------------------------------
 tests/valatestsfactory.vala |  372 +++++++++++++++++++++++++++++++++++++++++++
 valadate/testexplorer.vala  |    5 +-
 valadate/testresult.vala    |    2 +-
 5 files changed, 392 insertions(+), 323 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0bb1890..6ee25b2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -53,6 +53,7 @@ valactests@PACKAGE_SUFFIX@_VALAFLAGS = \
 
 valactests@PACKAGE_SUFFIX@_SOURCES = \
        valatests.vala \
+       valatestsfactory.vala \
        $(NULL)
 
 valactests@PACKAGE_SUFFIX@_LDADD = \
diff --git a/tests/valatests.vala b/tests/valatests.vala
index 021cfb2..da04512 100644
--- a/tests/valatests.vala
+++ b/tests/valatests.vala
@@ -59,96 +59,31 @@ public class Vala.Tests : Valadate.TestSuite {
 
        private class ValaTest : Valadate.TestCase {
 
-               private delegate void CommandCallback(bool err, string buffer);
-               
-               private static SubprocessLauncher launcher;
-               
-               private const string VALA_FLAGS =
-                       """--main main --save-temps --disable-warnings --pkg gio-2.0 
-                         -X -lm -X -g -X -O0 -X -pipe
-                         -X -Wno-discarded-qualifiers -X -Wno-incompatible-pointer-types
-                         -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""";
-               
-               private const string TESTCASE_FLAGS =
-                       "--pkg valadate -X -pie -X -fPIE";
-               
-               private const string GIRHEADER =
-                       """<?xml version="1.0"?>
-                       <repository version="1.2"
-                                               xmlns="http://www.gtk.org/introspection/core/1.0";
-                                               xmlns:c="http://www.gtk.org/introspection/c/1.0";
-                                               xmlns:glib="http://www.gtk.org/introspection/glib/1.0";>
-                               <include name="GLib" version="2.0"/>
-                               <include name="GObject" version="2.0"/>
-                               <c:include name="test.h"/>
-                               <namespace name="Test"
-                                                        version="1.2"
-                                                        c:identifier-prefixes="Test"
-                                                        c:symbol-prefixes="test">
-                                       %s
-                               </namespace>
-                               </repository>""";
-
                private const string BUGZILLA_URL = "http://bugzilla.gnome.org/";;
                
-               private static File testdir;
-               private static File tempdir;
-               private static File buildir;
-               private static File vapidir;
-               private static File valadatedir;
-               private static File valac;
-               private static File vapigen;
-               private static string vapidirs;
-
-               private File[] testfiles = {};
-
-               class construct {
-                       testdir = File.new_for_path(GLib.Environment.get_current_dir());
-                       tempdir = testdir.get_child(".tests");
-                       buildir = testdir.get_parent();
-                       vapidir = buildir.get_child("vapi");
-                       valadatedir = buildir.get_child("valadate");
-                       valac = buildir.get_child("compiler").get_child("valac");
-                       vapigen = buildir.get_child("vapigen").get_child("vapigen");
-                       vapidirs = "--vapidir %s".printf(vapidir.get_path());
-                       launcher = new SubprocessLauncher(GLib.SubprocessFlags.STDOUT_PIPE | 
GLib.SubprocessFlags.STDERR_MERGE);
-                       launcher.set_cwd(tempdir.get_path());
-               }
-
-               
-               public override void tear_down() {
-                       foreach(var file in testfiles)
-                               if(file.query_exists())
-                                       file.delete();
-               }
+               private TestsFactory factory = TestsFactory.get_instance();
                
                public ValaTest(File directory) throws Error {
                        this.name = directory.get_basename();
                        this.bug_base = BUGZILLA_URL;
-                       
+
                        string current_test = Valadate.get_current_test_path();
 
                        if(current_test != null) {
                                var basename = Path.get_basename(current_test);
                                if (directory.get_child(basename + ".vala").query_exists())
                                        load_test(directory.get_child(basename + ".vala"));
-                               else if (directory.get_child(basename + ".gs").query_exists())
-                                       load_test(directory.get_child(basename + ".gs"));
                                else if (directory.get_child(basename + ".test").query_exists())
                                        load_test(directory.get_child(basename + ".test"));
+                               else if (directory.get_child(basename + ".gs").query_exists())
+                                       load_test(directory.get_child(basename + ".gs"));
                        } else {
                                var enumerator = directory.enumerate_children (FileAttribute.STANDARD_NAME, 
0);
                                FileInfo file_info;
                                while ((file_info = enumerator.next_file ()) != null) {
                                        if (file_info.get_file_type() == GLib.FileType.DIRECTORY)
                                                continue;
-
-                                       string fname = file_info.get_name();
-
-                                       load_test(directory.get_child(fname));
+                                       load_test(directory.get_child(file_info.get_name()));
                                }
                        }
                }
@@ -157,256 +92,20 @@ public class Vala.Tests : Valadate.TestSuite {
                        string testname = testfile.get_basename().substring(
                                0,testfile.get_basename().last_index_of("."));
 
-                       string fname = testfile.get_basename();
-
-                       if(fname.has_suffix(".vala") || fname.has_suffix(".gs")) {
-                               
-                               add_test(testname,
-                                ()=> {
-                                       string binary = testfile.get_basename().substring(
-                                               0,testfile.get_basename().last_index_of("."));
-                                       string command = "%s %s %s -o %s %s".printf(
-                                               valac.get_path(), vapidirs, VALA_FLAGS,
-                                               binary, testfile.get_path());
-
-                                       try {
-                                               if(binary.has_prefix("bug")) {
-                                                       bug_base = BUGZILLA_URL;                              
                  
-                                                       bug(binary.substring(3));
-                                               }
-                                               run_command(command);
-                                               
-                                               testfiles += tempdir.get_child(binary);
-                                               testfiles += tempdir.get_child(binary + ".c");
-                                               
-                                               if(tempdir.get_child(binary).query_exists())
-                                                       run_command("./%s".printf(binary));
-                                               else
-                                                       fail("Binary not generated");
-                                       } catch (Error e) {
-                                               fail(e.message);
-                                               stdout.printf ("%s", e.message);
-                                       }});
-                       }
-                       
-                       if(fname.has_suffix(".test")) {
-                               add_test(testname,
-                                ()=> {
-                                       try {
-                                               if(fname.has_prefix("bug")) {
-                                                       bug(fname.substring(3,fname.length-8));
-                                               }
-                                               parse_test(testfile);
-                                       } catch (Error e) {
-                                               fail(e.message);
-                                               stdout.printf ("%s", e.message);
-                                       }});
-                       }
-               }
-
-               private void default_callback(bool err, string buffer) {
-                       if (err) {
-                               fail(buffer);
-                       } else {
-                               stdout.printf ("%s", buffer);
-                       }
+                       add_test(testname,
+                        ()=> {
+                               try {
+                                       if(testname.has_prefix("bug"))
+                                               bug(testname.substring(3));
+                                       var prog = factory.get_test_program(testfile);
+                                       prog.run();
+                               } catch (Error e) {
+                                       fail(e.message);
+                               }});
                }
 
-               private void run_command(string command, CommandCallback callback = default_callback) throws 
Error {
-                       string[] args;
-                       Shell.parse_argv(command, out args);
-                       string buffer = null;
-                       var process = launcher.spawnv(args);
-
-                       process.communicate_utf8(null, null, out buffer, null);
-
-                       try {
-                               if(process.wait_check())
-                                       callback(false, buffer);
-                       } catch (Error e) {
-                               callback(true, buffer);
-                       }
-               }
-
-               private void parse_test(File testfile) throws Error {
-                       
-                       var stream = new DataInputStream(testfile.read());
-                       string testname = testfile.get_basename().substring(
-                               0,testfile.get_basename().last_index_of("."));
-                       
-                       string line = stream.read_line(null);
-                       
-                       string packages = "";
-                       
-                       if (line.has_prefix("Packages:")) {
-                               packages = line.split(":")[1];
-                               packages = string.joinv(" --pkg ", packages.split(" "));
-                               line = stream.read_line(null);
-                       }
-                       switch (line) {
-                               
-                               case "D-Bus":
-                                       var clientfile = tempdir.get_child(testname + ".client.vala");
-                                       testfiles += clientfile;
-                                       var serverfile = tempdir.get_child(testname + ".server.vala");
-                                       testfiles += serverfile;
-                                       var client = clientfile.create(FileCreateFlags.REPLACE_DESTINATION);
-                                       var client_stream = new DataOutputStream (client);
-                                       var server = serverfile.create(FileCreateFlags.REPLACE_DESTINATION);
-                                       var server_stream = new DataOutputStream (server);
-                                       
-                                       do {} while ((line = stream.read_line (null)) != "Program: client");
-                                       
-                                       while ((line = stream.read_line (null)) != "Program: server") {
-                                               client_stream.put_string(line + "\n");
-                                       }
-
-                                       while ((line = stream.read_line (null)) != null) {
-                                               server_stream.put_string(line + "\n");
-                                       }
-
-                                       string command = "%s %s %s %s %s".printf(
-                                               valac.get_path(), vapidirs, packages, VALA_FLAGS,
-                                               clientfile.get_path());
-                                       
-                                       run_command(command);
-
-                                       command = "%s %s %s %s %s".printf(
-                                               valac.get_path(), vapidirs, packages, VALA_FLAGS,
-                                               serverfile.get_path());
-
-                                       run_command(command);
-
-                                       string binary = serverfile.get_basename().substring(
-                                               0,serverfile.get_basename().last_index_of("."));
-
-                                       testfiles += tempdir.get_child(binary);
-                                       testfiles += tempdir.get_child(binary + ".c");
-                                       testfiles += tempdir.get_child(testname + ".client");
-                                       testfiles += tempdir.get_child(testname + ".client.c");
-
-                                       command = "./" + binary;
-                                       
-                                       Bus.watch_name(
-                                               BusType.SESSION,
-                                               "org.example.Test",
-                                               GLib.BusNameWatcherFlags.NONE,
-                                               null,
-                                               (c,n) => {
-                                                       run_command(command);
-                                               });
-
-                                       break;
-
-                               case "GIR":
-
-                                       string gir = "";
-                                       string girdirs = "";
-                                       
-                                       foreach(string dir in GLib.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());
-                                       
-                                       string vapi = "/* %s.vapi generated by lt-vapigen, do not modify. 
*/\n\n".printf(testname);
-                                       vapi += "[CCode (cprefix = \"Test\", gir_namespace = \"Test\", 
gir_version = \"1.2\", lower_case_cprefix = \"test_\")]";
-                                       vapi += "\nnamespace Test {";
-
-                                       while ((line = stream.read_line (null)) != "Input:") { }
-
-                                       while ((line = stream.read_line (null)) != "Output:") {
-                                               gir += line + "\n";
-                                       }
-
-                                       stream.read_line (null);
-
-                                       while ((line = stream.read_line (null)) != null) {
-                                               if(line.length > 0)
-                                                       vapi += "\n\t" + line;
-                                       }
-
-                                       vapi += "\n}\n";
-
-                                       var girfile = tempdir.get_child(testname + ".gir");
-                                       testfiles += girfile;
-                                       var girstream = girfile.create(FileCreateFlags.REPLACE_DESTINATION);
-                                       girstream.write(GIRHEADER.printf(gir).data);
-
-                                       string command = "%s %s %s --library %s %s".printf(
-                                               vapigen.get_path(),
-                                               vapidirs,
-                                               girdirs,
-                                               testname,
-                                               girfile.get_path());
-                               
-                                       run_command(command);
-
-                                       uint8[] contents;
-                                       File file = tempdir.get_child(testname+".vapi");
-                                       testfiles += file;
-                                       file.load_contents (null, out contents, null);
-
-                                       if(strcmp(vapi, (string)contents) != 0)
-                                               fail((string)contents);
-                               
-                                       break;
-
-                               case "Invalid Code":
-                                       
-                                       var invalidfile = tempdir.get_child(testname + ".vala");
-                                       testfiles += invalidfile;
-                                       var invalid_stream = new DataOutputStream 
(invalidfile.create(FileCreateFlags.REPLACE_DESTINATION));
-
-                                       while ((line = stream.read_line (null)) != null) {
-                                               invalid_stream.put_string(line + "\n");
-                                       }
-
-                                       string command = "%s %s %s %s %s".printf(
-                                               valac.get_path(),
-                                               vapidirs, packages,
-                                               VALA_FLAGS,
-                                               invalidfile.get_path());
-
-                                       run_command(command, (e,b) => {
-                                               if (!e)
-                                                       fail(b);
-                                       });
-                                       break;
-
-                               case "TestCase":
-                                       
-                                       var testcasefile = tempdir.get_child(testname + ".vala");
-                                       var testcase = 
testcasefile.create(FileCreateFlags.REPLACE_DESTINATION);
-                                       var testcase_stream = new DataOutputStream (testcase);
-
-                                       testcase_stream.put_string("namespace Vala.Tests {\n");
-
-                                       while ((line = stream.read_line (null)) != null) {
-                                               testcase_stream.put_string(line + "\n");
-                                       }
-
-                                       testcase_stream.put_string("\n}");
-
-                                       string command = "%s %s %s %s %s".printf(
-                                               valac.get_path(),
-                                               vapidirs,
-                                               packages,
-                                               VALA_FLAGS,
-                                               testcasefile.get_path());
-                                       
-                                       run_command(command);
-
-                                       string binary = testcasefile.get_basename().substring(
-                                               0,testcasefile.get_basename().last_index_of("."));
-
-                                       command = "./" + binary;
-
-                                       run_command(command);
-
-                                       break;
-
-                               default :
-                                       break;
-                       }
+               public override void tear_down() {
+                       factory.cleanup();
                }
        }
 }
diff --git a/tests/valatestsfactory.vala b/tests/valatestsfactory.vala
new file mode 100644
index 0000000..90dea8b
--- /dev/null
+++ b/tests/valatestsfactory.vala
@@ -0,0 +1,372 @@
+/*
+ * ValaTestsFactory
+ * 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>
+ */
+
+internal class Vala.TestsFactory : Object {
+
+       internal static File currdir;
+       internal static File testdir;
+       internal static File buildir;
+       internal static File valac;
+
+       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");
+       }
+
+       private static TestsFactory instance;
+       public ValaCompiler compiler;
+
+       private Program[] programs = {};
+       private File[] tempfiles = {};
+       
+       public static TestsFactory get_instance() {
+               if (instance == null)
+                       instance = new TestsFactory();
+               return instance;
+       }
+
+       private TestsFactory() {
+               compiler = new ValaCompiler(valac);
+       }
+
+       public void cleanup() {
+               foreach (var file in tempfiles)
+                       if(file.query_exists())
+                               file.delete();
+
+               foreach (var prog in programs)
+                       prog.cleanup();
+       }
+
+       public Program get_test_program(File testfile) throws Error {
+               string testname = testfile.get_basename().substring(
+                       0,testfile.get_basename().last_index_of("."));
+               
+               Program program = null;
+               
+               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")) {
+                       var stream = new DataInputStream(testfile.read());
+                       
+                       string line = stream.read_line(null);
+                       
+                       string packages = "";
+                       
+                       if (line.has_prefix("Packages:")) {
+                               packages = line.split(":")[1];
+                               packages = string.joinv(" --pkg ", packages.split(" "));
+                               line = stream.read_line(null);
+                       }
+                       
+                       switch (line) {
+                               case "D-Bus":
+                                       program = new DBusTest(testname, packages, stream);
+                                       break;
+
+                               case "Invalid Code":
+                                       program = new InvalidCode(testname, packages, stream);
+                                       break;
+
+                               case "GIR":
+                                       program = new GIRTestProgram(testname, packages, stream);
+                                       break;
+                               
+                               default:
+                                       program = new TestProgram(testdir.get_child(testname));
+                                       break;
+                       }
+
+               }
+               programs += program;
+               return program;
+       }
+       
+
+       public abstract class Program : Object {
+
+               public delegate void CommandCallback(bool err, string buffer);
+
+               public static SubprocessLauncher launcher;
+
+               class construct {
+                       launcher = new SubprocessLauncher(GLib.SubprocessFlags.STDOUT_PIPE | 
GLib.SubprocessFlags.STDERR_MERGE);
+                       launcher.set_cwd(testdir.get_path());
+               }
+               
+               public File program {get; private set;}
+               
+               public CommandCallback callback {get;set;}
+               
+               private File[] files = {};
+               
+               public Program(File program) {
+                       this.program = program;
+                       files += program;
+                       callback = default_callback;
+               }
+       
+               public void add_file(File file) {
+                       files += file;
+               }
+       
+               private void default_callback(bool err, string buffer) {
+                       if (err)
+                               error(buffer);
+                       else
+                               stdout.printf ("%s", buffer);
+               }
+               
+               public virtual void run(string? command = null) throws Error {
+                       string[] args;
+                       Shell.parse_argv("%s %s".printf(program.get_path(), command ?? ""), out args);
+                       string buffer = null;
+                       var process = launcher.spawnv(args);
+                       process.communicate_utf8(null, null, out buffer, null);
+
+                       try {
+                               if(process.wait_check())
+                                       callback(false, buffer);
+                       } catch (Error e) {
+                               callback(true, buffer);
+                       }
+               }
+               
+               public virtual void cleanup() {
+                       foreach(File file in files)
+                               if(file.query_exists())
+                                       file.delete();
+               }
+       }
+       
+       public class TestProgram : Program {
+               public TestProgram(File program) {
+                       base(program);
+               }
+
+               public void add_file_from_stream(
+                       File file,
+                       DataInputStream stream,
+                       string? start,
+                       string? end,
+                       string? header = null,
+                       string? footer = null) throws Error {
+                       
+                               var newfile = file.create(FileCreateFlags.NONE);
+                               var outstream = new DataOutputStream (newfile);
+                               string line;
+                               
+                               if(header != null)
+                                       outstream.put_string(header + "\n");
+                               
+                               if(start != null)
+                                       do {} while ((line = stream.read_line (null)) != start);
+
+                               while ((line = stream.read_line (null)) != end)
+                                       outstream.put_string(line + "\n");
+
+                               if(footer != null)
+                                       outstream.put_string(footer);
+                       
+                               add_file(file);
+               }
+       }
+
+       public class DBusTest : TestProgram {
+               
+               private Program server;
+               private Program client;
+               
+               public DBusTest(string testname, string packages, DataInputStream stream) throws Error {
+                       base(testdir.get_child(testname + ".server"));
+                       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);
+               }
+               
+               public override void run(string? command = null) throws Error {
+                       Bus.watch_name(
+                               BusType.SESSION,
+                               "org.example.Test",
+                               GLib.BusNameWatcherFlags.NONE,
+                               null,
+                               (c,n) => {
+                                       this.server.run(command);
+                               });
+               }
+               
+               public override void cleanup() {
+                       server.cleanup();
+                       client.cleanup();
+                       base.cleanup();
+               }
+       }
+       
+       public class InvalidCode : TestProgram {
+               
+               private File source;
+               private ValaCompiler compiler = new ValaCompiler(valac);
+               private string packages;
+               private Program testprogam;
+               
+               public InvalidCode(string testname, string packages, DataInputStream stream) throws Error {
+                       base(testdir.get_child(testname));
+                       this.packages = packages;
+                       source = testdir.get_child(testname + ".vala");
+                       add_file_from_stream(source, stream, null, null);
+                       compiler.callback = new_callback;
+               }
+               
+               private void new_callback(bool err, string buffer) {
+                       if (!err)
+                               error(buffer);
+                       else
+                               stdout.printf ("%s", buffer);
+               }
+               
+               public override void run(string? command = null) throws Error {
+                       testprogam = compiler.compile(program, source, packages);
+               }
+               
+               public override void cleanup() {
+                       testprogam.cleanup();
+                       base.cleanup();
+               }
+               
+       }
+       
+       public class GIRTestProgram : TestProgram {
+               private const string GIRHEADER =
+               """<?xml version="1.0"?>
+               <repository version="1.2"
+                                       xmlns="http://www.gtk.org/introspection/core/1.0";
+                                       xmlns:c="http://www.gtk.org/introspection/c/1.0";
+                                       xmlns:glib="http://www.gtk.org/introspection/glib/1.0";>
+                       <include name="GLib" version="2.0"/>
+                       <include name="GObject" version="2.0"/>
+                       <c:include name="test.h"/>
+                       <namespace name="Test"
+                                                version="1.2"
+                                                c:identifier-prefixes="Test"
+                                                c:symbol-prefixes="test">""";
+
+               private const string GIRFOOTER = "\n</namespace>\n</repository>";
+
+               private const string VAPIHEADER = 
+               """/* %s.vapi generated by lt-vapigen, do not modify. */
+               [CCode (cprefix = "Test", gir_namespace = "Test", gir_version = "1.2", lower_case_cprefix = 
"test_")]
+               namespace Test {""";
+
+               private string testname;
+               
+               private File vapifile;
+               
+               public GIRTestProgram(string testname, string packages, DataInputStream stream) throws Error {
+                       base(testdir.get_child(testname + ".gir"));
+                       this.testname = testname;
+                       add_file_from_stream(program, stream, "Input:", "Output:", GIRHEADER, GIRFOOTER);
+                       vapifile = testdir.get_child(testname + ".vapi.ref");
+                       add_file_from_stream(vapifile, stream, null, null, VAPIHEADER.printf(testname), 
"\n}\n");
+               }
+               
+               public override void run(string? command = null) throws Error {
+                       var vgen = new VapiGen();
+                       var vapi = vgen.compile(testname, program);
+                       add_file(vapi);
+                       var diff = new Diff();
+                       diff.run("-Bw %s %s".printf(vapi.get_path(), vapifile.get_path()));
+               }
+               
+       }
+       
+       public class Diff : Program {
+
+               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(
+                               vapidir.get_path(),
+                               girdirs,
+                               testname,
+                               girfile.get_path());
+                       run(command);
+                       return testdir.get_child(testname + ".vapi");
+               }
+       }
+       
+       public class ValaCompiler : Program {
+               
+               private const string VALA_FLAGS =
+                       """--save-temps --disable-warnings --pkg gio-2.0 
+                         -X -lm -X -g -X -O0 -X -pipe
+                         -X -Wno-discarded-qualifiers -X -Wno-incompatible-pointer-types
+                         -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");
+               }
+
+               
+               public ValaCompiler(File compiler) {
+                       base(compiler);
+               }
+               
+               public Program compile(File binary, File sourcefile, string? parameters = null) throws Error {
+                       string command = "--vapidir %s %s %s -o %s %s".printf(
+                               vapidir.get_path(), VALA_FLAGS, parameters ?? "", binary.get_path(), 
sourcefile.get_path());
+                       run(command);
+                       var prog = new TestProgram(binary);
+                       prog.add_file(binary.get_parent().get_child(binary.get_basename() + ".c"));
+                       return prog;
+               }
+               
+       }
+}
diff --git a/valadate/testexplorer.vala b/valadate/testexplorer.vala
index 21d6d75..ac4dda3 100644
--- a/valadate/testexplorer.vala
+++ b/valadate/testexplorer.vala
@@ -72,8 +72,7 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor {
                foreach(var method in testclass.get_methods()) {
                        if( method.name.has_prefix("test_") &&
                                method.has_result != true &&
-                               method.get_parameters().size == 0
-                       ) {
+                               method.get_parameters().size == 0) {
 
                                if (config.runtest != null &&
                                        config.runtest != "/" + method.get_full_name().replace(".","/"))
@@ -112,6 +111,4 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor {
                }
                ns.accept_children(this);
        }
-       
-       
 }
diff --git a/valadate/testresult.vala b/valadate/testresult.vala
index 3e3b62f..73a6908 100644
--- a/valadate/testresult.vala
+++ b/valadate/testresult.vala
@@ -128,7 +128,7 @@ public class Valadate.TestResult : Object {
 
                if (config.runtest == null) {
                        loop = new MainLoop();
-                       var time = new TimeoutSource (5);
+                       var time = new TimeoutSource (30);
                        time.set_callback (() => {
                                report();
                                return true;


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