https://bugs.webkit.org/show_bug.cgi?id=68976
Reviewed by Adam Barth.
* Scripts/webkitpy/common/watchlist/watchlistparser.py: Add suggestions
for typos and improve consistency of the error messages.
* Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py: Add tests
and improve the regex that were already present.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96232
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
2011-09-28 David Levin <levin@chromium.org>
+ watchlist: Suggest corrections for typos and improve error message consistency.
+ https://bugs.webkit.org/show_bug.cgi?id=68976
+
+ Reviewed by Adam Barth.
+
+ * Scripts/webkitpy/common/watchlist/watchlistparser.py: Add suggestions
+ for typos and improve consistency of the error messages.
+ * Scripts/webkitpy/common/watchlist/watchlistparser_unittest.py: Add tests
+ and improve the regex that were already present.
+
+2011-09-28 David Levin <levin@chromium.org>
+
watchlist: Add support for matching added or deleted lines.
https://bugs.webkit.org/show_bug.cgi?id=68972
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+import difflib
import re
from webkitpy.common.watchlist.changedlinepattern import ChangedLinePattern
from webkitpy.common.watchlist.filenamepattern import FilenamePattern
for section in dictionary:
parser = self._section_parsers.get(section)
if not parser:
- raise Exception('Unknown section "%s" in watch list.' % section)
+ raise Exception(('Unknown section "%s" in watch list.'
+ + self._suggest_words(section, self._section_parsers.keys()))
+ % section)
parser(dictionary[section], watch_list)
return watch_list
def _eval_watch_list(self, watch_list_contents):
return eval(watch_list_contents, {'__builtins__': None}, None)
+ def _suggest_words(self, invalid_word, valid_words):
+ close_matches = difflib.get_close_matches(invalid_word, valid_words)
+ if not close_matches:
+ return ''
+ return '\n\nPerhaps it should be %s.' % (' or '.join(close_matches))
+
def _parse_definition_section(self, definition_section, watch_list):
definitions = {}
for name in definition_section:
for pattern_type in definition:
pattern_parser = self._definition_pattern_parsers.get(pattern_type)
if not pattern_parser:
- raise Exception('Invalid pattern type "%s" in definition "%s".' % (pattern_type, name))
+ raise Exception(('Unknown pattern type "%s" in definition "%s".'
+ + self._suggest_words(pattern_type, self._definition_pattern_parsers.keys()))
+ % (pattern_type, name))
pattern = pattern_parser(definition[pattern_type])
definitions[name].append(pattern)
self.assertRaisesRegexp('Unknown section "FOO" in watch list.',
self._watch_list_parser.parse, watch_list_with_bad_section)
+ def test_section_typo(self):
+ watch_list_with_bad_section = ('{"DEFINTIONS": {}}')
+ self.assertRaisesRegexp(r'Unknown section "DEFINTIONS" in watch list\.\s*'
+ + r'Perhaps it should be DEFINITIONS\.',
+ self._watch_list_parser.parse, watch_list_with_bad_section)
+
def test_bad_definition(self):
watch_list_with_bad_definition = (
'{'
' },'
'}')
- self._verifyException('Invalid character "|" in definition "WatchList1|A".',
+ self._verifyException(r'Invalid character "\|" in definition "WatchList1\|A"\.',
self._watch_list_parser.parse, watch_list_with_bad_definition)
def test_bad_match_type(self):
' },'
'}')
- self._verifyException('Invalid pattern type "nothing_matches_this" in definition "WatchList1".',
+ self._verifyException('Unknown pattern type "nothing_matches_this" in definition "WatchList1".',
+ self._watch_list_parser.parse, watch_list_with_bad_match_type)
+
+ def test_match_type_typo(self):
+ watch_list_with_bad_match_type = (
+ '{'
+ ' "DEFINITIONS": {'
+ ' "WatchList1": {'
+ ' "iflename": r".*\\MyFileName\\.cpp",'
+ ' },'
+ ' },'
+ '}')
+
+ self._verifyException(r'Unknown pattern type "iflename" in definition "WatchList1"\.\s*'
+ + r'Perhaps it should be filename\.',
self._watch_list_parser.parse, watch_list_with_bad_match_type)