Changeset 52790 in webkit


Ignore:
Timestamp:
Jan 5, 2010 12:47:34 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-01-05 Chris Jerdonek <chris.jerdonek@gmail.com>

Reviewed by Eric Seidel.

Minor improvements to test-webkit-scripts, as suggested
by an earlier review.

https://bugs.webkit.org/show_bug.cgi?id=33125

  • Scripts/test-webkit-scripts:
    • Used OptionParser class instead of getopt.getopt().
    • Created main() method for main block.
    • Enclosed functions in a class.
Location:
trunk/WebKitTools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r52789 r52790  
     12010-01-05  Chris Jerdonek  <chris.jerdonek@gmail.com>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Minor improvements to test-webkit-scripts, as suggested
     6        by an earlier review.
     7
     8        https://bugs.webkit.org/show_bug.cgi?id=33125
     9
     10        * Scripts/test-webkit-scripts:
     11          - Used OptionParser class instead of getopt.getopt().
     12          - Created main() method for __main__ block.
     13          - Enclosed functions in a class.
     14
    1152010-01-05  Chris Fleizach  <cfleizach@apple.com>
    216
  • trunk/WebKitTools/Scripts/test-webkit-scripts

    r52732 r52790  
    11#!/usr/bin/python
    22#
    3 # Copyright (C) 2009 Chris Jerdonek (chris.jerdonek@gmail.com)
     3# Copyright (C) 2009, 2010 Chris Jerdonek (chris.jerdonek@gmail.com)
    44#
    55# Redistribution and use in source and binary forms, with or without
     
    2929# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    3030
    31 """Tests WebKit Perl and Python scripts.
     31"""Run unit tests of WebKit's Perl and Python scripts."""
    3232
    33 Syntax: test-webkit-scripts [--all]
     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).
    3439
    35     --all    Runs all available tests, including those suppressed
    36              by default.
    37 """
    38 
    39 import getopt
    4040import os
    4141import subprocess
    4242import sys
     43from optparse import OptionParser
    4344
    44 def test_script(title, script_path, args=None):
    45     """Run the given test command."""
    46     print('Testing %s:' % title)
     45class ScriptsTester(object):
    4746
    48     call_args = [script_path]
    49     if args is not None:
    50         call_args.extend(args)
    51     subprocess.call(call_args)
    52     print(70 * "*") # dividing line
     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
     76        # FIXME: Display a cumulative indication of success or failure.
     77        #        In addition, call sys.exit() with 0 or 1 depending on that
     78        #        cumulative success or failure.
     79        print('Note: Perl and Python results appear separately above.')
     80
    5381
    5482if __name__ == '__main__':
    55 
    56     try:
    57         (opts, filenames) = getopt.getopt(sys.argv[1:], '', ['help', 'all'])
    58     except getopt.GetoptError:
    59         print(__doc__)
    60         sys.exit('Error: invalid option.')
    61 
    62     should_include_all = False
    63 
    64     for (opt, val) in opts:
    65         if opt == '--help':
    66             print(__doc__)
    67             sys.exit()
    68         elif opt == '--all':
    69             should_include_all = True
    70 
    71     # Use absolute paths so this script can be run from any directory.
    72     scripts_directory = sys.path[0]
    73 
    74     test_script('Perl scripts', os.path.join(scripts_directory, 'test-webkitperl'))
    75 
    76     test_script('Python scripts',
    77                 os.path.join(scripts_directory, 'test-webkitpy'),
    78                 ['--all'] if should_include_all else None)
    79 
    80     # FIXME: Display a cumulative indication of success or failure.
    81     #        In addition, call sys.exit() with 0 or 1 depending on that
    82     #        cumulative success or failure.
    83     print('Note: Perl and Python results appear separately above.')
     83    # The scripts directory is the directory containing this file.
     84    tester = ScriptsTester(os.path.dirname(__file__))
     85    tester.main()
Note: See TracChangeset for help on using the changeset viewer.