test-webkit-scripts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/python
  2. #
  3. # Copyright (C) 2009, 2010 Chris Jerdonek (chris.jerdonek@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. """Run unit tests of WebKit's Perl, Python, and Ruby scripts."""
  31. # The docstring above is passed as the "description" to the OptionParser
  32. # used in this script's __main__ block.
  33. #
  34. # For the command options supported by this script, see the code below
  35. # that instantiates the OptionParser class, or else pass --help
  36. # while running this script (since argument help is auto-generated).
  37. import os
  38. import subprocess
  39. import sys
  40. from optparse import OptionParser
  41. class ScriptsTester(object):
  42. """Supports running unit tests of WebKit scripts."""
  43. def __init__(self, scripts_directory):
  44. self.scripts_directory = scripts_directory
  45. def script_path(self, script_file_name):
  46. """Return an absolute path to the given script."""
  47. return os.path.join(self.scripts_directory, script_file_name)
  48. def run_test_script(self, script_title, script_path, args=None):
  49. """Run the given test script."""
  50. print('Testing %s:' % script_title)
  51. call_args = [script_path]
  52. if args:
  53. call_args.extend(args)
  54. subprocess.call(call_args)
  55. print(70 * "*") # dividing line
  56. def main(self):
  57. parser = OptionParser(description=__doc__)
  58. parser.add_option('-a', '--all', dest='all', action='store_true',
  59. default=False, help='run all available tests, '
  60. 'including those suppressed by default')
  61. (options, args) = parser.parse_args()
  62. self.run_test_script('Perl scripts', self.script_path('test-webkitperl'))
  63. self.run_test_script('Python scripts', self.script_path('test-webkitpy'),
  64. ['--all'] if options.all else None)
  65. self.run_test_script('Ruby scripts', self.script_path('test-webkitruby'))
  66. # FIXME: Display a cumulative indication of success or failure.
  67. # In addition, call sys.exit() with 0 or 1 depending on that
  68. # cumulative success or failure.
  69. print('Note: Perl, Python, and Ruby results appear separately above.')
  70. if __name__ == '__main__':
  71. # The scripts directory is the directory containing this file.
  72. tester = ScriptsTester(os.path.dirname(__file__))
  73. tester.main()