1# Copyright (C) 2009 Google Inc. All rights reserved. 2# 3# Redistribution and use in source and binary forms, with or without 4# modification, are permitted provided that the following conditions are 5# met: 6# 7# * Redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer. 9# * Redistributions in binary form must reproduce the above 10# copyright notice, this list of conditions and the following disclaimer 11# in the documentation and/or other materials provided with the 12# distribution. 13# * Neither the name of Google Inc. nor the names of its 14# contributors may be used to endorse or promote products derived from 15# this software without specific prior written permission. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29import unittest 30from changelogs import * 31 32import os 33import tempfile 34from StringIO import StringIO 35 36class ChangeLogsTest(unittest.TestCase): 37 38 _example_entry = '''2009-08-17 Peter Kasting <pkasting@google.com> 39 40 Reviewed by Steve Falkenburg. 41 42 https://bugs.webkit.org/show_bug.cgi?id=27323 43 Only add Cygwin to the path when it isn't already there. This avoids 44 causing problems for people who purposefully have non-Cygwin versions of 45 executables like svn in front of the Cygwin ones in their paths. 46 47 * DumpRenderTree/win/DumpRenderTree.vcproj: 48 * DumpRenderTree/win/ImageDiff.vcproj: 49 * DumpRenderTree/win/TestNetscapePlugin/TestNetscapePlugin.vcproj: 50''' 51 52 # More example text than we need. Eventually we need to support parsing this all and write tests for the parsing. 53 _example_changelog = '''2009-08-17 David Kilzer <ddkilzer@apple.com> 54 55 <http://webkit.org/b/28393> check-webkit-style: add check for use of std::max()/std::min() instead of MAX()/MIN() 56 57 Reviewed by David Levin. 58 59 * Scripts/modules/cpp_style.py: 60 (_ERROR_CATEGORIES): Added 'runtime/max_min_macros'. 61 (check_max_min_macros): Added. Returns level 4 error when MAX() 62 and MIN() macros are used in header files and C++ source files. 63 (check_style): Added call to check_max_min_macros(). 64 * Scripts/modules/cpp_style_unittest.py: Added unit tests. 65 (test_max_macro): Added. 66 (test_min_macro): Added. 67 682009-08-16 David Kilzer <ddkilzer@apple.com> 69 70 Backed out r47343 which was mistakenly committed 71 72 * Scripts/bugzilla-tool: 73 * Scripts/modules/scm.py: 74 752009-06-18 Darin Adler <darin@apple.com> 76 77 Rubber stamped by Mark Rowe. 78 79 * DumpRenderTree/mac/DumpRenderTreeWindow.mm: 80 (-[DumpRenderTreeWindow close]): Resolved crashes seen during regression 81 tests. The close method can be called on a window that's already closed 82 so we can't assert here. 83 84== Rolled over to ChangeLog-2009-06-16 == 85''' 86 87 def test_latest_entry_parse(self): 88 changelog_contents = "%s\n%s" % (self._example_entry, self._example_changelog) 89 changelog_file = StringIO(changelog_contents) 90 latest_entry = ChangeLog._parse_latest_entry_from_file(changelog_file) 91 self.assertEquals(self._example_entry, latest_entry) 92 93 @staticmethod 94 def _write_tmp_file_with_contents(contents): 95 (file_descriptor, file_path) = tempfile.mkstemp() # NamedTemporaryFile always deletes the file on close in python < 2.6 96 file = os.fdopen(file_descriptor, 'w') 97 file.write(contents) 98 file.close() 99 return file_path 100 101 @staticmethod 102 def _read_file_contents(file_path): 103 file = open(file_path) 104 contents = file.read() 105 file.close() 106 return contents 107 108 _new_entry_boilerplate = '''2009-08-19 Eric Seidel <eric@webkit.org> 109 110 Reviewed by NOBODY (OOPS!). 111 112 Need a short description and bug URL (OOPS!) 113 114 * Scripts/bugzilla-tool: 115''' 116 117 def test_set_reviewer(self): 118 changelog_contents = "%s\n%s" % (self._new_entry_boilerplate, self._example_changelog) 119 changelog_path = self._write_tmp_file_with_contents(changelog_contents) 120 reviewer_name = 'Test Reviewer' 121 ChangeLog(changelog_path).set_reviewer(reviewer_name) 122 actual_contents = self._read_file_contents(changelog_path) 123 expected_contents = changelog_contents.replace('NOBODY (OOPS!)', reviewer_name) 124 os.remove(changelog_path) 125 self.assertEquals(actual_contents, expected_contents) 126 127 _revert_message = """ No review, rolling out r12345. 128 http://trac.webkit.org/changeset/12345 129 http://example.com/123 130 131 This is a very long reason which should be long enough so that 132 _message_for_revert will need to wrap it. We'll also include 133 a 134 https://veryveryveryveryverylongbugurl.com/reallylongbugthingy.cgi?bug_id=12354 135 link so that we can make sure we wrap that right too. 136""" 137 138 def test_message_for_revert(self): 139 changelog = ChangeLog("/fake/path") 140 long_reason = "This is a very long reason which should be long enough so that _message_for_revert will need to wrap it. We'll also include a https://veryveryveryveryverylongbugurl.com/reallylongbugthingy.cgi?bug_id=12354 link so that we can make sure we wrap that right too." 141 message = changelog._message_for_revert(12345, long_reason, "http://example.com/123") 142 self.assertEquals(message, self._revert_message) 143 144 _revert_entry_with_bug_url = '''2009-08-19 Eric Seidel <eric@webkit.org> 145 146 No review, rolling out r12345. 147 http://trac.webkit.org/changeset/12345 148 http://example.com/123 149 150 Reason 151 152 * Scripts/bugzilla-tool: 153''' 154 155 _revert_entry_without_bug_url = '''2009-08-19 Eric Seidel <eric@webkit.org> 156 157 No review, rolling out r12345. 158 http://trac.webkit.org/changeset/12345 159 160 Reason 161 162 * Scripts/bugzilla-tool: 163''' 164 165 def _assert_update_for_revert_output(self, args, expected_entry): 166 changelog_contents = "%s\n%s" % (self._new_entry_boilerplate, self._example_changelog) 167 changelog_path = self._write_tmp_file_with_contents(changelog_contents) 168 changelog = ChangeLog(changelog_path) 169 changelog.update_for_revert(*args) 170 actual_entry = changelog.latest_entry() 171 os.remove(changelog_path) 172 self.assertEquals(actual_entry, expected_entry) 173 174 def test_update_for_revert(self): 175 self._assert_update_for_revert_output([12345, "Reason"], self._revert_entry_without_bug_url) 176 self._assert_update_for_revert_output([12345, "Reason", "http://example.com/123"], self._revert_entry_with_bug_url) 177 178if __name__ == '__main__': 179 unittest.main() 180