blob: 48c5a36b57e008d2ac1825206cbb054c1eb22251 [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
[email protected]0066f732017-12-28 10:33:0814class CheckARCCompilationGuardTest(unittest.TestCase):
15 """Test the _CheckARCCompilationGuard presubmit check."""
16
17 def testGoodImplementationFiles(self):
18 """Test that .m and .mm files with a guard don't raise any errors."""
Gauthier Ambard7fc07bf2018-01-02 09:48:0919 lines = ["foobar"] + PRESUBMIT.ARC_COMPILE_GUARD
[email protected]0066f732017-12-28 10:33:0820 mock_input = PRESUBMIT_test_mocks.MockInputApi()
21 mock_input.files = [
Gauthier Ambard7fc07bf2018-01-02 09:48:0922 PRESUBMIT_test_mocks.MockFile('ios/path/foo_controller.mm', lines),
23 PRESUBMIT_test_mocks.MockFile('ios/path/foo_controller.m', lines),
[email protected]0066f732017-12-28 10:33:0824 ]
25 mock_output = PRESUBMIT_test_mocks.MockOutputApi()
26 errors = PRESUBMIT._CheckARCCompilationGuard(mock_input, mock_output)
27 self.assertEqual(len(errors), 0)
28
29 def testBadImplementationFiles(self):
30 """Test that .m and .mm files without a guard raise an error."""
Gauthier Ambard7fc07bf2018-01-02 09:48:0931 lines = ["foobar"]
[email protected]0066f732017-12-28 10:33:0832 mock_input = PRESUBMIT_test_mocks.MockInputApi()
33 mock_input.files = [
Gauthier Ambard7fc07bf2018-01-02 09:48:0934 PRESUBMIT_test_mocks.MockFile('ios/path/foo_controller.mm', lines),
35 PRESUBMIT_test_mocks.MockFile('ios/path/foo_controller.m', lines),
[email protected]0066f732017-12-28 10:33:0836 ]
37 mock_output = PRESUBMIT_test_mocks.MockOutputApi()
38 errors = PRESUBMIT._CheckARCCompilationGuard(mock_input, mock_output)
39 self.assertEqual(len(errors), 1)
40 self.assertEqual('error', errors[0].type)
41 self.assertTrue('ios/path/foo_controller.m' in errors[0].message)
42 self.assertTrue('ios/path/foo_controller.mm' in errors[0].message)
43
44 def testOtherFiles(self):
45 """Test that other files without a guard don't raise errors."""
Gauthier Ambard7fc07bf2018-01-02 09:48:0946 lines = ["foobar"]
[email protected]0066f732017-12-28 10:33:0847 mock_input = PRESUBMIT_test_mocks.MockInputApi()
48 mock_input.files = [
Gauthier Ambard7fc07bf2018-01-02 09:48:0949 PRESUBMIT_test_mocks.MockFile('ios/path/foo_controller.h', lines),
50 PRESUBMIT_test_mocks.MockFile('ios/path/foo_controller.cc', lines),
51 PRESUBMIT_test_mocks.MockFile('ios/path/BUILD.gn', lines),
[email protected]0066f732017-12-28 10:33:0852 ]
53 mock_output = PRESUBMIT_test_mocks.MockOutputApi()
54 errors = PRESUBMIT._CheckARCCompilationGuard(mock_input, mock_output)
55 self.assertEqual(len(errors), 0)
Sylvain Defresnefcda19f2017-06-27 10:14:0156
57class CheckTODOFormatTest(unittest.TestCase):
58 """Test the _CheckBugInToDo presubmit check."""
59
60 def testTODOs(self):
61 bad_lines = ['TO''DO(ldap): fix this',
62 'TO''DO(ladp): see crbug.com/8675309',
63 'TO''DO(8675309): fix this',
64 'TO''DO(http://crbug.com/8675309): fix this',
65 'TO''DO( crbug.com/8675309): fix this',
66 'TO''DO(crbug/8675309): fix this',
67 'TO''DO(crbug.com): fix this']
68 good_lines = ['TO''DO(crbug.com/8675309): fix this',
69 'TO''DO(crbug.com/8675309): fix this (please)']
70 mock_input = PRESUBMIT_test_mocks.MockInputApi()
71 mock_input.files = [PRESUBMIT_test_mocks.MockFile(
72 'ios/path/foo_controller.mm', bad_lines + good_lines)]
73 mock_output = PRESUBMIT_test_mocks.MockOutputApi()
74 errors = PRESUBMIT._CheckBugInToDo(mock_input, mock_output)
75 self.assertEqual(len(errors), 1)
76 self.assertEqual('error', errors[0].type)
77 self.assertTrue('without bug numbers' in errors[0].message)
78 error_lines = errors[0].message.split('\n')
79 self.assertEqual(len(error_lines), len(bad_lines) + 2)
80
81
82if __name__ == '__main__':
83 unittest.main()