Bug 687264 - add mochitest support for filtering tests. r=ctalbert

This commit is contained in:
Joel Maher 2011-09-26 07:41:17 -04:00
Родитель 91912071f8
Коммит e0cdbc7dcb
2 изменённых файлов: 87 добавлений и 2 удалений

Просмотреть файл

@ -235,10 +235,19 @@ class MochitestOptions(optparse.OptionParser):
self.add_option("--repeat",
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.")
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);