1 #!/usr/bin/python 2 # 3 # Copyright (C) 2009, 2010 Chris Jerdonek (chris.jerdonek (at] gmail.com) 4 # 5 # Redistribution and use in source and binary forms, with or without 6 # modification, are permitted provided that the following conditions are 7 # met: 8 # 9 # * Redistributions of source code must retain the above copyright 10 # notice, this list of conditions and the following disclaimer. 11 # * Redistributions in binary form must reproduce the above 12 # copyright notice, this list of conditions and the following disclaimer 13 # in the documentation and/or other materials provided with the 14 # distribution. 15 # * Neither the name of Apple Computer, Inc. ("Apple") nor the names of 16 # its contributors may be used to endorse or promote products derived 17 # from this software without specific prior written permission. 18 # 19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31 """Run unit tests of WebKit's Perl, Python, and Ruby scripts.""" 32 33 # The docstring above is passed as the "description" to the OptionParser 34 # used in this script's __main__ block. 35 # 36 # For the command options supported by this script, see the code below 37 # that instantiates the OptionParser class, or else pass --help 38 # while running this script (since argument help is auto-generated). 39 40 import os 41 import subprocess 42 import sys 43 from optparse import OptionParser 44 45 class ScriptsTester(object): 46 47 """Supports running unit tests of WebKit scripts.""" 48 49 def __init__(self, scripts_directory): 50 self.scripts_directory = scripts_directory 51 52 def script_path(self, script_file_name): 53 """Return an absolute path to the given script.""" 54 return os.path.join(self.scripts_directory, script_file_name) 55 56 def run_test_script(self, script_title, script_path, args=None): 57 """Run the given test script.""" 58 print('Testing %s:' % script_title) 59 call_args = [script_path] 60 if args: 61 call_args.extend(args) 62 subprocess.call(call_args) 63 print(70 * "*") # dividing line 64 65 def main(self): 66 parser = OptionParser(description=__doc__) 67 parser.add_option('-a', '--all', dest='all', action='store_true', 68 default=False, help='run all available tests, ' 69 'including those suppressed by default') 70 (options, args) = parser.parse_args() 71 72 self.run_test_script('Perl scripts', self.script_path('test-webkitperl')) 73 self.run_test_script('Python scripts', self.script_path('test-webkitpy'), 74 ['--all'] if options.all else None) 75 self.run_test_script('Ruby scripts', self.script_path('test-webkitruby')) 76 77 # FIXME: Display a cumulative indication of success or failure. 78 # In addition, call sys.exit() with 0 or 1 depending on that 79 # cumulative success or failure. 80 print('Note: Perl, Python, and Ruby results appear separately above.') 81 82 83 if __name__ == '__main__': 84 # The scripts directory is the directory containing this file. 85 tester = ScriptsTester(os.path.dirname(__file__)) 86 tester.main() 87