DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (5b81998bb7ab)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

'''A generic script to verify all test files are in the 
corresponding .ini file.

Usage: xpccheck.py <directory> [<directory> ...]
'''

import sys
import os
from glob import glob
import manifestparser

def getIniTests(testdir):
  mp = manifestparser.ManifestParser(strict=False)
  mp.read(os.path.join(testdir, 'xpcshell.ini'))
  return mp.tests

def verifyDirectory(initests, directory):
  files = glob(os.path.join(os.path.abspath(directory), "test_*"))
  for f in files:
    if (not os.path.isfile(f)):
      continue

    name = os.path.basename(f)
    if name.endswith('.in'):
      name = name[:-3]

    if not name.endswith('.js'):
      continue

    found = False
    for test in initests:
      if os.path.join(os.path.abspath(directory), name) == test['path']:
        found = True
        break
   
    if not found:
      print >>sys.stderr, "TEST-UNEXPECTED-FAIL | xpccheck | test %s is missing from test manifest %s!" % (name, os.path.join(directory, 'xpcshell.ini'))
      sys.exit(1)

def verifyIniFile(initests, directory):
  files = glob(os.path.join(os.path.abspath(directory), "test_*"))
  for test in initests:
    name = test['path'].split('/')[-1]

    found = False
    for f in files:

      fname = f.split('/')[-1]
      if fname.endswith('.in'):
        fname = '.in'.join(fname.split('.in')[:-1])

      if os.path.join(os.path.abspath(directory), fname) == test['path']:
        found = True
        break

    if not found:
      print >>sys.stderr, "TEST-UNEXPECTED-FAIL | xpccheck | found %s in xpcshell.ini and not in directory '%s'" % (name, directory)
      sys.exit(1)

if __name__ == '__main__':
  if len(sys.argv) < 3:
    print >>sys.stderr, "Usage: xpccheck.py <topsrcdir> <directory> [<directory> ...]"
    sys.exit(1)

  topsrcdir = sys.argv[1]
  for d in sys.argv[2:]:
    # xpcshell-unpack is a copy of xpcshell sibling directory and in the Makefile
    # we copy all files (including xpcshell.ini from the sibling directory.
    if d.endswith('toolkit/mozapps/extensions/test/xpcshell-unpack'):
      continue

    initests = getIniTests(d)
    verifyDirectory(initests, d)
    verifyIniFile(initests, d)