зеркало из https://github.com/mozilla/pjs.git
Bug 687264 - add mochitest support for filtering tests. r=ctalbert
This commit is contained in:
Родитель
91912071f8
Коммит
e0cdbc7dcb
|
@ -236,9 +236,18 @@ class MochitestOptions(optparse.OptionParser):
|
|||
action = "store", type = "int",
|
||||
dest = "repeat", metavar = "REPEAT",
|
||||
help = "repeats the test or set of tests the given number of times, ie: repeat=1 will run the test twice.")
|
||||
|
||||
defaults["repeat"] = 0
|
||||
|
||||
self.add_option("--run-only-tests",
|
||||
action = "store", type="string", dest = "runOnlyTests",
|
||||
help = "JSON list of tests that we only want to run, cannot be specified with --exclude-tests.")
|
||||
defaults["runOnlyTests"] = None
|
||||
|
||||
self.add_option("--exclude-tests",
|
||||
action = "store", type="string", dest = "excludeTests",
|
||||
help = "JSON list of tests that we want to not run, cannot be specified with --run-only-tests.")
|
||||
defaults["excludeTests"] = None
|
||||
|
||||
# -h, --help are automatically handled by OptionParser
|
||||
|
||||
self.set_defaults(**defaults)
|
||||
|
@ -302,6 +311,17 @@ See <http://mochikit.com/doc/html/MochiKit/Logging.html> for details on the logg
|
|||
self.error("%s not found, cannot automate VMware recording." %
|
||||
mochitest.vmwareHelperPath)
|
||||
|
||||
if options.runOnlyTests != None and options.excludeTests != None:
|
||||
self.error("We can only support --run-only-tests OR --exclude-tests, not both.")
|
||||
|
||||
if (options.runOnlyTests):
|
||||
if (not os.path.exists(os.path.join(os.path.dirname(__file__), options.runOnlyTests))):
|
||||
self.error("unable to find --run-only-tests file '%s'" % (options.runOnlyTests));
|
||||
|
||||
if (options.excludeTests):
|
||||
if (not os.path.exists(os.path.join(os.path.dirname(__file__), options.excludeTests))):
|
||||
self.error("unable to find --exclude-tests file '%s'" % (options.excludeTests));
|
||||
|
||||
return options
|
||||
|
||||
|
||||
|
@ -581,6 +601,10 @@ class Mochitest(object):
|
|||
self.urlOpts.append("repeat=%d" % options.repeat)
|
||||
if os.path.isfile(os.path.join(self.oldcwd, os.path.dirname(__file__), self.TEST_PATH, options.testPath)) and options.repeat > 0:
|
||||
self.urlOpts.append("testname=%s" % ("/").join([self.TEST_PATH, options.testPath]))
|
||||
if options.runOnlyTests:
|
||||
self.urlOpts.append("runOnlyTests=%s" % options.runOnlyTests)
|
||||
elif options.excludeTests:
|
||||
self.urlOpts.append("excludeTests=%s" % options.excludeTests)
|
||||
|
||||
def cleanup(self, manifest, options):
|
||||
""" remove temporary files and profile """
|
||||
|
|
|
@ -135,6 +135,10 @@ if (!params.quiet) {
|
|||
var gTestList = [];
|
||||
var RunSet = {}
|
||||
RunSet.runall = function(e) {
|
||||
// Filter tests to include|exclude tests based on data in params.filter.
|
||||
// This allows for including or excluding tests from the gTestList
|
||||
gTestList = filterTests(params.runOnlyTests, params.excludeTests);
|
||||
|
||||
// Which tests we're going to run
|
||||
var my_tests = gTestList;
|
||||
|
||||
|
@ -213,6 +217,63 @@ RunSet.reloadAndRunAll = function(e) {
|
|||
}
|
||||
};
|
||||
|
||||
// Test Filtering Code
|
||||
|
||||
// Open the file referenced by runOnly|exclude and use that to compare against
|
||||
// gTestList. Return a modified version of gTestList
|
||||
function filterTests(runOnly, exclude) {
|
||||
var filteredTests = [];
|
||||
var filterFile = null;
|
||||
|
||||
if (runOnly) {
|
||||
filterFile = runOnly;
|
||||
} else if (exclude) {
|
||||
filterFile = exclude;
|
||||
}
|
||||
|
||||
if (filterFile == null)
|
||||
return gTestList;
|
||||
|
||||
var datafile = "http://mochi.test:8888/" + filterFile;
|
||||
var objXml = new XMLHttpRequest();
|
||||
objXml.open("GET",datafile,false);
|
||||
objXml.send(null);
|
||||
try {
|
||||
var filter = JSON.parse(objXml.responseText);
|
||||
} catch (ex) {
|
||||
dump("INFO | setup.js | error loading or parsing '" + datafile + "'\n");
|
||||
return gTestList;
|
||||
}
|
||||
|
||||
for (var i = 0; i < gTestList.length; ++i) {
|
||||
var test_path = gTestList[i];
|
||||
|
||||
//We use tmp_path to remove leading '/'
|
||||
var tmp_path = test_path.replace(/^\//, '');
|
||||
|
||||
var found = false;
|
||||
|
||||
for (var f in filter) {
|
||||
// Remove leading /tests/ if exists
|
||||
file = f.replace(/^\//, '')
|
||||
file = file.replace(/^tests\//, '')
|
||||
|
||||
// Match directory or filename, gTestList has tests/<path>
|
||||
if (tmp_path.match("^tests/" + file) != null) {
|
||||
if (runOnly)
|
||||
filteredTests.push(test_path);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (exclude && !found)
|
||||
filteredTests.push(test_path);
|
||||
}
|
||||
|
||||
return filteredTests;
|
||||
}
|
||||
|
||||
// UI Stuff
|
||||
function toggleVisible(elem) {
|
||||
toggleElementClass("invisible", elem);
|
||||
|
|
Загрузка…
Ссылка в новой задаче