# HG changeset patch # User Steve Losh # Date 1276641560 14400 # Node ID d63ea569a174470255c810beba9c46d98077ffd9 # Parent deb8a96475a5a890829c6058266da8037153d888 cli: strip leading and trailing whitespace from whole comments diff -r deb8a96475a5 -r d63ea569a174 review/extension_ui.py --- a/review/extension_ui.py Tue Jun 15 18:27:09 2010 -0400 +++ b/review/extension_ui.py Tue Jun 15 18:39:20 2010 -0400 @@ -43,7 +43,7 @@ def _comment_command(ui, repo, *fnames, **opts): rev = opts.pop('rev') - message = opts.pop('message') + message = opts.pop('message').strip() lines = opts.pop('lines') rd = api.ReviewDatastore(ui, repo) @@ -74,7 +74,7 @@ def _signoff_command(ui, repo, **opts): rd = api.ReviewDatastore(ui, repo) rcset = rd[opts.pop('rev')] - message = opts.pop('message') + message = opts.pop('message').strip() if not message: raise util.Abort(messages.SIGNOFF_REQUIRES_MESSAGE) diff -r deb8a96475a5 -r d63ea569a174 review/tests/test_comment.py --- a/review/tests/test_comment.py Tue Jun 15 18:27:09 2010 -0400 +++ b/review/tests/test_comment.py Tue Jun 15 18:39:20 2010 -0400 @@ -22,6 +22,33 @@ assert messages.COMMENT_REQUIRES_MESSAGE in error else: assert False, 'The correct error message was not printed.' + try: + review(comment=True, message=' \t\t') + except hgutil.Abort, e: + error = str(e) + assert messages.COMMENT_REQUIRES_MESSAGE in error + else: + assert False, 'The correct error message was not printed.' + +@with_setup(setup_reviewed_sandbox, teardown_sandbox) +def test_comment_formatting(): + review(comment=True, message=' \tTest comment one.\t ') + output = review() + + assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' in output + assert messages.REVIEW_LOG_COMMENT_LINE % ' \tTest comment one.' not in output + assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.\t ' not in output + assert messages.REVIEW_LOG_COMMENT_LINE % ' \tTest comment one.\t ' not in output + review(rev=0, comment=True, + message=' \tTest\n indented\n\ttabindented\noutdented \ndone\t ') + output = review(rev=0) + + assert messages.REVIEW_LOG_COMMENT_LINE % 'Test' in output + assert messages.REVIEW_LOG_COMMENT_LINE % ' indented' in output + assert messages.REVIEW_LOG_COMMENT_LINE % '\ttabindented' in output + assert messages.REVIEW_LOG_COMMENT_LINE % 'outdented ' in output + assert messages.REVIEW_LOG_COMMENT_LINE % 'done' in output + @with_setup(setup_reviewed_sandbox, teardown_sandbox) def test_add_comments_to_parent_rev(): diff -r deb8a96475a5 -r d63ea569a174 review/tests/test_signoff.py --- a/review/tests/test_signoff.py Tue Jun 15 18:27:09 2010 -0400 +++ b/review/tests/test_signoff.py Tue Jun 15 18:39:20 2010 -0400 @@ -24,6 +24,26 @@ assert False, 'The correct error message was not printed.' @with_setup(setup_reviewed_sandbox, teardown_sandbox) +def test_signoff_formatting(): + review(signoff=True, message=' \tTest signoff one.\t ') + output = review() + + assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.' in output + assert messages.REVIEW_LOG_SIGNOFF_LINE % ' \tTest signoff one.' not in output + assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.\t ' not in output + assert messages.REVIEW_LOG_SIGNOFF_LINE % ' \tTest signoff one.\t ' not in output + review(rev=0, signoff=True, + message=' \tTest\n indented\n\ttabindented\noutdented \ndone\t ') + output = review(rev=0) + + assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test' in output + assert messages.REVIEW_LOG_SIGNOFF_LINE % ' indented' in output + assert messages.REVIEW_LOG_SIGNOFF_LINE % '\ttabindented' in output + assert messages.REVIEW_LOG_SIGNOFF_LINE % 'outdented ' in output + assert messages.REVIEW_LOG_SIGNOFF_LINE % 'done' in output + + +@with_setup(setup_reviewed_sandbox, teardown_sandbox) def test_signoff_on_parent_rev(): review(signoff=True, message='Test signoff one.')