blob: e50ff3de816fbc0ac3d380b585b431cebfff2f95 [file] [log] [blame]
Sylvain Defresnefcda19f2017-06-27 10:14:011# Copyright 2017 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import os
6import sys
7import unittest
8
9import PRESUBMIT
10
11sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
12import PRESUBMIT_test_mocks
13
14
15class CheckTODOFormatTest(unittest.TestCase):
16 """Test the _CheckBugInToDo presubmit check."""
17
18 def testTODOs(self):
19 bad_lines = ['TO''DO(ldap): fix this',
20 'TO''DO(ladp): see crbug.com/8675309',
21 'TO''DO(8675309): fix this',
22 'TO''DO(http://crbug.com/8675309): fix this',
23 'TO''DO( crbug.com/8675309): fix this',
24 'TO''DO(crbug/8675309): fix this',
25 'TO''DO(crbug.com): fix this']
26 good_lines = ['TO''DO(crbug.com/8675309): fix this',
27 'TO''DO(crbug.com/8675309): fix this (please)']
28 mock_input = PRESUBMIT_test_mocks.MockInputApi()
29 mock_input.files = [PRESUBMIT_test_mocks.MockFile(
30 'ios/path/foo_controller.mm', bad_lines + good_lines)]
31 mock_output = PRESUBMIT_test_mocks.MockOutputApi()
32 errors = PRESUBMIT._CheckBugInToDo(mock_input, mock_output)
33 self.assertEqual(len(errors), 1)
34 self.assertEqual('error', errors[0].type)
35 self.assertTrue('without bug numbers' in errors[0].message)
36 error_lines = errors[0].message.split('\n')
37 self.assertEqual(len(error_lines), len(bad_lines) + 2)
38
39
40if __name__ == '__main__':
41 unittest.main()