Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(572)

Side by Side Diff: tests/presubmit_unittest.py

Issue 9756001: Allow 'class Singleton<T>' in header files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: add unit test Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py."""
7 7
8 # pylint: disable=E1101,E1103 8 # pylint: disable=E1101,E1103
9 9
10 import logging 10 import logging
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 'CheckChangeHasTestField', 1486 'CheckChangeHasTestField',
1487 'CheckChangeLintsClean', 1487 'CheckChangeLintsClean',
1488 'CheckChangeSvnEolStyle', 1488 'CheckChangeSvnEolStyle',
1489 'CheckChangeWasUploaded', 1489 'CheckChangeWasUploaded',
1490 'CheckDoNotSubmit', 1490 'CheckDoNotSubmit',
1491 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', 1491 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles',
1492 'CheckLongLines', 'CheckTreeIsOpen', 'PanProjectChecks', 1492 'CheckLongLines', 'CheckTreeIsOpen', 'PanProjectChecks',
1493 'CheckLicense', 1493 'CheckLicense',
1494 'CheckOwners', 1494 'CheckOwners',
1495 'CheckRietveldTryJobExecution', 1495 'CheckRietveldTryJobExecution',
1496 'CheckSingletonInHeaders',
1496 'CheckSvnModifiedDirectories', 1497 'CheckSvnModifiedDirectories',
1497 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty', 1498 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty',
1498 'RunPythonUnitTests', 'RunPylint', 1499 'RunPythonUnitTests', 'RunPylint',
1499 'RunUnitTests', 'RunUnitTestsInDirectory', 1500 'RunUnitTests', 'RunUnitTestsInDirectory',
1500 ] 1501 ]
1501 # If this test fails, you should add the relevant test. 1502 # If this test fails, you should add the relevant test.
1502 self.compareMembers(presubmit_canned_checks, members) 1503 self.compareMembers(presubmit_canned_checks, members)
1503 1504
1504 def DescriptionTest(self, check, description1, description2, error_type, 1505 def DescriptionTest(self, check, description1, description2, error_type,
1505 committing): 1506 committing):
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 'DO NOTSUBMIT', None, 'DO NOT ' + 'SUBMIT', None, 1691 'DO NOTSUBMIT', None, 'DO NOT ' + 'SUBMIT', None,
1691 presubmit.OutputApi.PresubmitError) 1692 presubmit.OutputApi.PresubmitError)
1692 1693
1693 def testCheckChangeHasNoStrayWhitespace(self): 1694 def testCheckChangeHasNoStrayWhitespace(self):
1694 self.ContentTest( 1695 self.ContentTest(
1695 lambda x,y,z: 1696 lambda x,y,z:
1696 presubmit_canned_checks.CheckChangeHasNoStrayWhitespace(x, y), 1697 presubmit_canned_checks.CheckChangeHasNoStrayWhitespace(x, y),
1697 'Foo', None, 'Foo ', None, 1698 'Foo', None, 'Foo ', None,
1698 presubmit.OutputApi.PresubmitPromptWarning) 1699 presubmit.OutputApi.PresubmitPromptWarning)
1699 1700
1701 def testCheckSingletonInHeaders(self):
1702 change1 = presubmit.Change(
1703 'foo1', 'foo1\n', self.fake_root_dir, None, 0, 0, None)
1704 input_api1 = self.MockInputApi(change1, False)
1705 affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile)
1706 affected_file2 = self.mox.CreateMock(presubmit.SvnAffectedFile)
1707 input_api1.AffectedSourceFiles(None).AndReturn(
1708 [affected_file1, affected_file2])
1709 affected_file1.LocalPath().AndReturn('foo.h')
1710 input_api1.ReadFile(affected_file1).AndReturn(
1711 '// Comment mentioning Singleton<Foo>.\n' +
1712 'friend class Singleton<Foo>;')
1713 for _ in range(4):
1714 affected_file2.LocalPath().AndReturn('foo.cc')
1715
1716 change2 = presubmit.Change(
1717 'foo2', 'foo2\n', self.fake_root_dir, None, 0, 0, None)
1718 input_api2 = self.MockInputApi(change2, False)
1719
1720 affected_file3 = self.mox.CreateMock(presubmit.SvnAffectedFile)
1721 input_api2.AffectedSourceFiles(None).AndReturn([affected_file3])
1722 affected_file3.LocalPath().AndReturn('foo.h')
1723 input_api2.ReadFile(affected_file3).AndReturn(
1724 'Foo* foo = Singleton<Foo>::get();')
1725
1726 self.mox.ReplayAll()
1727
1728 results1 = presubmit_canned_checks.CheckSingletonInHeaders(
1729 input_api1, presubmit.OutputApi)
1730 self.assertEquals(results1, [])
1731 results2 = presubmit_canned_checks.CheckSingletonInHeaders(
1732 input_api2, presubmit.OutputApi)
1733 self.assertEquals(len(results2), 1)
1734 self.assertEquals(results2[0].__class__, presubmit.OutputApi.PresubmitError)
1735
1700 def testCheckChangeHasOnlyOneEol(self): 1736 def testCheckChangeHasOnlyOneEol(self):
1701 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasOnlyOneEol, 1737 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasOnlyOneEol,
1702 "Hey!\nHo!\n", "Hey!\nHo!\n\n", 1738 "Hey!\nHo!\n", "Hey!\nHo!\n\n",
1703 presubmit.OutputApi.PresubmitPromptWarning) 1739 presubmit.OutputApi.PresubmitPromptWarning)
1704 1740
1705 def testCheckChangeHasNoCR(self): 1741 def testCheckChangeHasNoCR(self):
1706 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasNoCR, 1742 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasNoCR,
1707 "Hey!\nHo!\n", "Hey!\r\nHo!\r\n", 1743 "Hey!\nHo!\n", "Hey!\r\nHo!\r\n",
1708 presubmit.OutputApi.PresubmitPromptWarning) 1744 presubmit.OutputApi.PresubmitPromptWarning)
1709 1745
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
2398 owners_check=False) 2434 owners_check=False)
2399 self.assertEqual(1, len(results)) 2435 self.assertEqual(1, len(results))
2400 self.assertEqual( 2436 self.assertEqual(
2401 'Found line ending with white spaces in:', results[0]._message) 2437 'Found line ending with white spaces in:', results[0]._message)
2402 self.checkstdout('') 2438 self.checkstdout('')
2403 2439
2404 2440
2405 if __name__ == '__main__': 2441 if __name__ == '__main__':
2406 import unittest 2442 import unittest
2407 unittest.main() 2443 unittest.main()
OLDNEW
« no previous file with comments | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698