diff --git a/bears/general/KeywordBear.py b/bears/general/KeywordBear.py index fabf10843f..d0689f9eeb 100644 --- a/bears/general/KeywordBear.py +++ b/bears/general/KeywordBear.py @@ -1,4 +1,5 @@ import re +import logging from coalib.bearlib import deprecate_settings from coalib.bears.LocalBear import LocalBear @@ -19,7 +20,11 @@ def _get_comments(dependency_results): return for result in annotation_bear_results: - yield from result.contents.get('comments', []) + if isinstance(result.contents, str): + logging.error(result.contents) + yield [] + else: + yield from result.contents.get('comments', []) def generate_diff(comments, file, filename, diff --git a/tests/general/KeywordBearTest.py b/tests/general/KeywordBearTest.py index 45c0c98307..05eb5a5067 100644 --- a/tests/general/KeywordBearTest.py +++ b/tests/general/KeywordBearTest.py @@ -3,6 +3,7 @@ import unittest from bears.general.KeywordBear import KeywordBear +from bears.general.AnnotationBear import AnnotationBear from coalib.results.HiddenResult import HiddenResult from coalib.results.SourceRange import SourceRange from coalib.settings.Section import Section @@ -214,3 +215,27 @@ def test_keyword_regex(self): self.assertEqual(result[0].message, 'The line contains the keyword' " 'Issue #123' which resulted " 'in a match with given regex.') + + def test_wrong_language(self): + section = Section('') + section.append(Setting('language', 'anything')) + section.append(Setting('keywords', 'TODO')) + uut = KeywordBear(section, Queue()) + uut1 = AnnotationBear(section, Queue()) + dep_results = { + 'AnnotationBear': HiddenResult( + 'AnnotationBear', + 'coalang specification for anything not found.') + } + + text = ['# todo 123'] + + with execute_bear(uut, 'F', text, + dependency_results=dep_results) as result: + self.assertEqual(result[0].diffs, {}) + self.assertEqual(result[0].affected_code[0].start.line, 1) + self.assertEqual(len(result), 1) + + with execute_bear(uut1, 'F', text) as result: + self.assertEqual(result[0].contents, + 'coalang specification for anything not found.')