test_expectations.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Copyright (C) 2010 Google Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are
  5. # met:
  6. #
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above
  10. # copyright notice, this list of conditions and the following disclaimer
  11. # in the documentation and/or other materials provided with the
  12. # distribution.
  13. # * Neither the name of Google Inc. nor the names of its
  14. # contributors may be used to endorse or promote products derived from
  15. # this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. """Checks WebKit style for test_expectations files."""
  29. import logging
  30. import optparse
  31. import os
  32. import re
  33. import sys
  34. from common import TabChecker
  35. from webkitpy.common.host import Host
  36. from webkitpy.layout_tests.models.test_expectations import TestExpectationParser
  37. _log = logging.getLogger(__name__)
  38. class TestExpectationsChecker(object):
  39. """Processes TestExpectations lines for validating the syntax."""
  40. categories = set(['test/expectations'])
  41. def _determine_port_from_expectations_path(self, host, expectations_path):
  42. # Pass a configuration to avoid calling default_configuration() when initializing the port (takes 0.5 seconds on a Mac Pro!).
  43. options_wk1 = optparse.Values({'configuration': 'Release', 'webkit_test_runner': False})
  44. options_wk2 = optparse.Values({'configuration': 'Release', 'webkit_test_runner': True})
  45. for port_name in host.port_factory.all_port_names():
  46. ports = [host.port_factory.get(port_name, options=options_wk1), host.port_factory.get(port_name, options=options_wk2)]
  47. for port in ports:
  48. for test_expectation_file in port.expectations_files():
  49. if test_expectation_file.replace(port.path_from_webkit_base() + host.filesystem.sep, '') == expectations_path:
  50. return port
  51. return None
  52. def __init__(self, file_path, handle_style_error, host=None):
  53. self._file_path = file_path
  54. self._handle_style_error = handle_style_error
  55. self._tab_checker = TabChecker(file_path, handle_style_error)
  56. # FIXME: host should be a required parameter, not an optional one.
  57. host = host or Host()
  58. host.initialize_scm()
  59. self._port_obj = self._determine_port_from_expectations_path(host, file_path)
  60. # Suppress error messages of test_expectations module since they will be reported later.
  61. log = logging.getLogger("webkitpy.layout_tests.layout_package.test_expectations")
  62. log.setLevel(logging.CRITICAL)
  63. def _handle_error_message(self, lineno, message, confidence):
  64. pass
  65. def check_test_expectations(self, expectations_str, tests=None):
  66. parser = TestExpectationParser(self._port_obj, tests, allow_rebaseline_modifier=False)
  67. expectations = parser.parse('expectations', expectations_str)
  68. level = 5
  69. for expectation_line in expectations:
  70. for warning in expectation_line.warnings:
  71. self._handle_style_error(expectation_line.line_number, 'test/expectations', level, warning)
  72. def check_tabs(self, lines):
  73. self._tab_checker.check(lines)
  74. def check(self, lines):
  75. expectations = '\n'.join(lines)
  76. if self._port_obj:
  77. self.check_test_expectations(expectations_str=expectations, tests=None)
  78. # Warn tabs in lines as well
  79. self.check_tabs(lines)