Bug 845676 - Remove most of the assertion annotations in the content/media mochitests...
[gecko.git] / build / xpccheck.py
blob3be74a1b66c1ce74faa7021dacc1308f17916939
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 '''A generic script to verify all test files are in the
6 corresponding .ini file.
8 Usage: xpccheck.py <directory> [<directory> ...]
9 '''
11 import sys
12 import os
13 from glob import glob
14 import manifestparser
16 class srcManifestParser(manifestparser.ManifestParser):
17 def __init__(self, manifests=(), defaults=None, strict=True, testroot=None):
18 self.testroot = testroot
19 manifestparser.ManifestParser.__init__(self, manifests, defaults, strict)
21 def getRelativeRoot(self, here):
22 if self.testroot is None:
23 return manifestparser.ManifestParser.getRelativeRoot(self, self.rootdir)
24 return self.testroot
27 def getIniTests(testdir):
28 mp = manifestparser.ManifestParser(strict=False)
29 mp.read(os.path.join(testdir, 'xpcshell.ini'))
30 return mp.tests
32 def verifyDirectory(initests, directory):
33 files = glob(os.path.join(os.path.abspath(directory), "test_*"))
34 for f in files:
35 if (not os.path.isfile(f)):
36 continue
38 name = os.path.basename(f)
39 if name.endswith('.in'):
40 name = name[:-3]
42 if not name.endswith('.js'):
43 continue
45 found = False
46 for test in initests:
47 if os.path.join(os.path.abspath(directory), name) == test['path']:
48 found = True
49 break
51 if not found:
52 print >>sys.stderr, "TEST-UNEXPECTED-FAIL | xpccheck | test %s is missing from test manifest %s!" % (name, os.path.join(directory, 'xpcshell.ini'))
53 sys.exit(1)
55 def verifyIniFile(initests, directory):
56 files = glob(os.path.join(os.path.abspath(directory), "test_*"))
57 for test in initests:
58 name = test['path'].split('/')[-1]
60 found = False
61 for f in files:
63 fname = f.split('/')[-1]
64 if fname.endswith('.in'):
65 fname = '.in'.join(fname.split('.in')[:-1])
67 if os.path.join(os.path.abspath(directory), fname) == test['path']:
68 found = True
69 break
71 if not found:
72 print >>sys.stderr, "TEST-UNEXPECTED-FAIL | xpccheck | found %s in xpcshell.ini and not in directory '%s'" % (name, directory)
73 sys.exit(1)
75 def verifyMasterIni(mastername, topsrcdir, directory):
76 mp = srcManifestParser(strict=False, testroot=topsrcdir)
77 mp.read(mastername)
78 tests = mp.tests
80 found = False
81 for test in tests:
82 if test['manifest'] == os.path.abspath(os.path.join(directory, 'xpcshell.ini')):
83 found = True
84 break
86 if not found:
87 print >>sys.stderr, "TEST-UNEXPECTED-FAIL | xpccheck | directory %s is missing from master xpcshell.ini file %s" % (directory, mastername)
88 sys.exit(1)
91 if __name__ == '__main__':
92 if len(sys.argv) < 4:
93 print >>sys.stderr, "Usage: xpccheck.py <topsrcdir> <path/master.ini> <directory> [<directory> ...]"
94 sys.exit(1)
96 topsrcdir = sys.argv[1]
97 for d in sys.argv[3:]:
98 # xpcshell-unpack is a copy of xpcshell sibling directory and in the Makefile
99 # we copy all files (including xpcshell.ini from the sibling directory.
100 if d.endswith('toolkit/mozapps/extensions/test/xpcshell-unpack'):
101 continue
103 initests = getIniTests(d)
104 verifyDirectory(initests, d)
105 verifyIniFile(initests, d)
106 verifyMasterIni(sys.argv[2], topsrcdir, d)