diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index b033f6257..576d58d74 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -824,17 +824,17 @@ def _CheckConstNSObject(input_api, output_api, source_file_filter): return [] -def _CheckSingletonInHeaders(input_api, output_api, source_file_filter): +def CheckSingletonInHeaders(input_api, output_api, source_file_filter=None): """Checks to make sure no header files have |Singleton<|.""" - pattern = input_api.re.compile(r'Singleton\s*<') + pattern = input_api.re.compile(r'(?.\n' + + 'friend class Singleton;') + for _ in range(4): + affected_file2.LocalPath().AndReturn('foo.cc') + + change2 = presubmit.Change( + 'foo2', 'foo2\n', self.fake_root_dir, None, 0, 0, None) + input_api2 = self.MockInputApi(change2, False) + + affected_file3 = self.mox.CreateMock(presubmit.SvnAffectedFile) + input_api2.AffectedSourceFiles(None).AndReturn([affected_file3]) + affected_file3.LocalPath().AndReturn('foo.h') + input_api2.ReadFile(affected_file3).AndReturn( + 'Foo* foo = Singleton::get();') + + self.mox.ReplayAll() + + results1 = presubmit_canned_checks.CheckSingletonInHeaders( + input_api1, presubmit.OutputApi) + self.assertEquals(results1, []) + results2 = presubmit_canned_checks.CheckSingletonInHeaders( + input_api2, presubmit.OutputApi) + self.assertEquals(len(results2), 1) + self.assertEquals(results2[0].__class__, presubmit.OutputApi.PresubmitError) + def testCheckChangeHasOnlyOneEol(self): self.ReadFileTest(presubmit_canned_checks.CheckChangeHasOnlyOneEol, "Hey!\nHo!\n", "Hey!\nHo!\n\n",