/webkit-efl/Tools/Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py

https://review.tizen.org/git/ · Python · 259 lines · 196 code · 35 blank · 28 comment · 0 complexity · 6e87e79de88f630155fa1c8d0b26f514 MD5 · raw file

  1. # Copyright (C) 2011 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. '''Unit tests for watchlistparser.py.'''
  29. import logging
  30. import sys
  31. from webkitpy.common import webkitunittest
  32. from webkitpy.common.system.outputcapture import OutputCapture
  33. from webkitpy.common.watchlist.watchlistparser import WatchListParser
  34. class WatchListParserTest(webkitunittest.TestCase):
  35. def setUp(self):
  36. webkitunittest.TestCase.setUp(self)
  37. self._watch_list_parser = WatchListParser()
  38. def test_bad_section(self):
  39. watch_list = ('{"FOO": {}}')
  40. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  41. expected_logs='Unknown section "FOO" in watch list.\n')
  42. def test_section_typo(self):
  43. watch_list = ('{"DEFINTIONS": {}}')
  44. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  45. expected_logs='Unknown section "DEFINTIONS" in watch list.'
  46. + '\n\nPerhaps it should be DEFINITIONS.\n')
  47. def test_bad_definition(self):
  48. watch_list = (
  49. '{'
  50. ' "DEFINITIONS": {'
  51. ' "WatchList1|A": {'
  52. ' "filename": r".*\\MyFileName\\.cpp",'
  53. ' },'
  54. ' },'
  55. '}')
  56. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  57. expected_logs='Invalid character "|" in definition "WatchList1|A".\n')
  58. def test_bad_filename_regex(self):
  59. watch_list = (
  60. '{'
  61. ' "DEFINITIONS": {'
  62. ' "WatchList1": {'
  63. ' "filename": r"*",'
  64. ' "more": r"RefCounted",'
  65. ' },'
  66. ' },'
  67. ' "CC_RULES": {'
  68. ' "WatchList1": ["levin@chromium.org"],'
  69. ' },'
  70. '}')
  71. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  72. expected_logs='The regex "*" is invalid due to "nothing to repeat".\n')
  73. def test_bad_more_regex(self):
  74. watch_list = (
  75. '{'
  76. ' "DEFINITIONS": {'
  77. ' "WatchList1": {'
  78. ' "filename": r"aFileName\\.cpp",'
  79. ' "more": r"*",'
  80. ' },'
  81. ' },'
  82. ' "CC_RULES": {'
  83. ' "WatchList1": ["levin@chromium.org"],'
  84. ' },'
  85. '}')
  86. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  87. expected_logs='The regex "*" is invalid due to "nothing to repeat".\n')
  88. def test_bad_match_type(self):
  89. watch_list = (
  90. '{'
  91. ' "DEFINITIONS": {'
  92. ' "WatchList1": {'
  93. ' "nothing_matches_this": r".*\\MyFileName\\.cpp",'
  94. ' "filename": r".*\\MyFileName\\.cpp",'
  95. ' },'
  96. ' },'
  97. ' "CC_RULES": {'
  98. ' "WatchList1": ["levin@chromium.org"],'
  99. ' },'
  100. '}')
  101. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  102. expected_logs='Unknown pattern type "nothing_matches_this" in definition "WatchList1".\n')
  103. def test_match_type_typo(self):
  104. watch_list = (
  105. '{'
  106. ' "DEFINITIONS": {'
  107. ' "WatchList1": {'
  108. ' "iflename": r".*\\MyFileName\\.cpp",'
  109. ' "more": r"RefCounted",'
  110. ' },'
  111. ' },'
  112. ' "CC_RULES": {'
  113. ' "WatchList1": ["levin@chromium.org"],'
  114. ' },'
  115. '}')
  116. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  117. expected_logs='Unknown pattern type "iflename" in definition "WatchList1".'
  118. + '\n\nPerhaps it should be filename.\n')
  119. def test_empty_definition(self):
  120. watch_list = (
  121. '{'
  122. ' "DEFINITIONS": {'
  123. ' "WatchList1": {'
  124. ' },'
  125. ' },'
  126. ' "CC_RULES": {'
  127. ' "WatchList1": ["levin@chromium.org"],'
  128. ' },'
  129. '}')
  130. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  131. expected_logs='The definition "WatchList1" has no patterns, so it should be deleted.\n')
  132. def test_empty_cc_rule(self):
  133. watch_list = (
  134. '{'
  135. ' "DEFINITIONS": {'
  136. ' "WatchList1": {'
  137. ' "filename": r".*\\MyFileName\\.cpp",'
  138. ' },'
  139. ' },'
  140. ' "CC_RULES": {'
  141. ' "WatchList1": [],'
  142. ' },'
  143. '}')
  144. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  145. expected_logs='A rule for definition "WatchList1" is empty, so it should be deleted.\n'
  146. + 'The following definitions are not used and should be removed: WatchList1\n')
  147. def test_cc_rule_with_invalid_email(self):
  148. watch_list = (
  149. '{'
  150. ' "DEFINITIONS": {'
  151. ' "WatchList1": {'
  152. ' "filename": r".*\\MyFileName\\.cpp",'
  153. ' },'
  154. ' },'
  155. ' "CC_RULES": {'
  156. ' "WatchList1": ["levin+bad+email@chromium.org"],'
  157. ' },'
  158. '}')
  159. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  160. expected_logs='The email alias levin+bad+email@chromium.org which is'
  161. + ' in the watchlist is not listed as a contributor in committers.py\n')
  162. def test_empty_message_rule(self):
  163. watch_list = (
  164. '{'
  165. ' "DEFINITIONS": {'
  166. ' "WatchList1": {'
  167. ' "filename": r".*\\MyFileName\\.cpp",'
  168. ' },'
  169. ' },'
  170. ' "MESSAGE_RULES": {'
  171. ' "WatchList1": ['
  172. ' ],'
  173. ' },'
  174. '}')
  175. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  176. expected_logs='A rule for definition "WatchList1" is empty, so it should be deleted.\n'
  177. + 'The following definitions are not used and should be removed: WatchList1\n')
  178. def test_unused_defintion(self):
  179. watch_list = (
  180. '{'
  181. ' "DEFINITIONS": {'
  182. ' "WatchList1": {'
  183. ' "filename": r".*\\MyFileName\\.cpp",'
  184. ' },'
  185. ' },'
  186. '}')
  187. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  188. expected_logs='The following definitions are not used and should be removed: WatchList1\n')
  189. def test_cc_rule_with_undefined_defintion(self):
  190. watch_list = (
  191. '{'
  192. ' "CC_RULES": {'
  193. ' "WatchList1": ["levin@chromium.org"]'
  194. ' },'
  195. '}')
  196. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  197. expected_logs='In section "CC_RULES", the following definitions are not used and should be removed: WatchList1\n')
  198. def test_message_rule_with_undefined_defintion(self):
  199. watch_list = (
  200. '{'
  201. ' "MESSAGE_RULES": {'
  202. ' "WatchList1": ["The message."]'
  203. ' },'
  204. '}')
  205. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  206. expected_logs='In section "MESSAGE_RULES", the following definitions are not used and should be removed: WatchList1\n')
  207. def test_cc_rule_with_undefined_defintion_with_suggestion(self):
  208. watch_list = (
  209. '{'
  210. ' "DEFINITIONS": {'
  211. ' "WatchList1": {'
  212. ' "filename": r".*\\MyFileName\\.cpp",'
  213. ' },'
  214. ' },'
  215. ' "CC_RULES": {'
  216. ' "WatchList": ["levin@chromium.org"]'
  217. ' },'
  218. ' "MESSAGE_RULES": {'
  219. ' "WatchList1": ["levin@chromium.org"]'
  220. ' },'
  221. '}')
  222. OutputCapture().assert_outputs(self, self._watch_list_parser.parse, args=[watch_list],
  223. expected_logs='In section "CC_RULES", the following definitions are not used and should be removed: WatchList'
  224. + '\n\nPerhaps it should be WatchList1.\n')