Commit bc50eb4a authored by maruel@chromium.org's avatar maruel@chromium.org

Add CheckChangeHasDescription.

TEST=unit test
BUG=none

Review URL: http://codereview.chromium.org/119427

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@18077 0039d316-1c4b-4281-b951-d872f2087c98
parent 5de1397a
......@@ -53,6 +53,16 @@ def CheckDoNotSubmitInDescription(input_api, output_api):
return []
def CheckChangeHasDescription(input_api, output_api):
"""Checks the CL description is not empty."""
text = input_api.change.DescriptionText()
if text.strip() == '':
if input_api.is_committing:
return [output_api.PresubmitError("Add a description.")]
else:
return [output_api.PresubmitNotifyResult("Add a description.")]
return []
### Content checks
def CheckDoNotSubmitInFiles(input_api, output_api):
......
......@@ -937,9 +937,9 @@ class CannedChecksUnittest(PresubmitTestsBase):
def testMembersChanged(self):
self.mox.ReplayAll()
members = [
'CheckChangeHasBugField', 'CheckChangeHasOnlyOneEol',
'CheckChangeHasNoCR', 'CheckChangeHasNoCrAndHasOnlyOneEol',
'CheckChangeHasNoTabs',
'CheckChangeHasBugField', 'CheckChangeHasDescription',
'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR',
'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs',
'CheckChangeHasQaField', 'CheckChangeHasTestedField',
'CheckChangeHasTestField', 'CheckChangeSvnEolStyle',
'CheckDoNotSubmit',
......@@ -949,11 +949,14 @@ class CannedChecksUnittest(PresubmitTestsBase):
# If this test fails, you should add the relevant test.
self.compareMembers(presubmit_canned_checks, members)
def DescriptionTest(self, check, description1, description2, error_type):
def DescriptionTest(self, check, description1, description2, error_type,
committing):
input_api1 = self.MockInputApi()
input_api1.change = self.MakeBasicChange('foo', 'Foo\n' + description1)
input_api1.is_committing = committing
input_api1.change = self.MakeBasicChange('foo', description1)
input_api2 = self.MockInputApi()
input_api2.change = self.MakeBasicChange('foo', 'Foo\n' + description2)
input_api2.is_committing = committing
input_api2.change = self.MakeBasicChange('foo', description2)
self.mox.ReplayAll()
results1 = check(input_api1, presubmit.OutputApi)
......@@ -1013,28 +1016,44 @@ class CannedChecksUnittest(PresubmitTestsBase):
def testCannedCheckChangeHasBugField(self):
self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField,
'BUG=1234', '',
presubmit.OutputApi.PresubmitNotifyResult)
'Foo\nBUG=1234', 'Foo\n',
presubmit.OutputApi.PresubmitNotifyResult,
False)
def testCheckChangeHasDescription(self):
self.DescriptionTest(presubmit_canned_checks.CheckChangeHasDescription,
'Bleh', '',
presubmit.OutputApi.PresubmitNotifyResult,
False)
self.mox.VerifyAll()
self.DescriptionTest(presubmit_canned_checks.CheckChangeHasDescription,
'Bleh', '',
presubmit.OutputApi.PresubmitError,
True)
def testCannedCheckChangeHasTestField(self):
self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestField,
'TEST=did some stuff', '',
presubmit.OutputApi.PresubmitNotifyResult)
'Foo\nTEST=did some stuff', 'Foo\n',
presubmit.OutputApi.PresubmitNotifyResult,
False)
def testCannedCheckChangeHasTestedField(self):
self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestedField,
'TESTED=did some stuff', '',
presubmit.OutputApi.PresubmitError)
'Foo\nTESTED=did some stuff', 'Foo\n',
presubmit.OutputApi.PresubmitError,
False)
def testCannedCheckChangeHasQAField(self):
self.DescriptionTest(presubmit_canned_checks.CheckChangeHasQaField,
'QA=BSOD your machine', '',
presubmit.OutputApi.PresubmitError)
'Foo\nQA=BSOD your machine', 'Foo\n',
presubmit.OutputApi.PresubmitError,
False)
def testCannedCheckDoNotSubmitInDescription(self):
self.DescriptionTest(presubmit_canned_checks.CheckDoNotSubmitInDescription,
'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT',
presubmit.OutputApi.PresubmitError)
'Foo\nDO NOTSUBMIT', 'Foo\nDO NOT ' + 'SUBMIT',
presubmit.OutputApi.PresubmitError,
False)
def testCannedCheckDoNotSubmitInFiles(self):
self.ContentTest(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment