[vala/wip/valadate: 86/101] code clean up from ricotz
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/valadate: 86/101] code clean up from ricotz
- Date: Sat, 7 Oct 2017 10:57:12 +0000 (UTC)
commit 96162d601c32fb2df680e120d918e1f103bef80f
Author: Chris Daley <chebizarro gmail com>
Date: Fri Apr 28 12:38:22 2017 -0700
code clean up from ricotz
tests/valatests.vala | 50 ++++----
tests/valatestsfactory.vala | 64 +++++-----
valadate/assembly.vala | 54 ++++----
valadate/assemblyerror.vala | 2 +-
valadate/gnutestreportprinter.vala | 60 ++++----
valadate/taptestreportprinter.vala | 110 ++++++++--------
valadate/test.vala | 6 +-
valadate/testadapter.vala | 46 +++---
valadate/testassembly.vala | 78 ++++++------
valadate/testcase.vala | 60 ++++----
valadate/testconfig.vala | 2 +-
valadate/testerror.vala | 10 +-
valadate/testexplorer.vala | 6 +-
valadate/testgatherer.vala | 40 +++---
valadate/testmodule.vala | 32 +++---
valadate/testoptions.vala | 16 +-
valadate/testplan.vala | 260 ++++++++++++++++++------------------
valadate/testreport.vala | 240 +++++++++++++++++-----------------
valadate/testreportprinter.vala | 30 ++--
valadate/testresult.vala | 114 ++++++++--------
valadate/testrunner.vala | 140 ++++++++++----------
valadate/testsuite.vala | 38 +++---
valadate/xmlfile.vala | 66 +++++-----
valadate/xmltestreportprinter.vala | 46 +++---
24 files changed, 785 insertions(+), 785 deletions(-)
---
diff --git a/tests/valatests.vala b/tests/valatests.vala
index 9e4cbd2..7a90d65 100644
--- a/tests/valatests.vala
+++ b/tests/valatests.vala
@@ -1,31 +1,31 @@
/**
* Vala.Tests
- *
+ *
* Searchs all of the sub directories in the current directory for
* *.vala or *.test files, compiles and runs them.
- *
+ *
* If the test is a self contained application (has its own main entry
* point), it will compile and run it. The test is deemed succesful if
* it compiles and runs without error.
- *
+ *
* 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.
- *
+ *
* The tests can be run against the system compiler or the one in the
* source tree. This can be used to verify if a patch or other change
* to the compiler either fixes a bug or causes a regression (or both)
*/
public class Vala.Tests : Valadate.TestSuite {
-
+
private const string BUGZILLA_URL = "http://bugzilla.gnome.org/";
construct {
try {
- var testdir = File.new_for_path (GLib.Environment.get_variable("G_TEST_BUILDDIR"));
+ var testdir = File.new_for_path (GLib.Environment.get_variable ("G_TEST_BUILDDIR"));
var testpath = Valadate.TestOptions.get_current_test_path ();
-
+
if (testpath != null) {
var testpaths = testpath.split ("/");
if (testpaths.length < 4)
@@ -35,26 +35,26 @@ public class Vala.Tests : Valadate.TestSuite {
add_test (new ValaTest (runtest));
} else {
var tempdir = testdir.get_child (".tests");
- if (tempdir.query_exists()) {
+ if (tempdir.query_exists ()) {
var enumerator = tempdir.enumerate_children
(FileAttribute.STANDARD_NAME, 0);
FileInfo file_info;
while ((file_info = enumerator.next_file ()) != null) {
- var filename = file_info.get_name();
- if(filename == "." || filename == "..")
+ var filename = file_info.get_name ();
+ if (filename == "." || filename == "..")
continue;
- var tfile = tempdir.get_child(file_info.get_name());
- tfile.delete();
+ var tfile = tempdir.get_child (file_info.get_name ());
+ tfile.delete ();
}
} else {
- tempdir.make_directory();
+ tempdir.make_directory ();
}
var enumerator = testdir.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 &&
- !file_info.get_name().has_prefix("."))
- add_test (new ValaTest
(testdir.get_child(file_info.get_name())));
+ if (file_info.get_file_type () == GLib.FileType.DIRECTORY &&
+ !file_info.get_name ().has_prefix ("."))
+ add_test (new ValaTest (testdir.get_child (file_info.get_name
())));
}
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
@@ -64,13 +64,13 @@ public class Vala.Tests : Valadate.TestSuite {
private class ValaTest : Valadate.TestCase {
private TestsFactory factory = TestsFactory.get_instance ();
-
+
public ValaTest (File directory) throws Error {
this.name = directory.get_basename ();
this.label = directory.get_path ();
this.bug_base = BUGZILLA_URL;
- string current_test = Valadate.TestOptions.get_current_test_path();
+ string current_test = Valadate.TestOptions.get_current_test_path ();
if (current_test != null) {
var basename = Path.get_basename (current_test);
@@ -95,15 +95,15 @@ public class Vala.Tests : Valadate.TestSuite {
string basename = testfile.get_basename ();
string testname = basename.substring (0, basename.last_index_of ("."));
- var adapter = new Valadate.TestAdapter(testname, 1000);
- adapter.label = "/Vala/Tests/%s/%s".printf(
- Path.get_basename(testfile.get_parent().get_path()),
+ var adapter = new Valadate.TestAdapter (testname, 1000);
+ adapter.label = "/Vala/Tests/%s/%s".printf (
+ Path.get_basename (testfile.get_parent ().get_path ()),
testname);
-
- adapter.add_test_method(() => {
+
+ adapter.add_test_method (() => {
try {
if (testname.has_prefix ("bug"))
- bug (testname.substring(3));
+ bug (testname.substring (3));
var prog = factory.get_test_program (testfile);
prog.run ();
factory.cleanup ();
@@ -112,7 +112,7 @@ public class Vala.Tests : Valadate.TestSuite {
}
});
- add_test(adapter);
+ add_test (adapter);
}
}
}
diff --git a/tests/valatestsfactory.vala b/tests/valatestsfactory.vala
index 090cb91..3f42758 100644
--- a/tests/valatestsfactory.vala
+++ b/tests/valatestsfactory.vala
@@ -29,27 +29,27 @@ public class Vala.TestsFactory : Object {
static File vapidir;
class construct {
- currdir = File.new_for_path (GLib.Environment.get_variable("G_TEST_BUILDDIR"));
+ currdir = File.new_for_path (GLib.Environment.get_variable ("G_TEST_BUILDDIR"));
testdir = currdir.get_child (".tests");
buildir = currdir.get_parent ();
var usevalac = Environment.get_variable ("VALAC");
- if (usevalac != null && File.new_for_path(usevalac).query_exists())
- valac = File.new_for_path(usevalac);
+ 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");
+ valac = buildir.get_child ("compiler").get_child ("valac");
var usevapidir = Environment.get_variable ("VAPIDIR");
- if (usevapidir != null && File.new_for_path (usevapidir).query_exists())
+ 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;
- public static unowned TestsFactory get_instance() {
+ public static unowned TestsFactory get_instance () {
if (instance == null)
instance = new TestsFactory ();
return instance;
@@ -78,9 +78,9 @@ public class Vala.TestsFactory : Object {
public Program get_test_program (File testfile) throws Error {
string basename = testfile.get_basename ();
string testname = basename.substring (0, basename.last_index_of ("."));
-
+
Program program = null;
-
+
if (basename.has_suffix (".vala") || basename.has_suffix (".gs")) {
program = compiler.compile (testdir.get_child (testname), testfile, "--main main");
} else if (basename.has_suffix (".test")) {
@@ -165,7 +165,7 @@ public class Vala.TestsFactory : Object {
}
}
- public virtual void cleanup() throws Error {
+ public virtual void cleanup () throws Error {
foreach (unowned File file in files)
if (file.query_exists ())
file.delete ();
@@ -210,7 +210,7 @@ public class Vala.TestsFactory : Object {
public DBusTest (string testname, string packages, DataInputStream stream) throws Error {
Object (program : testdir.get_child (testname + ".server"));
- var factory = TestsFactory.get_instance();
+ 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");
@@ -242,7 +242,7 @@ public class Vala.TestsFactory : Object {
public InvalidCode (string testname, string packages, DataInputStream stream) throws Error {
Object (program : testdir.get_child (testname));
this.packages = packages;
- source = testdir.get_child(testname + ".vala");
+ source = testdir.get_child (testname + ".vala");
add_file_from_stream (source, stream, null, null);
compiler = new ValaCompiler (valac);
compiler.callback = new_callback;
@@ -259,9 +259,9 @@ public class Vala.TestsFactory : Object {
testprogam = compiler.compile (program, source, packages);
}
- public override void cleanup() throws Error {
- testprogam.cleanup();
- base.cleanup();
+ public override void cleanup () throws Error {
+ testprogam.cleanup ();
+ base.cleanup ();
}
}
@@ -282,7 +282,7 @@ public class Vala.TestsFactory : Object {
private const string GIRFOOTER = "\n</namespace>\n</repository>";
- private const string VAPIHEADER =
+ 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 {""";
@@ -291,11 +291,11 @@ public class Vala.TestsFactory : Object {
private File vapifile;
public GIRTestProgram (string testname, string packages, DataInputStream stream) throws Error
{
- Object (program : testdir.get_child(testname + ".gir"));
+ Object (program : 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");
+ add_file_from_stream (vapifile, stream, null, null, VAPIHEADER.printf (testname),
"\n}\n");
}
public override void run (string? command = null) throws Error {
@@ -308,8 +308,8 @@ public class Vala.TestsFactory : Object {
}
public class Diff : Program {
- public Diff() {
- Object (program : File.new_for_path(Environment.find_program_in_path ("diff")));
+ public Diff () {
+ Object (program : File.new_for_path (Environment.find_program_in_path ("diff")));
}
}
@@ -351,34 +351,34 @@ public class Vala.TestsFactory : Object {
string command = "--vapidir %s %s %s %s -o %s %s".printf (
vapidir.get_path (),
VALA_FLAGS,
- get_flags(),
+ get_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"));
+ prog.add_file (binary.get_parent ().get_child (binary.get_basename () + ".c"));
return prog;
}
-
- private string get_flags() throws Error {
-
+
+ private string get_flags () throws Error {
+
string result = "";
string[] flags = {"CFLAGS", "CPPFLAGS", "LDFLAGS"};
-
- foreach(string key in flags) {
+
+ foreach (string key in flags) {
var val = Environment.get_variable (key);
- if(val == null || val.length == 0)
+ if (val == null || val.length == 0)
continue;
string[] args;
- Shell.parse_argv(val, out args);
+ Shell.parse_argv (val, out args);
foreach (var item in args)
- result += "-X %s ".printf(item);
+ result += "-X %s ".printf (item);
}
-
+
return result;
}
-
+
}
}
diff --git a/valadate/assembly.vala b/valadate/assembly.vala
index 8536460..aa48c7c 100644
--- a/valadate/assembly.vala
+++ b/valadate/assembly.vala
@@ -15,27 +15,27 @@
* 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 abstract class Valadate.Assembly {
protected static SubprocessLauncher launcher;
-
- private static void init_launcher() {
+
+ private static void init_launcher () {
if (launcher == null) {
- launcher = new SubprocessLauncher(
+ launcher = new SubprocessLauncher (
GLib.SubprocessFlags.STDIN_PIPE |
GLib.SubprocessFlags.STDOUT_PIPE |
GLib.SubprocessFlags.STDERR_PIPE);
- launcher.setenv("G_MESSAGES_DEBUG","all",true);
- launcher.setenv("G_DEBUG","fatal-criticals fatal-warnings gc-friendly",true);
- launcher.setenv("G_SLICE","always-malloc debug-blocks",true);
+ launcher.setenv ("G_MESSAGES_DEBUG","all",true);
+ launcher.setenv ("G_DEBUG","fatal-criticals fatal-warnings gc-friendly",true);
+ launcher.setenv ("G_SLICE","always-malloc debug-blocks",true);
}
}
-
+
public File binary {get;set;}
public InputStream stderr {get;set;}
public OutputStream stdin {get;set;}
@@ -43,31 +43,31 @@ public abstract class Valadate.Assembly {
protected Subprocess process;
- public Assembly(File binary) throws Error {
- init_launcher();
- if(!binary.query_exists())
- throw new FileError.NOENT("The file %s does not exist", binary.get_path());
- if(!GLib.FileUtils.test(binary.get_path(), FileTest.IS_EXECUTABLE))
- throw new FileError.PERM("The file %s is not executable", binary.get_path());
+ public Assembly (File binary) throws Error {
+ init_launcher ();
+ if (!binary.query_exists ())
+ throw new FileError.NOENT ("The file %s does not exist", binary.get_path ());
+ if (!GLib.FileUtils.test (binary.get_path (), FileTest.IS_EXECUTABLE))
+ throw new FileError.PERM ("The file %s is not executable", binary.get_path ());
this.binary = binary;
}
- public abstract Assembly clone() throws Error;
+ public abstract Assembly clone () throws Error;
- public virtual Assembly run(string? command = null, Cancellable? cancellable = null) throws Error {
+ public virtual Assembly run (string? command = null, Cancellable? cancellable = null) throws Error {
string[] args;
- Shell.parse_argv("%s %s".printf(binary.get_path(), command ?? ""), out args);
- process = launcher.spawnv(args);
- stdout = new DataInputStream (process.get_stdout_pipe());
- stderr = new DataInputStream (process.get_stderr_pipe());
- stdin = new DataOutputStream (process.get_stdin_pipe());
- process.wait_check(cancellable);
- cancellable.set_error_if_cancelled();
+ Shell.parse_argv ("%s %s".printf (binary.get_path (), command ?? ""), out args);
+ process = launcher.spawnv (args);
+ stdout = new DataInputStream (process.get_stdout_pipe ());
+ stderr = new DataInputStream (process.get_stderr_pipe ());
+ stdin = new DataOutputStream (process.get_stdin_pipe ());
+ process.wait_check (cancellable);
+ cancellable.set_error_if_cancelled ();
return this;
}
- public virtual void quit() {
- if(process != null)
- process.force_exit();
+ public virtual void quit () {
+ if (process != null)
+ process.force_exit ();
}
}
diff --git a/valadate/assemblyerror.vala b/valadate/assemblyerror.vala
index aa1b57e..4c7f2f2 100644
--- a/valadate/assemblyerror.vala
+++ b/valadate/assemblyerror.vala
@@ -15,7 +15,7 @@
* 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>
*/
diff --git a/valadate/gnutestreportprinter.vala b/valadate/gnutestreportprinter.vala
index 87ce5e5..5de3199 100644
--- a/valadate/gnutestreportprinter.vala
+++ b/valadate/gnutestreportprinter.vala
@@ -15,61 +15,61 @@
* 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.GnuTestReportPrinter : TestReportPrinter {
-
+
private const string TAP_VERSION = "13";
-
- private List<TestCase> testcases = new List<TestCase>();
-
- public GnuTestReportPrinter(TestConfig config) throws Error {
- base(config);
+
+ private List<TestCase> testcases = new List<TestCase> ();
+
+ public GnuTestReportPrinter (TestConfig config) throws Error {
+ base (config);
}
-
- public override void print(TestReport report) {
- if(report.test is TestSuite) {
- testcases = new List<TestCase>();
- } else if(report.test is TestCase) {
- testcases.append(report.test as TestCase);
- } else if(report.test is TestAdapter) {
+ public override void print (TestReport report) {
+
+ if (report.test is TestSuite) {
+ testcases = new List<TestCase> ();
+ } else if (report.test is TestCase) {
+ testcases.append (report.test as TestCase);
+ } else if (report.test is TestAdapter) {
var test = report.test as TestAdapter;
- var idx = testcases.index(test.parent as TestCase);
+ var idx = testcases.index (test.parent as TestCase);
int index = 1;
-
- if(idx > 0)
- for(int i=0; i<idx;i++)
- index += testcases.nth_data(i).count;
-
- for(int i=0;i<test.parent.count; i++) {
- if(test.parent[i] == test) {
+
+ if (idx > 0)
+ for (int i=0; i<idx;i++)
+ index += testcases.nth_data (i).count;
+
+ for (int i=0;i<test.parent.count; i++) {
+ if (test.parent[i] == test) {
index += i;
}
}
- switch(report.test.status) {
+ switch (report.test.status) {
case TestStatus.PASSED:
- stdout.printf("PASS: %s %d - %s\n", test.parent.name, index,
test.name);
+ stdout.printf ("PASS: %s %d - %s\n", test.parent.name, index,
test.name);
break;
case TestStatus.SKIPPED:
- stdout.printf("SKIP: %s %d - %s # SKIP %s \n",
+ stdout.printf ("SKIP: %s %d - %s # SKIP %s \n",
test.parent.name, index, test.label, test.status_message ??
"");
break;
case TestStatus.TODO:
- var errs = report.xml.eval("//failure | //error");
- if(errs.size > 0)
- stdout.printf("XFAIL: %s %d - %s # TODO %s \n",
+ var errs = report.xml.eval ("//failure | //error");
+ if (errs.size > 0)
+ stdout.printf ("XFAIL: %s %d - %s # TODO %s \n",
test.parent.name, index, test.label,
test.status_message ?? "");
else
- stdout.printf("PASS: %s %d - %s # TODO %s \n",
+ stdout.printf ("PASS: %s %d - %s # TODO %s \n",
test.parent.name, index, test.label,
test.status_message ?? "");
break;
case TestStatus.FAILED:
case TestStatus.ERROR:
- stdout.printf("FAIL: %s %d - %s\n", test.parent.name, index,
test.label);
+ stdout.printf ("FAIL: %s %d - %s\n", test.parent.name, index,
test.label);
break;
default:
break;
diff --git a/valadate/taptestreportprinter.vala b/valadate/taptestreportprinter.vala
index c1f9d77..92fb427 100644
--- a/valadate/taptestreportprinter.vala
+++ b/valadate/taptestreportprinter.vala
@@ -15,94 +15,94 @@
* 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.TapTestReportPrinter : TestReportPrinter {
-
+
private const string TAP_VERSION = "13";
-
- private List<TestCase> testcases = new List<TestCase>();
-
- public TapTestReportPrinter(TestConfig config) throws Error {
- base(config);
- if(!config.list_only) {
- stdout.printf("TAP version %s\n", TAP_VERSION);
- stdout.printf("# random seed: %s\n", config.seed);
+
+ private List<TestCase> testcases = new List<TestCase> ();
+
+ public TapTestReportPrinter (TestConfig config) throws Error {
+ base (config);
+ if (!config.list_only) {
+ stdout.printf ("TAP version %s\n", TAP_VERSION);
+ stdout.printf ("# random seed: %s\n", config.seed);
}
}
-
- public override void print(TestReport report) {
- if(report.test is TestSuite && report.test.parent.name == "/") {
- stdout.printf("1..%d\n", report.test.count);
-
- var props = report.xml.eval("//properties/property");
- stdout.puts("# Environment\n");
- foreach(Xml.Node* prop in props) {
- stdout.printf("# %s : %s\n",
- prop->get_prop("name"), prop->get_prop("value"));
+ public override void print (TestReport report) {
+
+ if (report.test is TestSuite && report.test.parent.name == "/") {
+ stdout.printf ("1..%d\n", report.test.count);
+
+ var props = report.xml.eval ("//properties/property");
+ stdout.puts ("# Environment\n");
+ foreach (Xml.Node* prop in props) {
+ stdout.printf ("# %s : %s\n",
+ prop->get_prop ("name"), prop->get_prop ("value"));
}
- } else if(report.test is TestCase) {
- testcases.append(report.test as TestCase);
- stdout.printf("# Start of %s tests\n", report.test.label);
+ } else if (report.test is TestCase) {
+ testcases.append (report.test as TestCase);
+ stdout.printf ("# Start of %s tests\n", report.test.label);
- } else if(report.test is TestAdapter) {
+ } else if (report.test is TestAdapter) {
var test = report.test as TestAdapter;
- var idx = testcases.index(test.parent as TestCase);
+ var idx = testcases.index (test.parent as TestCase);
int index = 1;
bool lasttest = false;
-
- if(idx > 0)
- for(int i=0; i<idx;i++)
- index += testcases.nth_data(i).count;
-
- for(int i=0;i<test.parent.count; i++) {
- if(test.parent[i] == test) {
+
+ if (idx > 0)
+ for (int i=0; i<idx;i++)
+ index += testcases.nth_data (i).count;
+
+ for (int i=0;i<test.parent.count; i++) {
+ if (test.parent[i] == test) {
index += i;
lasttest = (i == test.parent.count-1);
}
}
- switch(report.test.status) {
+ switch (report.test.status) {
case TestStatus.PASSED:
- stdout.printf("ok %d - %s\n", index, test.label);
+ stdout.printf ("ok %d - %s\n", index, test.label);
break;
case TestStatus.SKIPPED:
- stdout.printf("ok %d - %s # SKIP %s \n", index, test.label,
test.status_message ?? "Skipping");
+ stdout.printf ("ok %d - %s # SKIP %s \n", index, test.label,
test.status_message ?? "Skipping");
break;
case TestStatus.TODO:
- var errs = report.xml.eval("//failure | //error");
- if(errs.size > 0)
- stdout.printf("not ok %d - %s # TODO %s \n", index,
test.label, test.status_message ?? "Todo");
+ var errs = report.xml.eval ("//failure | //error");
+ if (errs.size > 0)
+ stdout.printf ("not ok %d - %s # TODO %s \n", index,
test.label, test.status_message ?? "Todo");
else
- stdout.printf("ok %d - %s # TODO %s \n", index, test.label,
test.status_message ?? "Todo");
+ stdout.printf ("ok %d - %s # TODO %s \n", index, test.label,
test.status_message ?? "Todo");
break;
case TestStatus.FAILED:
case TestStatus.ERROR:
- stdout.printf("not ok %d - %s\n", index, test.label);
+ stdout.printf ("not ok %d - %s\n", index, test.label);
break;
default:
- stdout.printf("Bail out! %s\n", "There was an unexpected error");
+ stdout.printf ("Bail out! %s\n", "There was an unexpected error");
break;
}
- stdout.puts(" ---\n");
- stdout.printf(" duration_ms: %.4f\n", test.time);
- var messages = report.xml.eval("//failure | //error | //info");
- foreach(Xml.Node* mess in messages) {
- stdout.printf(" message: >\n %s\n", mess->get_prop("message"));
- stdout.printf(" severity: %s\n", mess->name);
+ stdout.puts (" ---\n");
+ stdout.printf (" duration_ms: %.4f\n", test.time);
+ var messages = report.xml.eval ("//failure | //error | //info");
+ foreach (Xml.Node* mess in messages) {
+ stdout.printf (" message: >\n %s\n", mess->get_prop ("message"));
+ stdout.printf (" severity: %s\n", mess->name);
}
- stdout.puts(" ...\n");
- messages = report.xml.eval("//system-out | //system-err");
- foreach(Xml.Node* mess in messages)
- stdout.printf("# %s\n", string.joinv("\n# ",
mess->get_content().split("\n")));
- if(lasttest)
- stdout.printf("# End of %s tests\n", test.parent.label);
- stdout.flush();
+ stdout.puts (" ...\n");
+ messages = report.xml.eval ("//system-out | //system-err");
+ foreach (Xml.Node* mess in messages)
+ stdout.printf ("# %s\n", string.joinv ("\n# ", mess->get_content ().split
("\n")));
+ if (lasttest)
+ stdout.printf ("# End of %s tests\n", test.parent.label);
+ stdout.flush ();
}
}
}
diff --git a/valadate/test.vala b/valadate/test.vala
index 0d853eb..f6350d6 100644
--- a/valadate/test.vala
+++ b/valadate/test.vala
@@ -26,7 +26,7 @@
*/
public interface Valadate.Test : Object {
/**
- * Runs the Tests and collects the results in a TestResult
+ * Runs the Tests and collects the results in a TestResult
*
* @param result the TestResult object used to store the results of the Test
*/
@@ -59,7 +59,7 @@ public interface Valadate.Test : Object {
public abstract Test? parent {get;set;}
- public abstract Test get(int index);
+ public abstract Test get (int index);
- public abstract void set(int index, Test test);
+ public abstract void set (int index, Test test);
}
diff --git a/valadate/testadapter.vala b/valadate/testadapter.vala
index 9308308..e3849f4 100644
--- a/valadate/testadapter.vala
+++ b/valadate/testadapter.vala
@@ -25,7 +25,7 @@ public class Valadate.TestAdapter : Object, Test {
public string name {get;set;}
public string label {get;set;}
public double time {get;set;}
-
+
public int timeout {get;set;}
public TestStatus status {get;set;default=TestStatus.NOT_RUN;}
@@ -46,18 +46,18 @@ public class Valadate.TestAdapter : Object, Test {
private TestCase.TestMethod test;
public Test? parent {get;set;}
- public new Test get(int index) {
+ public new Test get (int index) {
return this;
}
- public TestAdapter(string name, int timeout) {
+ public TestAdapter (string name, int timeout) {
this.name = name;
this.timeout = timeout;
}
- public void add_test(owned TestPlan.TestMethod testmethod) {
+ public void add_test (owned TestPlan.TestMethod testmethod) {
this.test = () => {
- testmethod(parent as TestCase);
+ testmethod (parent as TestCase);
};
}
@@ -68,40 +68,40 @@ public class Valadate.TestAdapter : Object, Test {
var p = parent as TestCase;
this.test = () => {
AsyncResult? result = null;
- var loop = new MainLoop();
- var thread = new Thread<void*>.try(name, () => {
- async_begin(p, (o, r) => { result = r; loop.quit();});
+ var loop = new MainLoop ();
+ var thread = new Thread<void*>.try (name, () => {
+ async_begin (p, (o, r) => { result = r; loop.quit ();});
return null;
});
- Timeout.add(timeout, () => {
- loop.quit();
+ Timeout.add (timeout, () => {
+ loop.quit ();
return false;
},
Priority.HIGH);
- loop.run();
- if(result == null)
- throw new IOError.TIMED_OUT(
+ loop.run ();
+ if (result == null)
+ throw new IOError.TIMED_OUT (
"The test timed out after %d milliseconds",timeout);
- async_finish(p, result);
+ async_finish (p, result);
};
}
- public void add_test_method(owned TestCase.TestMethod testmethod) {
+ public void add_test_method (owned TestCase.TestMethod testmethod) {
this.test = (owned)testmethod;
}
- public void run(TestResult result) {
- if(status == TestStatus.SKIPPED)
+ public void run (TestResult result) {
+ if (status == TestStatus.SKIPPED)
return;
var p = parent as TestCase;
- result.add_test(this);
- p.set_up();
+ result.add_test (this);
+ p.set_up ();
try {
- test();
+ test ();
} catch (Error e) {
- result.add_failure(this, e.message);
+ result.add_failure (this, e.message);
}
- p.tear_down();
- result.add_success(this);
+ p.tear_down ();
+ result.add_success (this);
}
}
diff --git a/valadate/testassembly.vala b/valadate/testassembly.vala
index bc8e5aa..1819987 100644
--- a/valadate/testassembly.vala
+++ b/valadate/testassembly.vala
@@ -15,7 +15,7 @@
* 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>
*/
@@ -27,67 +27,67 @@ public class Valadate.TestAssembly : TestModule {
public TestOptions options {get;set;}
- public TestAssembly(string[] args) throws Error {
- base(File.new_for_path(args[0]));
- options = new TestOptions(args);
- setup_dirs();
+ public TestAssembly (string[] args) throws Error {
+ base (File.new_for_path (args[0]));
+ options = new TestOptions (args);
+ setup_dirs ();
}
-
- private TestAssembly.copy(TestAssembly other) throws Error {
- base(other.binary);
+
+ private TestAssembly.copy (TestAssembly other) throws Error {
+ base (other.binary);
options = other.options;
}
-
- private void setup_dirs() throws Error {
- var buildstr = Environment.get_variable("G_TEST_BUILDDIR");
-
- if(buildstr == null) {
- builddir = binary.get_parent();
- if(builddir.get_basename() == ".libs")
- builddir = builddir.get_parent();
+
+ private void setup_dirs () throws Error {
+ var buildstr = Environment.get_variable ("G_TEST_BUILDDIR");
+
+ if (buildstr == null) {
+ builddir = binary.get_parent ();
+ if (builddir.get_basename () == ".libs")
+ builddir = builddir.get_parent ();
} else {
- builddir = File.new_for_path(buildstr);
+ builddir = File.new_for_path (buildstr);
}
- var srcstr = Environment.get_variable("G_TEST_SRCDIR");
-
- if(srcstr == null) {
+ var srcstr = Environment.get_variable ("G_TEST_SRCDIR");
+
+ if (srcstr == null) {
// we're running outside the test harness
// check for buildir!=srcdir
// this currently on checks for autotools
- if(!builddir.get_child("Makefile.in").query_exists()) {
+ if (!builddir.get_child ("Makefile.in").query_exists ()) {
// check for Makefile in builddir and extract VPATH
- var makefile = builddir.get_child("Makefile");
- if(makefile.query_exists()) {
- var reader = new DataInputStream(makefile.read());
- var line = reader.read_line();
- while(line!= null) {
- if(line.has_prefix("VPATH = ")) {
- srcstr = Path.build_path(Path.DIR_SEPARATOR_S,
builddir.get_path(), line.split(" = ")[1]);
+ var makefile = builddir.get_child ("Makefile");
+ if (makefile.query_exists ()) {
+ var reader = new DataInputStream (makefile.read ());
+ var line = reader.read_line ();
+ while (line!= null) {
+ if (line.has_prefix ("VPATH = ")) {
+ srcstr = Path.build_path (Path.DIR_SEPARATOR_S,
builddir.get_path (), line.split (" = ")[1]);
break;
}
- line = reader.read_line();
+ line = reader.read_line ();
}
}
}
}
-
- if(srcstr == null)
+
+ if (srcstr == null)
srcdir = builddir;
else
- srcdir = File.new_for_path(srcstr);
+ srcdir = File.new_for_path (srcstr);
- var mesondir = srcdir.get_child(Path.get_basename(binary.get_path()) + "@exe");
+ var mesondir = srcdir.get_child (Path.get_basename (binary.get_path ()) + "@exe");
- if(mesondir.query_exists())
+ if (mesondir.query_exists ())
srcdir = mesondir;
-
- Environment.set_variable("G_TEST_BUILDDIR", builddir.get_path(), true);
- Environment.set_variable("G_TEST_SRCDIR", srcdir.get_path(), true);
+
+ Environment.set_variable ("G_TEST_BUILDDIR", builddir.get_path (), true);
+ Environment.set_variable ("G_TEST_SRCDIR", srcdir.get_path (), true);
}
- public override Assembly clone() throws Error {
- return new TestAssembly.copy(this);
+ public override Assembly clone () throws Error {
+ return new TestAssembly.copy (this);
}
}
diff --git a/valadate/testcase.vala b/valadate/testcase.vala
index 717d879..713bec6 100644
--- a/valadate/testcase.vala
+++ b/valadate/testcase.vala
@@ -1,4 +1,4 @@
-/*
+/*
* Valadate - Unit testing library for GObject-based libraries.
*
* testcase.vala
@@ -44,7 +44,7 @@ public abstract class Valadate.TestCase : Object, Test {
public int count {
get {
int testcount = 0;
- _tests.foreach((t) => {
+ _tests.foreach ((t) => {
testcount += t.count;
});
return testcount;
@@ -54,7 +54,7 @@ public abstract class Valadate.TestCase : Object, Test {
public int size {
get {
int testcount = 0;
- _tests.foreach((t) => {
+ _tests.foreach ((t) => {
testcount += t.count;
});
return testcount;
@@ -68,61 +68,61 @@ public abstract class Valadate.TestCase : Object, Test {
public double time {get;set;}
public string bug_base {get;set;}
-
- private List<Test> _tests = new List<Test>();
+
+ private List<Test> _tests = new List<Test> ();
private Test current_test;
private TestResult current_result;
- public new Test get(int index) {
- return _tests.nth_data((uint)index);
+ public new Test get (int index) {
+ return _tests.nth_data ((uint)index);
}
- public new void set(int index, Test test) {
+ public new void set (int index, Test test) {
test.parent = this;
- _tests.insert_before(_tests.nth(index), test);
- var t = _tests.nth_data((uint)index++);
- _tests.remove(t);
+ _tests.insert_before (_tests.nth (index), test);
+ var t = _tests.nth_data ((uint)index++);
+ _tests.remove (t);
}
- public void add_test(Test test) {
+ public void add_test (Test test) {
test.parent = this;
- _tests.append(test);
+ _tests.append (test);
}
- public void add_test_method(string testname, owned TestMethod test, int timeout, string? label =
null) {
+ public void add_test_method (string testname, owned TestMethod test, int timeout, string? label =
null) {
var adapter = new TestAdapter (testname, timeout);
- adapter.add_test_method((owned)test);
+ adapter.add_test_method ((owned)test);
adapter.label = label;
adapter.parent = this;
- _tests.append(adapter);
+ _tests.append (adapter);
}
-
- public virtual void run(TestResult result) {
- if(status != TestStatus.NOT_RUN)
+
+ public virtual void run (TestResult result) {
+ if (status != TestStatus.NOT_RUN)
return;
current_result = result;
- _tests.foreach((t) => {
+ _tests.foreach ((t) => {
current_test = t;
- t.run(result);
+ t.run (result);
});
}
- public void bug(string reference)
- requires(bug_base != null)
+ public void bug (string reference)
+ requires (bug_base != null)
{
- info("Bug Reference: %s%s",bug_base, reference);
+ info ("Bug Reference: %s%s",bug_base, reference);
}
- public void skip(string message) {
- current_result.add_skip(current_test, message);
+ public void skip (string message) {
+ current_result.add_skip (current_test, message);
}
- public void fail(string? message = null) {
- current_result.add_failure(current_test, message);
+ public void fail (string? message = null) {
+ current_result.add_failure (current_test, message);
}
- public virtual void set_up() {}
+ public virtual void set_up () {}
- public virtual void tear_down() {}
+ public virtual void tear_down () {}
}
diff --git a/valadate/testconfig.vala b/valadate/testconfig.vala
index a7405db..2064191 100644
--- a/valadate/testconfig.vala
+++ b/valadate/testconfig.vala
@@ -91,7 +91,7 @@ public class Valadate.TestConfig {
}
}
- public TestConfig(TestOptions options) {
+ public TestConfig (TestOptions options) {
this.options = options;
}
}
diff --git a/valadate/testerror.vala b/valadate/testerror.vala
index b173f71..8262442 100644
--- a/valadate/testerror.vala
+++ b/valadate/testerror.vala
@@ -1,23 +1,23 @@
/*
* Valadate - Unit testing library for GObject-based libraries.
* Copyright 2017 Chris Daley <bizarro@localhost.localdomain>
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program 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 General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
- *
- *
+ *
+ *
*/
public errordomain Valadate.TestError {
diff --git a/valadate/testexplorer.vala b/valadate/testexplorer.vala
index df7a0b8..e2f81d9 100644
--- a/valadate/testexplorer.vala
+++ b/valadate/testexplorer.vala
@@ -45,7 +45,7 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor {
testplan = testplan.substring (3);
string testplanfile = testdir + GLib.Path.DIR_SEPARATOR_S + testplan + ".vapi";
-
+
if (!FileUtils.test (testplanfile, FileTest.EXISTS))
throw new TestConfigError.TESTPLAN ("Test Plan %s Not Found!", testplanfile);
@@ -65,7 +65,7 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor {
parser.parse (context);
context.accept (this);
}
-
+
private void setup_context () {
context = new Vala.CodeContext ();
Vala.CodeContext.push (context);
@@ -105,7 +105,7 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor {
unowned Constructor meth = get_constructor (cl);
var current_test = meth () as TestCase;
current_test.name = cl.name;
-
+
foreach (var method in cl.get_methods ()) {
if (method.name.has_prefix ("test_") &&
method.has_result != true &&
diff --git a/valadate/testgatherer.vala b/valadate/testgatherer.vala
index a9049f3..e61a817 100644
--- a/valadate/testgatherer.vala
+++ b/valadate/testgatherer.vala
@@ -19,39 +19,39 @@
* Authors:
* Chris Daley <chebizarro gmail com>
*/
-
+
public class Valadate.TestGatherer : Vala.CodeVisitor {
-
- public HashTable<Type, Vala.Class> classes =
- new HashTable<Type, Vala.Class>(direct_hash, direct_equal);
-
+
+ public HashTable<Type, Vala.Class> classes =
+ new HashTable<Type, Vala.Class> (direct_hash, direct_equal);
+
private TestAssembly assembly;
- public TestGatherer(TestAssembly assembly) {
+ public TestGatherer (TestAssembly assembly) {
this.assembly = assembly;
}
- public override void visit_namespace(Vala.Namespace ns) {
- ns.accept_children(this);
+ public override void visit_namespace (Vala.Namespace ns) {
+ ns.accept_children (this);
}
-
- public override void visit_class(Vala.Class cls) {
+
+ public override void visit_class (Vala.Class cls) {
try {
- var classtype = find_type(cls);
- if (classtype.is_a(typeof(TestCase)) || classtype.is_a(typeof(TestSuite)))
- classes.insert(classtype, cls);
+ var classtype = find_type (cls);
+ if (classtype.is_a (typeof (TestCase)) || classtype.is_a (typeof (TestSuite)))
+ classes.insert (classtype, cls);
} catch (Error e) {
- warning(e.message);
+ warning (e.message);
}
- cls.accept_children(this);
+ cls.accept_children (this);
}
-
- private Type find_type(Vala.Class cls) throws Error {
+
+ private Type find_type (Vala.Class cls) throws Error {
var attr = new Vala.CCodeAttribute (cls);
unowned TestPlan.GetType node_get_type =
- (TestPlan.GetType)assembly.get_method(
- "%sget_type".printf(attr.lower_case_prefix));
- var ctype = node_get_type();
+ (TestPlan.GetType)assembly.get_method (
+ "%sget_type".printf (attr.lower_case_prefix));
+ var ctype = node_get_type ();
return ctype;
}
}
diff --git a/valadate/testmodule.vala b/valadate/testmodule.vala
index c06ae65..a0da7bf 100644
--- a/valadate/testmodule.vala
+++ b/valadate/testmodule.vala
@@ -24,32 +24,32 @@
* Represents a loadable module containing {@link Valadate.Test}s
*/
public class Valadate.TestModule : Assembly {
-
+
private GLib.Module module;
-
- public TestModule(File binary) throws Error {
- base(binary);
+
+ public TestModule (File binary) throws Error {
+ base (binary);
}
- private void load_module() throws AssemblyError {
- module = GLib.Module.open (binary.get_path(), ModuleFlags.BIND_LAZY);
+ private void load_module () throws AssemblyError {
+ module = GLib.Module.open (binary.get_path (), ModuleFlags.BIND_LAZY);
if (module == null)
- throw new AssemblyError.LOAD(GLib.Module.error());
- module.make_resident();
+ throw new AssemblyError.LOAD (GLib.Module.error ());
+ module.make_resident ();
}
-
- public virtual void* get_method(string method_name) throws AssemblyError {
- if(module == null)
- load_module();
+
+ public virtual void* get_method (string method_name) throws AssemblyError {
+ if (module == null)
+ load_module ();
void* function;
- if(module.symbol (method_name, out function))
+ if (module.symbol (method_name, out function))
if (function != null)
return function;
- throw new AssemblyError.METHOD(GLib.Module.error());
+ throw new AssemblyError.METHOD (GLib.Module.error ());
}
- public override Assembly clone() throws Error {
- return new TestModule(binary);
+ public override Assembly clone () throws Error {
+ return new TestModule (binary);
}
}
diff --git a/valadate/testoptions.vala b/valadate/testoptions.vala
index 1cffd54..f7a19c2 100644
--- a/valadate/testoptions.vala
+++ b/valadate/testoptions.vala
@@ -60,7 +60,7 @@ public class Valadate.TestOptions {
public OptionContext opt_context;
- public static string? get_current_test_path() {
+ public static string? get_current_test_path () {
return _runtest;
}
@@ -118,7 +118,7 @@ public class Valadate.TestOptions {
}
}
- public TestOptions(string[] args) throws OptionError {
+ public TestOptions (string[] args) throws OptionError {
_runtest = null;
opt_context = new OptionContext ("- Valadate Testing Framework");
@@ -126,12 +126,12 @@ public class Valadate.TestOptions {
opt_context.add_main_entries (options, null);
opt_context.parse (ref args);
- if(_seed == null)
- _seed = "R02S%08x%08x%08x%08x".printf(
- GLib.Random.next_int(),
- GLib.Random.next_int(),
- GLib.Random.next_int(),
- GLib.Random.next_int());
+ if (_seed == null)
+ _seed = "R02S%08x%08x%08x%08x".printf (
+ GLib.Random.next_int (),
+ GLib.Random.next_int (),
+ GLib.Random.next_int (),
+ GLib.Random.next_int ());
}
diff --git a/valadate/testplan.vala b/valadate/testplan.vala
index d70158d..9c32b1d 100644
--- a/valadate/testplan.vala
+++ b/valadate/testplan.vala
@@ -15,21 +15,21 @@
* 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.TestPlan : Vala.CodeVisitor {
[CCode (has_target = false)]
- public delegate void TestMethod(TestCase self) throws Error;
+ public delegate void TestMethod (TestCase self) throws Error;
+
+ public delegate void AsyncTestMethod (TestCase self, AsyncReadyCallback cb);
+ public delegate void AsyncTestMethodResult (TestCase self, AsyncResult res) throws Error;
- public delegate void AsyncTestMethod(TestCase self, AsyncReadyCallback cb);
- public delegate void AsyncTestMethodResult(TestCase self, AsyncResult res) throws Error;
+ public delegate Type GetType ();
- public delegate Type GetType();
-
public File plan {get;set;}
public TestAssembly assembly {get;set;}
@@ -39,47 +39,47 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
public TestConfig config {get;set;}
public TestResult result {get;set;}
-
+
public TestRunner runner {get;set;}
public TestSuite root {get;protected set;}
private Vala.CodeContext context;
private TestGatherer gatherer;
- private delegate TestCase Constructor();
+ private delegate TestCase Constructor ();
private TestSuite testsuite;
private TestCase testcase;
- public TestPlan(TestAssembly assembly) throws Error {
+ public TestPlan (TestAssembly assembly) throws Error {
this.assembly = assembly;
options = assembly.options;
-
- var plan_name = Path.get_basename(assembly.binary.get_path());
- if(plan_name.has_prefix("lt-"))
- plan_name = plan_name.substring(3);
-
- plan = assembly.srcdir.get_child(plan_name + ".vapi");
- if(!plan.query_exists()) {
- plan = assembly.builddir.get_child(plan_name + ".vapi");
- if(!plan.query_exists()) {
- throw new TestConfigError.TESTPLAN(
- "Test Plan %s Not Found in %s or %s", plan_name,
assembly.srcdir.get_path(), assembly.builddir.get_path());
+
+ var plan_name = Path.get_basename (assembly.binary.get_path ());
+ if (plan_name.has_prefix ("lt-"))
+ plan_name = plan_name.substring (3);
+
+ plan = assembly.srcdir.get_child (plan_name + ".vapi");
+ if (!plan.query_exists ()) {
+ plan = assembly.builddir.get_child (plan_name + ".vapi");
+ if (!plan.query_exists ()) {
+ throw new TestConfigError.TESTPLAN (
+ "Test Plan %s Not Found in %s or %s", plan_name,
assembly.srcdir.get_path (), assembly.builddir.get_path ());
}
}
- config = new TestConfig(options);
- runner = new TestRunner();
- result = new TestResult(config);
- testsuite = root = new TestSuite("/");
- setup_context();
- load_test_plan();
+ config = new TestConfig (options);
+ runner = new TestRunner ();
+ result = new TestResult (config);
+ testsuite = root = new TestSuite ("/");
+ setup_context ();
+ load_test_plan ();
}
- public int run() throws Error {
- return runner.run_all(this);
+ public int run () throws Error {
+ return runner.run_all (this);
}
- private void setup_context() {
+ private void setup_context () {
context = new Vala.CodeContext ();
Vala.CodeContext.push (context);
context.report.enable_warnings = false;
@@ -87,198 +87,198 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
context.verbose_mode = false;
}
- public void load_test_plan() throws Error {
+ public void load_test_plan () throws Error {
context.add_source_file (new Vala.SourceFile (
- context, Vala.SourceFileType.PACKAGE, plan.get_path()));
+ context, Vala.SourceFileType.PACKAGE, plan.get_path ()));
var parser = new Vala.Parser ();
parser.parse (context);
- gatherer = new TestGatherer(assembly);
- context.accept(gatherer);
- context.accept(this);
+ gatherer = new TestGatherer (assembly);
+ context.accept (gatherer);
+ context.accept (this);
}
- public override void visit_namespace(Vala.Namespace ns) {
+ public override void visit_namespace (Vala.Namespace ns) {
if (ns.name != null) {
- var currpath = "/" + ns.get_full_name().replace(".","/");
- if(config.in_subprocess)
- if(!options.running_test.has_prefix(currpath))
+ var currpath = "/" + ns.get_full_name ().replace (".","/");
+ if (config.in_subprocess)
+ if (!options.running_test.has_prefix (currpath))
return;
- if(currpath.last_index_of("/") == 0)
+ if (currpath.last_index_of ("/") == 0)
testsuite = root;
- var ts = new TestSuite(ns.name);
- testsuite.add_test(ts);
+ var ts = new TestSuite (ns.name);
+ testsuite.add_test (ts);
testsuite = ts;
}
- ns.accept_children(this);
+ ns.accept_children (this);
}
-
- public override void visit_class(Vala.Class cls) {
+
+ public override void visit_class (Vala.Class cls) {
try {
- if (is_subtype_of(cls, typeof(TestCase)) && !cls.is_abstract) {
- unowned Constructor ctor = get_constructor(cls);
- testcase = ctor();
+ if (is_subtype_of (cls, typeof (TestCase)) && !cls.is_abstract) {
+ unowned Constructor ctor = get_constructor (cls);
+ testcase = ctor ();
testcase.name = cls.name;
- testcase.label = "/%s".printf(cls.get_full_name().replace(".","/"));
- testsuite.add_test(testcase);
- visit_testcase(cls);
+ testcase.label = "/%s".printf (cls.get_full_name ().replace (".","/"));
+ testsuite.add_test (testcase);
+ visit_testcase (cls);
- } else if (is_subtype_of(cls,typeof(TestSuite))) {
- visit_testsuite(cls);
+ } else if (is_subtype_of (cls,typeof (TestSuite))) {
+ visit_testsuite (cls);
}
} catch (Error e) {
- error(e.message);
+ error (e.message);
}
- cls.accept_children(this);
+ cls.accept_children (this);
}
- private bool is_subtype_of(Vala.Class cls, Type type) {
- var t = Type.from_name(cls.get_full_name().replace(".",""));
- if(t.is_a(type))
+ private bool is_subtype_of (Vala.Class cls, Type type) {
+ var t = Type.from_name (cls.get_full_name ().replace (".",""));
+ if (t.is_a (type))
return true;
return false;
}
- private unowned Constructor get_constructor(Vala.Class cls) throws Error {
+ private unowned Constructor get_constructor (Vala.Class cls) throws Error {
var attr = new Vala.CCodeAttribute (cls.default_construction_method);
- return (Constructor)assembly.get_method(attr.name);
+ return (Constructor)assembly.get_method (attr.name);
}
- public void visit_testcase(Vala.Class cls) {
+ public void visit_testcase (Vala.Class cls) {
- var t = Type.from_name(cls.get_full_name().replace(".",""));
- var p = t.parent();
- if(p != typeof(TestCase)) {
- var basecls = gatherer.classes.get(p);
- if(basecls != null)
- visit_testcase(basecls);
+ var t = Type.from_name (cls.get_full_name ().replace (".",""));
+ var p = t.parent ();
+ if (p != typeof (TestCase)) {
+ var basecls = gatherer.classes.get (p);
+ if (basecls != null)
+ visit_testcase (basecls);
}
- foreach(var method in cls.get_methods()) {
+ foreach (var method in cls.get_methods ()) {
- if(config.in_subprocess)
- if (options.running_test != "%s/%s".printf(
+ if (config.in_subprocess)
+ if (options.running_test != "%s/%s".printf (
testcase.label, method.name))
continue;
- if(!is_test(method))
+ if (!is_test (method))
continue;
var added = false;
- foreach(var test in testcase)
- if(test.name == method.name)
+ foreach (var test in testcase)
+ if (test.name == method.name)
added=true;
- if(added)
+ if (added)
continue;
- var adapter = new TestAdapter(method.name, config.timeout);
- annotate_label(adapter);
- annotate(adapter, method);
+ var adapter = new TestAdapter (method.name, config.timeout);
+ annotate_label (adapter);
+ annotate (adapter, method);
- if(config.in_subprocess && adapter.status != TestStatus.SKIPPED) {
+ if (config.in_subprocess && adapter.status != TestStatus.SKIPPED) {
var attr = new Vala.CCodeAttribute (method);
- if(method.coroutine) {
+ if (method.coroutine) {
try {
- unowned TestPlan.AsyncTestMethod beginmethod =
-
(TestPlan.AsyncTestMethod)assembly.get_method(attr.name);
- unowned TestPlan.AsyncTestMethodResult testmethod =
-
(TestPlan.AsyncTestMethodResult)assembly.get_method(attr.finish_real_name);
- adapter.add_async_test(beginmethod, testmethod);
+ unowned TestPlan.AsyncTestMethod beginmethod =
+ (TestPlan.AsyncTestMethod)assembly.get_method
(attr.name);
+ unowned TestPlan.AsyncTestMethodResult testmethod =
+ (TestPlan.AsyncTestMethodResult)assembly.get_method
(attr.finish_real_name);
+ adapter.add_async_test (beginmethod, testmethod);
} catch (Error e) {
var message = e.message;
- adapter.add_test_method(()=> {debug(message);});
+ adapter.add_test_method (()=> {debug (message);});
}
} else {
try {
TestPlan.TestMethod testmethod =
- (TestPlan.TestMethod)assembly.get_method(attr.name);
- adapter.add_test((owned)testmethod);
+ (TestPlan.TestMethod)assembly.get_method (attr.name);
+ adapter.add_test ((owned)testmethod);
} catch (Error e) {
var message = e.message;
- adapter.add_test_method(()=> {debug(message);});
+ adapter.add_test_method (()=> {debug (message);});
}
}
} else {
- adapter.add_test_method(()=> {assert_not_reached();});
+ adapter.add_test_method (()=> {assert_not_reached ();});
}
- adapter.label = "%s/%s".printf(
+ adapter.label = "%s/%s".printf (
testcase.label,
adapter.label);
- testcase.add_test(adapter);
+ testcase.add_test (adapter);
}
}
- private void annotate_label(Test test) {
- if(test.name.has_prefix("test_")) {
- test.label = test.name.substring(5);
- } else if(test.name.has_prefix("_test_")) {
- test.label = test.name.substring(6);
+ private void annotate_label (Test test) {
+ if (test.name.has_prefix ("test_")) {
+ test.label = test.name.substring (5);
+ } else if (test.name.has_prefix ("_test_")) {
+ test.label = test.name.substring (6);
test.status = TestStatus.SKIPPED;
- } else if(test.name.has_prefix("todo_test_")) {
- test.label = test.name.substring(10);
+ } else if (test.name.has_prefix ("todo_test_")) {
+ test.label = test.name.substring (10);
test.status = TestStatus.TODO;
} else {
test.label = test.name;
}
- test.label = test.label.replace("_", " ");
+ test.label = test.label.replace ("_", " ");
}
- private void annotate(TestAdapter adapter, Vala.Method method) {
+ private void annotate (TestAdapter adapter, Vala.Method method) {
- foreach(var attr in method.attributes) {
- if(attr.name == "Test") {
- if(attr.has_argument("name"))
- adapter.label = attr.get_string("name");
- if(attr.has_argument("skip")) {
+ foreach (var attr in method.attributes) {
+ if (attr.name == "Test") {
+ if (attr.has_argument ("name"))
+ adapter.label = attr.get_string ("name");
+ if (attr.has_argument ("skip")) {
adapter.status = TestStatus.SKIPPED;
- adapter.status_message = attr.get_string("skip");
- } else if(attr.has_argument("todo")) {
+ adapter.status_message = attr.get_string ("skip");
+ } else if (attr.has_argument ("todo")) {
adapter.status = TestStatus.SKIPPED;
- adapter.status_message = attr.get_string("todo");
- } else if(attr.has_argument("timeout")) {
- adapter.timeout = int.parse(attr.get_string("timeout"));
+ adapter.status_message = attr.get_string ("todo");
+ } else if (attr.has_argument ("timeout")) {
+ adapter.timeout = int.parse (attr.get_string ("timeout"));
}
}
}
}
- private bool is_test(Vala.Method method) {
+ private bool is_test (Vala.Method method) {
bool istest = false;
-
- if(method.is_virtual)
- foreach(var test in testcase)
- if(test.name == method.name)
+
+ if (method.is_virtual)
+ foreach (var test in testcase)
+ if (test.name == method.name)
return false;
-
- if (method.name.has_prefix("test_") ||
- method.name.has_prefix("_test_") ||
- method.name.has_prefix("todo_test_"))
+
+ if (method.name.has_prefix ("test_") ||
+ method.name.has_prefix ("_test_") ||
+ method.name.has_prefix ("todo_test_"))
istest = true;
- foreach(var attr in method.attributes)
- if(attr.name == "Test")
+ foreach (var attr in method.attributes)
+ if (attr.name == "Test")
istest = true;
- if(method.has_result)
+ if (method.has_result)
istest = false;
-
- if(method.get_parameters().size > 0)
+
+ if (method.get_parameters ().size > 0)
istest = false;
-
+
return istest;
}
- public void visit_testsuite(Vala.Class testclass) throws Error {
- unowned Constructor meth = get_constructor(testclass);
- var tsuite = meth() as TestSuite;
+ public void visit_testsuite (Vala.Class testclass) throws Error {
+ unowned Constructor meth = get_constructor (testclass);
+ var tsuite = meth () as TestSuite;
tsuite.name = testclass.name;
- testsuite.add_test(tsuite);
+ testsuite.add_test (tsuite);
testsuite = tsuite;
- }
+ }
}
diff --git a/valadate/testreport.vala b/valadate/testreport.vala
index f5e58f6..d54d982 100644
--- a/valadate/testreport.vala
+++ b/valadate/testreport.vala
@@ -19,7 +19,7 @@
* Authors:
* Chris Daley <chebizarro gmail com>
*/
-
+
public class Valadate.TestReport {
private const string XML_DECL ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
@@ -45,7 +45,7 @@ public class Valadate.TestReport {
public Test test {get;set;}
public bool subprocess {get;set;}
-
+
public XmlFile xml {get;set;}
private static int64 start_time;
@@ -53,170 +53,170 @@ public class Valadate.TestReport {
private static Regex regex_err;
private const string regex_err_string =
- """(\*{2}\n([A-Z]*):([\S]*) ([\S ]*)\n)""";
-
- public TestReport(Test test, bool subprocess) throws Error {
+ """(\*{2}\n([A-Z]*):([\S]*)([\S ]*)\n)""";
+
+ public TestReport (Test test, bool subprocess) throws Error {
this.test = test;
this.subprocess = subprocess;
- if(test.status == TestStatus.NOT_RUN)
+ if (test.status == TestStatus.NOT_RUN)
test.status = TestStatus.RUNNING;
- if(subprocess) {
+ if (subprocess) {
Log.set_default_handler (log_func);
GLib.set_printerr_handler (printerr_func);
- regex_err = new Regex(regex_err_string);
+ regex_err = new Regex (regex_err_string);
}
- if(test is TestSuite || test is TestCase)
- new_testsuite();
+ if (test is TestSuite || test is TestCase)
+ new_testsuite ();
else if (test is TestAdapter)
- new_testcase();
+ new_testcase ();
}
-
- private void new_testsuite() throws Error {
- if(subprocess)
+
+ private void new_testsuite () throws Error {
+ if (subprocess)
return;
-
- var decl = "%s<%s>%s</%s>".printf(XML_DECL, ROOT_TAG, TESTSUITE_XML, ROOT_TAG);
- var doc = Xml.Parser.read_memory(decl, decl.length);
- var root = doc->get_root_element()->children;
- root->set_prop("tests", test.count.to_string());
- root->set_prop("name",test.label);
- xml = new XmlFile.from_doc(doc);
+
+ var decl = "%s<%s>%s</%s>".printf (XML_DECL, ROOT_TAG, TESTSUITE_XML, ROOT_TAG);
+ var doc = Xml.Parser.read_memory (decl, decl.length);
+ var root = doc->get_root_element ()->children;
+ root->set_prop ("tests", test.count.to_string ());
+ root->set_prop ("name",test.label);
+ xml = new XmlFile.from_doc (doc);
}
- private void new_testcase() throws Error {
- if(subprocess) {
- stderr.printf("%s<%s>",XML_DECL,ROOT_TAG);
- stderr.printf(TESTCASE_START,test.parent.get_type().name(), test.label);
- start_time = get_monotonic_time();
+ private void new_testcase () throws Error {
+ if (subprocess) {
+ stderr.printf ("%s<%s>",XML_DECL,ROOT_TAG);
+ stderr.printf (TESTCASE_START,test.parent.get_type ().name (), test.label);
+ start_time = get_monotonic_time ();
} else {
- var decl = "%s<%s>%s</%s>".printf(XML_DECL, ROOT_TAG, TESTCASE_XML, ROOT_TAG);
- var doc = Xml.Parser.read_memory(decl, decl.length);
- var root = doc->get_root_element()->children;
- root->set_prop("classname",((TestAdapter)test).parent.name);
- root->set_prop("status",test.status.to_string().substring(21));
- root->set_prop("name",test.label);
- xml = new XmlFile.from_doc(doc);
+ var decl = "%s<%s>%s</%s>".printf (XML_DECL, ROOT_TAG, TESTCASE_XML, ROOT_TAG);
+ var doc = Xml.Parser.read_memory (decl, decl.length);
+ var root = doc->get_root_element ()->children;
+ root->set_prop ("classname", ((TestAdapter)test).parent.name);
+ root->set_prop ("status",test.status.to_string ().substring (21));
+ root->set_prop ("name",test.label);
+ xml = new XmlFile.from_doc (doc);
}
}
- public void add_error(string message) {
+ public void add_error (string message) {
if (test.status != TestStatus.SKIPPED &&
test.status != TestStatus.TODO)
test.status = TestStatus.ERROR;
- add_message(ERROR_TAG, message);
+ add_message (ERROR_TAG, message);
- if(subprocess) {
- emit_timer();
- stderr.printf("</%s></%s>",TESTCASE_TAG, ROOT_TAG);
- stderr.putc(0);
+ if (subprocess) {
+ emit_timer ();
+ stderr.printf ("</%s></%s>",TESTCASE_TAG, ROOT_TAG);
+ stderr.putc (0);
}
- update_status();
+ update_status ();
}
- public void add_failure(string message) {
+ public void add_failure (string message) {
if (test.status != TestStatus.SKIPPED &&
test.status != TestStatus.TODO)
test.status = TestStatus.FAILED;
- add_message(FAILURE_TAG, message);
-
- if(subprocess) {
- emit_timer();
- stderr.printf("</%s></%s>",TESTCASE_TAG, ROOT_TAG);
- stderr.putc(0);
+ add_message (FAILURE_TAG, message);
+
+ if (subprocess) {
+ emit_timer ();
+ stderr.printf ("</%s></%s>",TESTCASE_TAG, ROOT_TAG);
+ stderr.putc (0);
}
- update_status();
+ update_status ();
}
- public void add_skip(string message) {
+ public void add_skip (string message) {
test.status = TestStatus.SKIPPED;
- add_message(SKIP_TAG, message);
- update_status();
+ add_message (SKIP_TAG, message);
+ update_status ();
}
- public void add_success() {
+ public void add_success () {
if (test.status != TestStatus.SKIPPED &&
test.status != TestStatus.TODO)
test.status = TestStatus.PASSED;
- if(subprocess) {
- emit_timer();
- stderr.printf("</%s></%s>",TESTCASE_TAG, ROOT_TAG);
- stderr.putc(0);
+ if (subprocess) {
+ emit_timer ();
+ stderr.printf ("</%s></%s>",TESTCASE_TAG, ROOT_TAG);
+ stderr.putc (0);
}
- update_status();
+ update_status ();
}
- private void add_message(string tag, string message) {
- var escaped = Markup.escape_text(message);
- if(subprocess) {
- stderr.printf(MESSAGE_XML, tag, escaped, tag.up(), message, tag);
+ private void add_message (string tag, string message) {
+ var escaped = Markup.escape_text (message);
+ if (subprocess) {
+ stderr.printf (MESSAGE_XML, tag, escaped, tag.up (), message, tag);
} else {
- Xml.Node* child = new Xml.Node(null, tag);
- child->set_content(escaped);
-
+ Xml.Node* child = new Xml.Node (null, tag);
+ child->set_content (escaped);
+
string[] tags = {ERROR_TAG, FAILURE_TAG, INFO_TAG};
-
- if(tag in tags) {
- child->new_prop("message", escaped);
- child->new_prop("type", tag.up());
+
+ if (tag in tags) {
+ child->new_prop ("message", escaped);
+ child->new_prop ("type", tag.up ());
}
-
- Xml.Node* root = xml.eval("//testcase | //testsuite")[0];
- root->add_child(child);
+
+ Xml.Node* root = xml.eval ("//testcase | //testsuite")[0];
+ root->add_child (child);
}
}
/**
* Adds arbitrary text to the TestReport. In the xml output this
* text will be encapsulated in <system-out/> or <system-err/> tag
- *
+ *
* @param text The text to be added to the {@link TestReport}.
* the text will be escaped before being added.
* @param tag The tag to use for adding the text
- */
- public void add_text(string text, string tag) {
- var markup = Markup.escape_text(text);
- Xml.Node* child = new Xml.Node(null, tag);
- child->set_content(markup);
-
+ */
+ public void add_text (string text, string tag) {
+ var markup = Markup.escape_text (text);
+ Xml.Node* child = new Xml.Node (null, tag);
+ child->set_content (markup);
+
string[] tags = {ERROR_TAG, FAILURE_TAG, INFO_TAG};
-
- if(tag in tags) {
- child->new_prop("message", markup);
- child->new_prop("type", tag.up());
+
+ if (tag in tags) {
+ child->new_prop ("message", markup);
+ child->new_prop ("type", tag.up ());
}
-
- Xml.Node* root = xml.eval("//testcase | //testsuite")[0];
- root->add_child(child);
+
+ Xml.Node* root = xml.eval ("//testcase | //testsuite")[0];
+ root->add_child (child);
}
-
- public void update_status() {
- if(test is TestAdapter && !subprocess) {
- Xml.Node* root = xml.eval("//testcase")[0];
- root->set_prop("status",test.status.to_string().substring(21));
- root->set_prop("time",test.time.to_string());
+
+ public void update_status () {
+ if (test is TestAdapter && !subprocess) {
+ Xml.Node* root = xml.eval ("//testcase")[0];
+ root->set_prop ("status",test.status.to_string ().substring (21));
+ root->set_prop ("time",test.time.to_string ());
}
}
- private static void emit_timer() {
- end_time = get_monotonic_time();
- var ms = "%f".printf(((double)(end_time-start_time))/1000);
- stderr.printf(MESSAGE_XML, TIMER_TAG, ms, TIMER_TAG, ms, TIMER_TAG);
+ private static void emit_timer () {
+ end_time = get_monotonic_time ();
+ var ms = "%f".printf (((double) (end_time-start_time))/1000);
+ stderr.printf (MESSAGE_XML, TIMER_TAG, ms, TIMER_TAG, ms, TIMER_TAG);
}
private static void printerr_func (string? text) {
- if(text == null)
+ if (text == null)
return;
MatchInfo info;
- if(regex_err.match(text, 0, out info)) {
- var escaped = Markup.escape_text(info.fetch(4));
- stderr.printf(MESSAGE_XML, ERROR_TAG, escaped, ERROR_TAG, text, ERROR_TAG);
- emit_timer();
- stderr.printf("</%s></%s>",TESTCASE_TAG, ROOT_TAG);
- stderr.putc(0);
+ if (regex_err.match (text, 0, out info)) {
+ var escaped = Markup.escape_text (info.fetch (4));
+ stderr.printf (MESSAGE_XML, ERROR_TAG, escaped, ERROR_TAG, text, ERROR_TAG);
+ emit_timer ();
+ stderr.printf ("</%s></%s>",TESTCASE_TAG, ROOT_TAG);
+ stderr.putc (0);
}
}
@@ -226,41 +226,41 @@ public class Valadate.TestReport {
string? message) {
if (((log_levels & LogLevelFlags.LEVEL_INFO) != 0) ||
- ((log_levels & LogLevelFlags.LEVEL_MESSAGE) != 0) ||
- ((log_levels & LogLevelFlags.LEVEL_DEBUG) != 0)) {
- add_message(INFO_TAG, message);
+ ((log_levels & LogLevelFlags.LEVEL_MESSAGE) != 0) ||
+ ((log_levels & LogLevelFlags.LEVEL_DEBUG) != 0)) {
+ add_message (INFO_TAG, message);
} else {
- add_error(message);
+ add_error (message);
}
}
- public void process_buffer(string buffer) throws Error {
-
- xml = new XmlFile.from_string(buffer);
+ public void process_buffer (string buffer) throws Error {
+
+ xml = new XmlFile.from_string (buffer);
- var bits = xml.eval("//testcase/text()");
+ var bits = xml.eval ("//testcase/text ()");
- if(bits.size != 0) {
+ if (bits.size != 0) {
Xml.Node* textnode = bits[0];
- add_message(SYSTEM_ERR_TAG, textnode->get_content());
- textnode->unlink();
+ add_message (SYSTEM_ERR_TAG, textnode->get_content ());
+ textnode->unlink ();
}
- var errs = xml.eval("//failure | //error");
+ var errs = xml.eval ("//failure | //error");
if (errs.size > 0 &&
test.status != TestStatus.SKIPPED &&
test.status != TestStatus.TODO)
test.status = TestStatus.FAILED;
- bits = xml.eval("//timer");
+ bits = xml.eval ("//timer");
Xml.Node* timer = bits[0];
- test.time = double.parse(timer->get_content());
- timer->unlink();
+ test.time = double.parse (timer->get_content ());
+ timer->unlink ();
- update_status();
+ update_status ();
}
- public void add_stdout(string text) {
- add_message(SYSTEM_OUT_TAG, text);
+ public void add_stdout (string text) {
+ add_message (SYSTEM_OUT_TAG, text);
}
}
diff --git a/valadate/testreportprinter.vala b/valadate/testreportprinter.vala
index 71c8ed8..ab9015a 100644
--- a/valadate/testreportprinter.vala
+++ b/valadate/testreportprinter.vala
@@ -1,47 +1,47 @@
/*
* Valadate - Unit testing library for GObject-based libraries.
* Copyright (C) 2017 Chris Daley <chebizarro gmail com>
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program 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 General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; 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 abstract class Valadate.TestReportPrinter {
- public static TestReportPrinter @new(TestConfig config) throws Error {
- switch(config.format) {
+ public static TestReportPrinter @new (TestConfig config) throws Error {
+ switch (config.format) {
case "tap" :
- return new TapTestReportPrinter(config);
+ return new TapTestReportPrinter (config);
case "xml" :
- return new XmlTestReportPrinter(config);
+ return new XmlTestReportPrinter (config);
case "gnu" :
- return new GnuTestReportPrinter(config);
+ return new GnuTestReportPrinter (config);
default:
- throw new TestConfigError.TEST_PRINTER("TestReportPrinter %s does not exist",
config.format);
+ throw new TestConfigError.TEST_PRINTER ("TestReportPrinter %s does not
exist", config.format);
}
}
-
+
public TestConfig config {get; set;}
-
- public TestReportPrinter(TestConfig config) throws Error {
+
+ public TestReportPrinter (TestConfig config) throws Error {
this.config = config;
}
- public abstract void print(TestReport report);
-
+ public abstract void print (TestReport report);
+
}
diff --git a/valadate/testresult.vala b/valadate/testresult.vala
index d04660d..cf91711 100644
--- a/valadate/testresult.vala
+++ b/valadate/testresult.vala
@@ -25,112 +25,112 @@ public class Valadate.TestResult {
public TestConfig config {get;set;}
public TestReportPrinter printer {get;set;}
- private Queue<TestReport> reports = new Queue<TestReport>();
- private HashTable<Test, TestReport> tests = new HashTable<Test, TestReport>(direct_hash,
direct_equal);
+ private Queue<TestReport> reports = new Queue<TestReport> ();
+ private HashTable<Test, TestReport> tests = new HashTable<Test, TestReport> (direct_hash,
direct_equal);
- public TestResult(TestConfig config) throws Error {
+ public TestResult (TestConfig config) throws Error {
this.config = config;
- if(!config.in_subprocess)
- printer = TestReportPrinter.new(config);
+ if (!config.in_subprocess)
+ printer = TestReportPrinter.new (config);
}
- public bool report() {
- if (reports.is_empty())
+ public bool report () {
+ if (reports.is_empty ())
return false;
-
- var rpt = reports.peek_head();
-
+
+ var rpt = reports.peek_head ();
+
if (rpt.test.status == TestStatus.PASSED ||
rpt.test.status == TestStatus.SKIPPED ||
rpt.test.status == TestStatus.TODO ||
rpt.test.status == TestStatus.FAILED ||
rpt.test.status == TestStatus.ERROR) {
-
- printer.print(rpt);
- reports.pop_head();
- report();
+
+ printer.print (rpt);
+ reports.pop_head ();
+ report ();
}
return true;
}
- private void update_status(Test test) {
- var rept = tests.get(test);
- if(rept == null)
+ private void update_status (Test test) {
+ var rept = tests.get (test);
+ if (rept == null)
return;
var parent = test.parent;
- if(parent == null)
+ if (parent == null)
return;
TestStatus status = TestStatus.PASSED;
- foreach(var t in parent) {
- if(t.status == TestStatus.RUNNING)
+ foreach (var t in parent) {
+ if (t.status == TestStatus.RUNNING)
return;
- else if(t.status == TestStatus.ERROR)
+ else if (t.status == TestStatus.ERROR)
status = TestStatus.ERROR;
- else if(t.status == TestStatus.FAILED)
+ else if (t.status == TestStatus.FAILED)
status = TestStatus.FAILED;
}
parent.status = status;
- update_status(parent);
- }
+ update_status (parent);
+ }
- public void add_test(Test test) {
+ public void add_test (Test test) {
try {
- reports.push_tail(new TestReport(test, config.in_subprocess));
- tests.insert(test, reports.peek_tail());
+ reports.push_tail (new TestReport (test, config.in_subprocess));
+ tests.insert (test, reports.peek_tail ());
} catch (Error e) {
- error(e.message);
+ error (e.message);
}
}
- public void add_error(Test test, string error) {
- tests.get(test).add_error(error);
- update_status(test);
+ public void add_error (Test test, string error) {
+ tests.get (test).add_error (error);
+ update_status (test);
}
- public void add_failure(Test test, string failure) {
- tests.get(test).add_failure(failure);
- update_status(test);
+ public void add_failure (Test test, string failure) {
+ tests.get (test).add_failure (failure);
+ update_status (test);
}
-
- public void add_success(Test test) {
- tests.get(test).add_success();
- update_status(test);
+
+ public void add_success (Test test) {
+ tests.get (test).add_success ();
+ update_status (test);
}
- public void add_skip(Test test, string message) {
- tests.get(test).add_skip(message);
- update_status(test);
+ public void add_skip (Test test, string message) {
+ tests.get (test).add_skip (message);
+ update_status (test);
}
- public void process_buffers(Test test, Assembly assembly) throws Error {
-
- var rept = tests.get(test);
- if(rept == null)
+ public void process_buffers (Test test, Assembly assembly) throws Error {
+
+ var rept = tests.get (test);
+ if (rept == null)
return;
var bis = new BufferedInputStream (assembly.stderr);
- bis.fill(-1);
- var xml = (string)bis.peek_buffer();
- if(xml.length < 8)
+ bis.fill (-1);
+ var xml = (string)bis.peek_buffer ();
+ if (xml.length < 8)
return;
- rept.process_buffer(xml);
+ rept.process_buffer (xml);
- update_status(test);
+ update_status (test);
uint8 outbuffer[4096] = {};
- assembly.stdout.read_all(outbuffer, null);
- xml = ((string)outbuffer).strip();
+ assembly.stdout.read_all (outbuffer, null);
+ xml = ((string)outbuffer).strip ();
int i;
- for(i=xml.length-1;i==0;i--)
- if(xml.get_char(i).isgraph())
+ for (i=xml.length-1;i==0;i--)
+ if (xml.get_char (i).isgraph ())
break;
- xml = xml.substring(0, i+1);
- if(xml.length < 1 || xml == "\n")
+ xml = xml.substring (0, i+1);
+ if (xml.length < 1 || xml == "\n")
return;
- rept.add_stdout(xml);
+ rept.add_stdout (xml);
}
}
diff --git a/valadate/testrunner.vala b/valadate/testrunner.vala
index 2576cc3..af9968b 100644
--- a/valadate/testrunner.vala
+++ b/valadate/testrunner.vala
@@ -15,7 +15,7 @@
* 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>
*/
@@ -28,139 +28,139 @@ public class Valadate.TestRunner {
private uint _n_ongoing_tests = 0;
private Queue<DelegateWrapper> _pending_tests = new Queue<DelegateWrapper> ();
- private static uint _max_n_ongoing_tests = GLib.get_num_processors();
+ private static uint _max_n_ongoing_tests = GLib.get_num_processors ();
private MainLoop loop;
private TestPlan plan;
-
- public void run(Test test, TestResult result) {
- result.add_test(test);
- test.run(result);
- result.report();
+
+ public void run (Test test, TestResult result) {
+ result.add_test (test);
+ test.run (result);
+ result.report ();
}
- public int run_all(TestPlan plan) throws Error {
+ public int run_all (TestPlan plan) throws Error {
this.plan = plan;
-
+
if (plan.config.list_only) {
- list_tests(plan.root, "");
+ list_tests (plan.root, "");
return 0;
} else if (plan.root.count == 0) {
return 0;
} else if (!plan.config.in_subprocess) {
- loop = new MainLoop();
- Timeout.add(
+ loop = new MainLoop ();
+ Timeout.add (
10,
- () => {
- bool res = plan.result.report();
- if(!res)
- loop.quit();
+ () => {
+ bool res = plan.result.report ();
+ if (!res)
+ loop.quit ();
return res;
-
+
},
Priority.HIGH_IDLE);
- run_test_internal(plan.root, plan.result, "");
- loop.run();
+ run_test_internal (plan.root, plan.result, "");
+ loop.run ();
} else {
- run_test_internal(plan.root, plan.result, "");
+ run_test_internal (plan.root, plan.result, "");
}
return 0;
}
-
- private void list_tests(Test test, string path) {
- foreach(var subtest in test) {
- string testpath = "%s/%s".printf(path, subtest.name);
- if(subtest is TestAdapter)
- stdout.printf("%s\n", testpath);
+
+ private void list_tests (Test test, string path) {
+ foreach (var subtest in test) {
+ string testpath = "%s/%s".printf (path, subtest.name);
+ if (subtest is TestAdapter)
+ stdout.printf ("%s\n", testpath);
else
- list_tests(subtest, testpath);
+ list_tests (subtest, testpath);
}
}
- public void run_test(Test test, TestResult result) {
- test.run(result);
+ public void run_test (Test test, TestResult result) {
+ test.run (result);
}
- private void run_test_internal(Test test, TestResult result, string path) throws Error {
+ private void run_test_internal (Test test, TestResult result, string path) throws Error {
- foreach(var subtest in test) {
+ foreach (var subtest in test) {
- var testpath = "%s/%s".printf(path, subtest.name);
+ var testpath = "%s/%s".printf (path, subtest.name);
- if(subtest is TestCase) {
- if(!plan.config.in_subprocess)
- result.add_test(subtest);
- run_test_internal(subtest, result, testpath);
+ if (subtest is TestCase) {
+ if (!plan.config.in_subprocess)
+ result.add_test (subtest);
+ run_test_internal (subtest, result, testpath);
} else if (subtest is TestSuite) {
- result.add_test(subtest);
- run_test_internal(subtest, result, testpath);
+ result.add_test (subtest);
+ run_test_internal (subtest, result, testpath);
} else if (plan.config.in_subprocess) {
- if(plan.config.running_test == testpath)
- test.run(result);
+ if (plan.config.running_test == testpath)
+ test.run (result);
} else if (subtest is TestAdapter) {
subtest.name = testpath;
- result.add_test(subtest);
- run_async.begin(subtest, result);
+ result.add_test (subtest);
+ run_async.begin (subtest, result);
}
}
}
- private async void run_async(Test test, TestResult result) throws Error
- requires(plan.config.in_subprocess != true) {
+ private async void run_async (Test test, TestResult result) throws Error
+ requires (plan.config.in_subprocess != true) {
var timeout = plan.config.timeout;
- var testprog = plan.assembly.clone();
+ var testprog = plan.assembly.clone ();
if (_n_ongoing_tests > _max_n_ongoing_tests) {
- var wrapper = new DelegateWrapper();
+ var wrapper = new DelegateWrapper ();
wrapper.cb = run_async.callback;
- _pending_tests.push_tail((owned)wrapper);
+ _pending_tests.push_tail ((owned)wrapper);
yield;
}
-
+
try {
_n_ongoing_tests++;
var cancellable = new Cancellable ();
var tcase = test as TestAdapter;
- if(timeout != tcase.timeout)
+ if (timeout != tcase.timeout)
timeout = tcase.timeout;
-
+
var time = new TimeoutSource (timeout);
-
+
cancellable.cancelled.connect (() => {
- testprog.quit();
+ testprog.quit ();
});
time.set_callback (() => {
if (tcase.status == TestStatus.RUNNING)
- cancellable.cancel();
+ cancellable.cancel ();
return false;
});
- time.attach (loop.get_context());
+ time.attach (loop.get_context ());
- testprog.run("-r %s".printf(test.name), cancellable);
- result.add_success(test);
- result.process_buffers(test, testprog);
+ testprog.run ("-r %s".printf (test.name), cancellable);
+ result.add_success (test);
+ result.process_buffers (test, testprog);
} catch (IOError e) {
- result.add_error(test, "The test timed out after %d milliseconds".printf(timeout));
- result.process_buffers(test, testprog);
+ result.add_error (test, "The test timed out after %d milliseconds".printf (timeout));
+ result.process_buffers (test, testprog);
} catch (Error e) {
- result.add_error(test, e.message);
- result.process_buffers(test, testprog);
+ result.add_error (test, e.message);
+ result.process_buffers (test, testprog);
} finally {
- result.report();
+ result.report ();
_n_ongoing_tests--;
var wrapper = _pending_tests.pop_head ();
- if(wrapper != null)
- wrapper.cb();
+ if (wrapper != null)
+ wrapper.cb ();
}
}
-
+
public static int main (string[] args) {
try {
- var assembly = new TestAssembly(args);
- var testplan = new TestPlan(assembly);
- return testplan.run();
+ var assembly = new TestAssembly (args);
+ var testplan = new TestPlan (assembly);
+ return testplan.run ();
} catch (Error e) {
- error(e.message);
+ error (e.message);
}
}
-
+
}
diff --git a/valadate/testsuite.vala b/valadate/testsuite.vala
index 6b0239c..bb4541e 100644
--- a/valadate/testsuite.vala
+++ b/valadate/testsuite.vala
@@ -22,7 +22,7 @@
public class Valadate.TestSuite : Object, Test {
- private List<Test> _tests = new List<Test>();
+ private List<Test> _tests = new List<Test> ();
/**
* the name of the TestSuite
*/
@@ -36,17 +36,17 @@ public class Valadate.TestSuite : Object, Test {
*/
public int size {
get {
- return (int)_tests.length();
+ return (int)_tests.length ();
}
}
/**
- * Returns the number of {@link Valadate.Test}s that will be run by
+ * Returns the number of {@link Valadate.Test}s that will be run by
* this TestSuite
*/
public int count {
get {
int testcount = 0;
- _tests.foreach((t) => {
+ _tests.foreach ((t) => {
testcount += t.count;
});
return testcount;
@@ -71,41 +71,41 @@ public class Valadate.TestSuite : Object, Test {
* The public constructor takes an optional string parameter for the
* TestSuite's name
*/
- public TestSuite(string? name = null) {
- this.name = name ?? this.get_type().name();
+ public TestSuite (string? name = null) {
+ this.name = name ?? this.get_type ().name ();
this.label = name;
}
/**
* Adds a test to the suite.
*/
- public void add_test(Test test) {
+ public void add_test (Test test) {
test.parent = this;
- _tests.append(test);
+ _tests.append (test);
}
/**
* Runs all of the tests in the Suite
*/
public void run (TestResult result) {
- if(status != TestStatus.NOT_RUN)
+ if (status != TestStatus.NOT_RUN)
return;
- _tests.foreach((t) => {
- t.run(result);
+ _tests.foreach ((t) => {
+ t.run (result);
});
}
- public new Test get(int index) {
- return _tests.nth_data((uint)index);
+ public new Test get (int index) {
+ return _tests.nth_data ((uint)index);
}
- public new void set(int index, Test test) {
+ public new void set (int index, Test test) {
test.parent = this;
- _tests.insert_before(_tests.nth(index), test);
- var t = _tests.nth_data((uint)index++);
- _tests.remove(t);
+ _tests.insert_before (_tests.nth (index), test);
+ var t = _tests.nth_data ((uint)index++);
+ _tests.remove (t);
}
- public virtual void set_up() {}
- public virtual void tear_down() {}
+ public virtual void set_up () {}
+ public virtual void tear_down () {}
}
diff --git a/valadate/xmlfile.vala b/valadate/xmlfile.vala
index 682f6a2..28bb3f7 100644
--- a/valadate/xmlfile.vala
+++ b/valadate/xmlfile.vala
@@ -1,17 +1,17 @@
/*
* Valadate - Unit testing library for GObject-based libraries.
* Copyright 2016 Chris Daley <chebizarro gmail com>
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program 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 General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
@@ -25,85 +25,85 @@ public errordomain Valadate.XmlFileError {
}
public class Valadate.XmlSearchResults {
-
+
private Xml.XPath.Object* result;
public int size {
get {
- if(result == null || result->type != Xml.XPath.ObjectType.NODESET ||
result->nodesetval == null)
+ if (result == null || result->type != Xml.XPath.ObjectType.NODESET ||
result->nodesetval == null)
return 0;
- return result->nodesetval->length();
+ return result->nodesetval->length ();
}
}
- public void* get(int i)
- requires(size > 0)
- requires(i < size)
- requires(i >= 0)
+ public void* get (int i)
+ requires (size > 0)
+ requires (i < size)
+ requires (i >= 0)
{
return result->nodesetval->item (i);
}
-
-
- internal XmlSearchResults(Xml.XPath.Object* result) {
+
+
+ internal XmlSearchResults (Xml.XPath.Object* result) {
this.result = result;
}
- ~XmlSearchResults() {
- if(result != null) delete result;
+ ~XmlSearchResults () {
+ if (result != null) delete result;
}
}
public class Valadate.XmlFile {
-
+
private Xml.Doc* document;
private Xml.XPath.Context context;
private bool owns_doc = false;
-
- public XmlFile(File path) throws Error {
- this.from_doc(Xml.Parser.parse_file(path.get_path()));
+
+ public XmlFile (File path) throws Error {
+ this.from_doc (Xml.Parser.parse_file (path.get_path ()));
owns_doc = true;
}
- internal XmlFile.from_doc(Xml.Doc* xmldoc) throws Error {
+ internal XmlFile.from_doc (Xml.Doc* xmldoc) throws Error {
document = xmldoc;
owns_doc = true;
if (document == null)
- throw new XmlFileError.ERROR(
+ throw new XmlFileError.ERROR (
"There was an error parsing the Xml.Doc");
- set_context();
+ set_context ();
}
- public XmlFile.from_string(string xml) throws Error {
- document = Xml.Parser.read_memory(xml, xml.length, null, null,
+ public XmlFile.from_string (string xml) throws Error {
+ document = Xml.Parser.read_memory (xml, xml.length, null, null,
Xml.ParserOption.RECOVER | Xml.ParserOption.NOERROR |
Xml.ParserOption.NOWARNING | Xml.ParserOption.NOBLANKS);
owns_doc = true;
if (document == null)
- throw new XmlFileError.ERROR(
+ throw new XmlFileError.ERROR (
"There was an error parsing the string %s", xml);
- set_context();
+ set_context ();
}
- private void set_context() {
+ private void set_context () {
context = new Xml.XPath.Context (document);
}
- ~XmlFile() {
+ ~XmlFile () {
if (owns_doc)
delete document;
}
- public void register_ns(string prefix, string ns) {
- context.register_ns(prefix, ns);
+ public void register_ns (string prefix, string ns) {
+ context.register_ns (prefix, ns);
}
- public XmlSearchResults eval(string expression) {
- return new XmlSearchResults(context.eval_expression (expression));
+ public XmlSearchResults eval (string expression) {
+ return new XmlSearchResults (context.eval_expression (expression));
}
-
+
}
diff --git a/valadate/xmltestreportprinter.vala b/valadate/xmltestreportprinter.vala
index e389c7d..dc6e754 100644
--- a/valadate/xmltestreportprinter.vala
+++ b/valadate/xmltestreportprinter.vala
@@ -1,33 +1,33 @@
/*
* Valadate - Unit testing library for GObject-based libraries.
* Copyright (C) 2017 Chris Daley <chebizarro gmail com>
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program 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 General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; 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.XmlTestReportPrinter : TestReportPrinter {
-
+
private const string XML_DECL ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
private const string TESTSUITES_XML =
"""<testsuites disabled="" errors="" failures="" name="" """ +
"""tests="" time=""></testsuites>""";
-
+
public XmlFile xml {get;set;}
private Xml.Node* testsuite;
@@ -35,36 +35,36 @@ public class Valadate.XmlTestReportPrinter : TestReportPrinter {
private int testcount = -1;
private int casecount = -1;
- public XmlTestReportPrinter(TestConfig config) throws Error {
- base(config);
+ public XmlTestReportPrinter (TestConfig config) throws Error {
+ base (config);
this.config = config;
- xml = new XmlFile.from_string(XML_DECL + TESTSUITES_XML);
+ xml = new XmlFile.from_string (XML_DECL + TESTSUITES_XML);
}
- public override void print(TestReport report) {
- Xml.Node* root = xml.eval("//testsuites")[0];
- Xml.Node* node = report.xml.eval("//testsuite | //testcase")[0];
+ public override void print (TestReport report) {
+ Xml.Node* root = xml.eval ("//testsuites")[0];
+ Xml.Node* node = report.xml.eval ("//testsuite | //testcase")[0];
- if(report.test is TestSuite) {
- if(testsuite == null) {
+ if (report.test is TestSuite) {
+ if (testsuite == null) {
testcount = report.test.count;
- testsuite = root->add_child(node->copy_list());
+ testsuite = root->add_child (node->copy_list ());
} else {
oldtestsuite = testsuite;
- testsuite = testsuite->add_child(node->copy_list());
+ testsuite = testsuite->add_child (node->copy_list ());
}
} else if (report.test is TestCase) {
oldtestsuite = testsuite;
- testsuite = testsuite->add_child(node->copy_list());
+ testsuite = testsuite->add_child (node->copy_list ());
casecount = report.test.count;
- } else if(report.test is TestAdapter) {
- testsuite->add_child(node->copy_list());
+ } else if (report.test is TestAdapter) {
+ testsuite->add_child (node->copy_list ());
testcount--;
casecount--;
- if(casecount == 0)
+ if (casecount == 0)
testsuite = oldtestsuite;
- }
- if(testcount == 0)
- root->doc->dump_format(stdout);
+ }
+ if (testcount == 0)
+ root->doc->dump_format (stdout);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]