testing/mochitest/manifestLibrary.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/mochitest/manifestLibrary.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,148 @@
     1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +function parseTestManifest(testManifest, params, callback) {
    1.11 +  var links = {};
    1.12 +  var paths = [];
    1.13 +
    1.14 +  // Support --test-manifest format for mobile/b2g
    1.15 +  if ("runtests" in testManifest || "excludetests" in testManifest) {
    1.16 +    callback(testManifest);
    1.17 +    return;
    1.18 +  }
    1.19 +
    1.20 +  // For mochitest-chrome and mochitest-browser-chrome harnesses, we 
    1.21 +  // define tests as links[testname] = true.
    1.22 +  // For mochitest-plain, we define lists as an array of testnames.
    1.23 +  for (var obj of testManifest['tests']) {
    1.24 +    var path = obj['path'];
    1.25 +    // Note that obj.disabled may be "". We still want to skip in that case.
    1.26 +    if ("disabled" in obj) {
    1.27 +      dump("TEST-SKIPPED | " + path + " | " + obj.disabled + "\n");
    1.28 +      continue;
    1.29 +    }
    1.30 +    if (params.testRoot != 'tests' && params.testRoot !== undefined) {
    1.31 +      links[params.baseurl + '/' + params.testRoot + '/' + path] = true
    1.32 +    } else {
    1.33 +      paths.push(params.testPrefix + path);
    1.34 +    }
    1.35 +  }
    1.36 +  if (paths.length > 0) {
    1.37 +    callback(paths);
    1.38 +  } else {
    1.39 +    callback(links);
    1.40 +  }
    1.41 +}
    1.42 +
    1.43 +function getTestManifest(url, params, callback) {
    1.44 +  var req = new XMLHttpRequest();
    1.45 +  req.open("GET", url);
    1.46 +  req.onload = function() {
    1.47 +    if (req.readyState == 4) {
    1.48 +      if (req.status == 200) {
    1.49 +        try {
    1.50 +          parseTestManifest(JSON.parse(req.responseText), params, callback);
    1.51 +        } catch (e) {
    1.52 +          dump("TEST-UNEXPECTED-FAIL: setup.js | error parsing " + url + " (" + e + ")\n");
    1.53 +          throw e;
    1.54 +        }
    1.55 +      } else {
    1.56 +        dump("TEST-UNEXPECTED-FAIL: setup.js | error loading " + url + "\n");
    1.57 +        callback({});
    1.58 +      }
    1.59 +    }
    1.60 +  }
    1.61 +  req.send();
    1.62 +}
    1.63 +
    1.64 +// Test Filtering Code
    1.65 +
    1.66 +/*
    1.67 + Open the file referenced by runOnly|exclude and use that to compare against
    1.68 + testList
    1.69 + parameters:
    1.70 +   filter = json object of runtests | excludetests
    1.71 +   testList = array of test names to run
    1.72 +   runOnly = use runtests vs excludetests in case both are defined
    1.73 + returns:
    1.74 +   filtered version of testList
    1.75 +*/
    1.76 +function filterTests(filter, testList, runOnly) {
    1.77 +
    1.78 +  var filteredTests = [];
    1.79 +  var removedTests = [];
    1.80 +  var runtests = {};
    1.81 +  var excludetests = {};
    1.82 +
    1.83 +  if (filter == null) {
    1.84 +    return testList;
    1.85 +  }
    1.86 +
    1.87 +  if ('runtests' in filter) {
    1.88 +    runtests = filter.runtests;
    1.89 +  }
    1.90 +  if ('excludetests' in filter) {
    1.91 +    excludetests = filter.excludetests;
    1.92 +  }
    1.93 +  if (!('runtests' in filter) && !('excludetests' in filter)) {
    1.94 +    if (runOnly == 'true') {
    1.95 +      runtests = filter;
    1.96 +    } else {
    1.97 +      excludetests = filter;
    1.98 +    }
    1.99 +  }
   1.100 +
   1.101 +  var testRoot = config.testRoot || "tests";
   1.102 +  // Start with testList, and put everything that's in 'runtests' in
   1.103 +  // filteredTests.
   1.104 +  if (Object.keys(runtests).length) {
   1.105 +    for (var i = 0; i < testList.length; i++) {
   1.106 +      var testpath = testList[i];
   1.107 +      var tmppath = testpath.replace(/^\//, '');
   1.108 +      for (var f in runtests) {
   1.109 +        // Remove leading /tests/ if exists
   1.110 +        file = f.replace(/^\//, '')
   1.111 +        file = file.replace(/^tests\//, '')
   1.112 +
   1.113 +        // Match directory or filename, testList has <testroot>/<path>
   1.114 +        if (tmppath.match(testRoot + "/" + file) != null) {
   1.115 +          filteredTests.push(testpath);
   1.116 +          break;
   1.117 +        }
   1.118 +      }
   1.119 +    }
   1.120 +  } else {
   1.121 +    filteredTests = testList.slice(0);
   1.122 +  }
   1.123 +
   1.124 +  // Continue with filteredTests, and deselect everything that's in
   1.125 +  // excludedtests.
   1.126 +  if (!Object.keys(excludetests).length) {
   1.127 +    return filteredTests;
   1.128 +  }
   1.129 +
   1.130 +  var refilteredTests = [];
   1.131 +  for (var i = 0; i < filteredTests.length; i++) {
   1.132 +    var found = false;
   1.133 +    var testpath = filteredTests[i];
   1.134 +    var tmppath = testpath.replace(/^\//, '');
   1.135 +    for (var f in excludetests) {
   1.136 +      // Remove leading /tests/ if exists
   1.137 +      file = f.replace(/^\//, '')
   1.138 +      file = file.replace(/^tests\//, '')
   1.139 +
   1.140 +      // Match directory or filename, testList has <testroot>/<path>
   1.141 +      if (tmppath.match(testRoot + "/" + file) != null) {
   1.142 +        found = true;
   1.143 +        break;
   1.144 +      }
   1.145 +    }
   1.146 +    if (!found) {
   1.147 +      refilteredTests.push(testpath);
   1.148 +    }
   1.149 +  }
   1.150 +  return refilteredTests;
   1.151 +}

mercurial