summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Daley <chebizarro@gmail.com>2017-04-30 20:04:28 -0700
committerRico Tzschichholz <ricotz@ubuntu.com>2017-11-19 12:35:04 +0100
commit7a53e2189dba7d8621029b096c9317a1bdc4b882 (patch)
tree9829fdf9fdf21472233b29abf52761095eace5e0
parent785284fa4a274106c832b489375c42d07d754ebb (diff)
downloadvala-7a53e2189dba7d8621029b096c9317a1bdc4b882.tar.gz
added ability to run tests in a given path with -p command line switch
-rw-r--r--tests/.gitignore2
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/valatests.vala40
-rw-r--r--valadate/taptestreportprinter.vala4
-rw-r--r--valadate/testadapter.vala3
-rw-r--r--valadate/testassembly.vala6
-rw-r--r--valadate/testconfig.vala10
-rw-r--r--valadate/testoptions.vala58
-rw-r--r--valadate/testplan.vala31
-rw-r--r--valadate/testrunner.vala4
10 files changed, 102 insertions, 58 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 53d758764..ba1d9d7a7 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -4,3 +4,5 @@
*.trs
valadatetests
valactests-*
+README
+gir/bug767718.test
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 87ca400bc..dea6eeada 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -14,6 +14,8 @@ TESTS_ENVIRONMENT += \
CPPFLAGS='$(CPPFLAGS)' \
LDFLAGS='$(LDFLAGS)'
+bin_PROGRAMS = valactests@PACKAGE_SUFFIX@
+
test_programs = valadatetests valactests@PACKAGE_SUFFIX@
# Valadate tests
diff --git a/tests/valatests.vala b/tests/valatests.vala
index 7a90d6594..d686eb710 100644
--- a/tests/valatests.vala
+++ b/tests/valatests.vala
@@ -24,10 +24,10 @@ public class Vala.Tests : Valadate.TestSuite {
construct {
try {
var testdir = File.new_for_path (GLib.Environment.get_variable ("G_TEST_BUILDDIR"));
- var testpath = Valadate.TestOptions.get_current_test_path ();
+ var running_test = Environment.get_variable ("V_RUNNING_TEST");
- if (testpath != null) {
- var testpaths = testpath.split ("/");
+ if (running_test != null) {
+ var testpaths = running_test.split ("/");
if (testpaths.length < 4)
return;
var runtest = testdir.get_child (testpaths[3]);
@@ -54,13 +54,33 @@ public class Vala.Tests : Valadate.TestSuite {
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(in_testpath("/Vala/Tests/%s".printf(file_info.get_name ())))
+ add_test (new ValaTest (testdir.get_child (file_info.get_name ())));
}
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
}
+ private static bool in_testpath (string path) {
+ var testpath = Environment.get_variable ("V_TESTPATH");
+ if (testpath == null)
+ return true;
+
+ var paths = path.split ("/");
+ var testpaths = testpath.split ("/");
+
+ for (int i=1; i<int.max (testpaths.length, paths.length); i++) {
+ if (testpaths[i] == null || paths[i] == null)
+ break;
+ if (testpaths[i] == "" || paths[i] == "")
+ break;
+ if (testpaths[i] != paths[i])
+ return false;
+ }
+ return true;
+ }
+
private class ValaTest : Valadate.TestCase {
private TestsFactory factory = TestsFactory.get_instance ();
@@ -70,7 +90,7 @@ public class Vala.Tests : Valadate.TestSuite {
this.label = directory.get_path ();
this.bug_base = BUGZILLA_URL;
- string current_test = Valadate.TestOptions.get_current_test_path ();
+ string current_test = Environment.get_variable ("V_RUNNING_TEST");
if (current_test != null) {
var basename = Path.get_basename (current_test);
@@ -94,12 +114,16 @@ public class Vala.Tests : Valadate.TestSuite {
private void load_test (File testfile) throws Error {
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 (
+ string label = "/Vala/Tests/%s/%s".printf (
Path.get_basename (testfile.get_parent ().get_path ()),
testname);
+ if(!in_testpath(label))
+ return;
+
+ var adapter = new Valadate.TestAdapter (testname, 1000);
+ adapter.label = label;
+
adapter.add_test_method (() => {
try {
if (testname.has_prefix ("bug"))
diff --git a/valadate/taptestreportprinter.vala b/valadate/taptestreportprinter.vala
index b0ab993c1..3d6fa58e4 100644
--- a/valadate/taptestreportprinter.vala
+++ b/valadate/taptestreportprinter.vala
@@ -31,6 +31,10 @@ internal class Valadate.TapTestReportPrinter : TestReportPrinter {
if (!config.list_only) {
stdout.printf ("TAP version %s\n", TAP_VERSION);
stdout.printf ("# random seed: %s\n", config.seed);
+
+ if (config.testpath != null)
+ stdout.printf ("# running tests in %s\n", config.testpath);
+
}
}
diff --git a/valadate/testadapter.vala b/valadate/testadapter.vala
index d20910ab6..e88b1cd5b 100644
--- a/valadate/testadapter.vala
+++ b/valadate/testadapter.vala
@@ -43,7 +43,8 @@ public class Valadate.TestAdapter : Object, Test {
}
}
- private TestCase.TestMethod test;
+ public TestCase.TestMethod test;
+
public Test? parent { get; set; }
public new Test get (int index) {
diff --git a/valadate/testassembly.vala b/valadate/testassembly.vala
index 181998785..718f69a9c 100644
--- a/valadate/testassembly.vala
+++ b/valadate/testassembly.vala
@@ -30,6 +30,12 @@ public class Valadate.TestAssembly : TestModule {
public TestAssembly (string[] args) throws Error {
base (File.new_for_path (args[0]));
options = new TestOptions (args);
+
+ if (options.testpath != null)
+ Environment.set_variable ("V_TESTPATH", options.testpath, true);
+ if (options.running_test != null)
+ Environment.set_variable ("V_RUNNING_TEST", options.running_test, true);
+
setup_dirs ();
}
diff --git a/valadate/testconfig.vala b/valadate/testconfig.vala
index 054f7c9d1..34faa1335 100644
--- a/valadate/testconfig.vala
+++ b/valadate/testconfig.vala
@@ -49,9 +49,9 @@ public class Valadate.TestConfig {
}
}
- public string[] testpaths {
+ public string? testpath {
get {
- return options.testpaths;
+ return options.testpath;
}
}
@@ -67,12 +67,6 @@ public class Valadate.TestConfig {
}
}
- public virtual bool run_async {
- get {
- return options.run_async;
- }
- }
-
public virtual bool list_only {
get {
return options.list;
diff --git a/valadate/testoptions.vala b/valadate/testoptions.vala
index 48557aa62..07d627e91 100644
--- a/valadate/testoptions.vala
+++ b/valadate/testoptions.vala
@@ -21,38 +21,25 @@
*/
public class Valadate.TestOptions {
- private static bool _async = true;
private static string _format = "tap";
private static bool _keepgoing = false;
private static bool _list;
- private static bool _quiet;
private static string _runtest = null;
- [CCode (array_length = false, array_null_terminated = true)]
- private static string[] _skip;
private static int _timeout = 60000;
private static string _seed;
private static bool _timed = true;
- private static string _testplan;
- private static bool _verbose;
private static bool _version;
- [CCode (array_length = false, array_null_terminated = true)]
- private static string[] _paths;
+ private static string _path = null;
public const OptionEntry[] options = {
- { "async", 'a', 0, OptionArg.NONE, ref _async, "Run tests asynchronously in a separate subprocess [Experimental]", null },
{ "format", 'f', 0, OptionArg.STRING, ref _format, "Output test results using format", "FORMAT" },
{ "", 'k', 0, OptionArg.NONE, ref _keepgoing, "Skip failed tests and continue running", null },
{ "list", 'l', 0, OptionArg.NONE, ref _list, "List test cases available in a test executable", null },
- { "quiet", 'q', 0, OptionArg.NONE, ref _quiet, "Run tests quietly", null },
{ "", 'r', 0, OptionArg.STRING, ref _runtest, null, null },
- { "skip", 's', 0, OptionArg.STRING_ARRAY, ref _skip, "Skip all tests matching", "TESTPATH..." },
{ "timeout", 't', 0, OptionArg.INT, ref _timeout, "Default timeout for tests", "MILLISECONDS" },
{ "seed", 0, 0, OptionArg.STRING, ref _seed, "Start tests with random seed", "SEEDSTRING" },
- { "timed", 0, 0, OptionArg.NONE, ref _timed, "Run timed tests", null },
- { "testplan", 0, 0, OptionArg.STRING, ref _testplan, "Run the specified TestPlan", "FILE" },
- { "verbose", 0, 0, OptionArg.NONE, ref _verbose, "Run tests verbosely", null },
{ "version", 0, 0, OptionArg.NONE, ref _version, "Display version number", null },
- { "", 0, 0, OptionArg.STRING_ARRAY, ref _paths, "Only start test cases matching", "TESTPATH..." },
+ { "path", 'p', 0, OptionArg.STRING, ref _path, "Only start test cases matching", "TESTPATH..." },
{ null }
};
@@ -80,12 +67,6 @@ public class Valadate.TestOptions {
}
}
- public bool run_async {
- get {
- return _async;
- }
- }
-
public bool list {
get {
return _list;
@@ -110,27 +91,32 @@ public class Valadate.TestOptions {
}
}
- public string[] testpaths {
+ public string? testpath {
get {
- return _paths;
+ return _path;
}
}
- public TestOptions (string[] args) throws OptionError {
+ public TestOptions (string[] args) {
_runtest = null;
- opt_context = new OptionContext ("- Valadate Testing Framework");
- opt_context.set_help_enabled (true);
- 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 ());
-
+ try {
+ opt_context = new OptionContext ("- Valadate Testing Framework");
+ opt_context.set_help_enabled (true);
+ 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 ());
+
+ } catch (OptionError e) {
+ stdout.printf ("%s\n", e.message);
+ stdout.printf ("Run '%s --help' to see a full list of available command line options.\n", args[0]);
+ }
}
}
diff --git a/valadate/testplan.vala b/valadate/testplan.vala
index d8dc66950..099c7d480 100644
--- a/valadate/testplan.vala
+++ b/valadate/testplan.vala
@@ -114,12 +114,17 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
public override void visit_class (Vala.Class cls) {
+ var label = "/%s".printf (cls.get_full_name ().replace (".","/"));
+
+ if(!in_testpath (label))
+ return;
+
try {
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 (".","/"));
+ testcase.label = label;
testsuite.add_test (testcase);
visit_testcase (cls);
@@ -132,6 +137,24 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
cls.accept_children (this);
}
+ private bool in_testpath (string path) {
+ if (config.testpath == null)
+ return true;
+
+ var paths = path.split ("/");
+ var testpaths = config.testpath.split ("/");
+
+ for (int i = 1; i < int.max (testpaths.length, paths.length); i++) {
+ if (testpaths[i] == null || paths[i] == null)
+ break;
+ if (testpaths[i] == "" || paths[i] == "")
+ break;
+ if (testpaths[i] != paths[i])
+ return false;
+ }
+ return true;
+ }
+
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))
@@ -156,9 +179,10 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
foreach (var method in cls.get_methods ()) {
+ var currpath = "%s/%s".printf (testcase.label, method.name);
+
if (config.in_subprocess)
- if (options.running_test != "%s/%s".printf (
- testcase.label, method.name))
+ if (options.running_test != currpath)
continue;
if (!is_test (method))
@@ -267,6 +291,7 @@ public class Valadate.TestPlan : Vala.CodeVisitor {
unowned Constructor meth = get_constructor (testclass);
var tsuite = meth () as TestSuite;
tsuite.name = testclass.name;
+ tsuite.label = "/%s".printf (testclass.get_full_name ().replace (".","/"));;
testsuite.add_test (tsuite);
testsuite = tsuite;
}
diff --git a/valadate/testrunner.vala b/valadate/testrunner.vala
index af9968b67..3aba022af 100644
--- a/valadate/testrunner.vala
+++ b/valadate/testrunner.vala
@@ -104,8 +104,8 @@ public class Valadate.TestRunner {
}
}
- 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 {
+
var timeout = plan.config.timeout;
var testprog = plan.assembly.clone ();
if (_n_ongoing_tests > _max_n_ongoing_tests) {