| """Tests for make_utils.""" |
| |
| from __future__ import absolute_import |
| import os |
| import sys |
| import unittest |
| |
| # Allow imports from cq/scripts folder |
| sys.path.insert( |
| 0, os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir))) |
| from helpers import make_utils |
| |
| |
| class MakeUtilsTest(unittest.TestCase): |
| |
| def testSingleError(self): |
| """Test the comments generated for a signle error.""" |
| make_output = ('path/to/warn.c:000:0: warning: This is just a warning.\n' |
| 'path/to/file.c:123:4: error: This is an error\n' |
| ' extra information for the erorr.\n' |
| 'some more lines that come later.\n') |
| directory = 'path/to' |
| |
| expected_comments = { |
| 'file.c': [{ |
| 'line': 123, |
| 'message': 'path/to/file.c:123:4: error: This is an error' |
| }] |
| } |
| |
| self.assertDictEqual( |
| expected_comments, |
| make_utils.make_error_to_comments(make_output, directory)) |
| |
| def testMultipleErrors(self): |
| """Test the comments generated from multiple different errors.""" |
| make_output = ('path/to/warn.c:000:0: warning: This is just a warning.\n' |
| 'path/to/file1.c:123:4: error: This is error 1\n' |
| ' extra information for the erorr.\n' |
| 'path/to/file1.c:456:7: error: This is error 2\n' |
| 'path/to/other/file3.c:1:1: error: This is error 3\n' |
| 'some more lines that come later.\n') |
| directory = 'path/to' |
| |
| expected_comments = { |
| 'file1.c': [{ |
| 'line': 123, |
| 'message': 'path/to/file1.c:123:4: error: This is error 1' |
| }, { |
| 'line': 456, |
| 'message': 'path/to/file1.c:456:7: error: This is error 2' |
| }], |
| 'other/file3.c': [{ |
| 'line': 1, |
| 'message': 'path/to/other/file3.c:1:1: error: This is error 3' |
| }] |
| } |
| |
| self.assertDictEqual( |
| expected_comments, |
| make_utils.make_error_to_comments(make_output, directory)) |
| |
| def testNoErrors(self): |
| """Test that no comments are generated if there are no errors.""" |
| make_output = ('path/to/warn.c:000:0: warning: This is just a warning.\n' |
| 'path/to/file.c:123:4: warning: This is another warning.\n' |
| ' extra information for the warning.\n' |
| 'Some more lines with something that is not an error\n') |
| directory = 'path/to' |
| |
| expected_comments = {} |
| |
| self.assertDictEqual( |
| expected_comments, |
| make_utils.make_error_to_comments(make_output, directory)) |
| |
| |
| if __name__ == '__main__': |
| unittest.main() |