Back to index

enigmail  1.4.3
xpccheck.py
Go to the documentation of this file.
00001 # ***** BEGIN LICENSE BLOCK *****
00002 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003 #
00004 # The contents of this file are subject to the Mozilla Public License Version
00005 # 1.1 (the "License"); you may not use this file except in compliance with
00006 # the License. You may obtain a copy of the License at
00007 # http://www.mozilla.org/MPL/
00008 #
00009 # Software distributed under the License is distributed on an "AS IS" basis,
00010 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011 # for the specific language governing rights and limitations under the
00012 # License.
00013 #
00014 # The Original Code is Mozilla build system.
00015 #
00016 # The Initial Developer of the Original Code is
00017 # Mozilla Foundation.
00018 # Portions created by the Initial Developer are Copyright (C) 2011
00019 # the Initial Developer. All Rights Reserved.
00020 #
00021 # Contributor(s):
00022 #  Joel Maher <joel.maher@gmail.com>
00023 #
00024 # Alternatively, the contents of this file may be used under the terms of
00025 # either the GNU General Public License Version 2 or later (the "GPL"), or
00026 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027 # in which case the provisions of the GPL or the LGPL are applicable instead
00028 # of those above. If you wish to allow use of your version of this file only
00029 # under the terms of either the GPL or the LGPL, and not to allow others to
00030 # use your version of this file under the terms of the MPL, indicate your
00031 # decision by deleting the provisiwons above and replace them with the notice
00032 # and other provisions required by the GPL or the LGPL. If you do not delete
00033 # the provisions above, a recipient may use your version of this file under
00034 # the terms of any one of the MPL, the GPL or the LGPL.
00035 #
00036 # ***** END LICENSE BLOCK *****
00037 
00038 '''A generic script to verify all test files are in the 
00039 corresponding .ini file.
00040 
00041 Usage: xpccheck.py <directory> [<directory> ...]
00042 '''
00043 
00044 import sys
00045 import os
00046 from glob import glob
00047 import manifestparser
00048 
00049 class srcManifestParser(manifestparser.ManifestParser):
00050   def __init__(self, manifests=(), defaults=None, strict=True, testroot=None):
00051     self.testroot = testroot
00052     manifestparser.ManifestParser.__init__(self, manifests, defaults, strict)
00053 
00054   def getRelativeRoot(self, here):
00055     if self.testroot is None:
00056         return manifestparser.ManifestParser.getRelativeRoot(self, self.rootdir)
00057     return self.testroot
00058 
00059 
00060 def getIniTests(testdir):
00061   mp = manifestparser.ManifestParser(strict=False)
00062   mp.read(os.path.join(testdir, 'xpcshell.ini'))
00063   return mp.tests
00064 
00065 def verifyDirectory(initests, directory):
00066   files = glob(os.path.join(os.path.abspath(directory), "test_*"))
00067   for f in files:
00068     if (not os.path.isfile(f)):
00069       continue
00070 
00071     name = os.path.basename(f)
00072     if name.endswith('.in'):
00073       name = name[:-3]
00074 
00075     if not name.endswith('.js'):
00076       continue
00077 
00078     found = False
00079     for test in initests:
00080       if os.path.join(os.path.abspath(directory), name) == test['path']:
00081         found = True
00082         break
00083    
00084     if not found:
00085       print >>sys.stderr, "TEST-UNEXPECTED-FAIL | xpccheck | test %s is missing from test manifest %s!" % (name, os.path.join(directory, 'xpcshell.ini'))
00086       sys.exit(1)
00087 
00088 def verifyIniFile(initests, directory):
00089   files = glob(os.path.join(os.path.abspath(directory), "test_*"))
00090   for test in initests:
00091     name = test['path'].split('/')[-1]
00092 
00093     found = False
00094     for f in files:
00095 
00096       fname = f.split('/')[-1]
00097       if fname.endswith('.in'):
00098         fname = '.in'.join(fname.split('.in')[:-1])
00099 
00100       if os.path.join(os.path.abspath(directory), fname) == test['path']:
00101         found = True
00102         break
00103 
00104     if not found:
00105       print >>sys.stderr, "TEST-UNEXPECTED-FAIL | xpccheck | found %s in xpcshell.ini and not in directory '%s'" % (name, directory)
00106       sys.exit(1)
00107 
00108 def verifyMasterIni(mastername, topsrcdir, directory):
00109   mp = srcManifestParser(strict=False, testroot=topsrcdir)
00110   mp.read(mastername)
00111   tests = mp.tests
00112 
00113   found = False
00114   for test in tests:
00115     if test['manifest'] == os.path.abspath(os.path.join(directory, 'xpcshell.ini')):
00116       found = True
00117       break
00118 
00119   if not found:
00120     print >>sys.stderr, "TEST-UNEXPECTED-FAIL | xpccheck | directory %s is missing from master xpcshell.ini file %s" % (directory, mastername)
00121     sys.exit(1)
00122 
00123 
00124 if __name__ == '__main__':
00125   if len(sys.argv) < 4:
00126     print >>sys.stderr, "Usage: xpccheck.py <topsrcdir> <path/master.ini> <directory> [<directory> ...]"
00127     sys.exit(1)
00128 
00129   topsrcdir = sys.argv[1]
00130   for d in sys.argv[3:]:
00131     # xpcshell-unpack is a copy of xpcshell sibling directory and in the Makefile
00132     # we copy all files (including xpcshell.ini from the sibling directory.
00133     if d.endswith('toolkit/mozapps/extensions/test/xpcshell-unpack'):
00134       continue
00135 
00136     initests = getIniTests(d)
00137     verifyDirectory(initests, d)
00138     verifyIniFile(initests, d)
00139     verifyMasterIni(sys.argv[2], topsrcdir, d)
00140 
00141