Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 3 | # |
| 4 | # Copyright 2017 Google, Inc |
| 5 | # |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 6 | |
Simon Glass | eb209e5 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 7 | """Functional tests for checking that patman behaves correctly""" |
| 8 | |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 9 | import contextlib |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 10 | import os |
Maxim Cournoyer | 0331edb | 2022-12-19 17:32:39 -0500 | [diff] [blame] | 11 | import pathlib |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 12 | import re |
| 13 | import shutil |
| 14 | import sys |
| 15 | import tempfile |
| 16 | import unittest |
| 17 | |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 18 | |
| 19 | from patman.commit import Commit |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 20 | from patman import control |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 21 | from patman import patchstream |
Simon Glass | a7fadab | 2020-10-29 21:46:26 -0600 | [diff] [blame] | 22 | from patman.patchstream import PatchStream |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 23 | from patman.series import Series |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 24 | from patman import settings |
Simon Glass | ba1b3b9 | 2025-02-09 14:26:00 -0700 | [diff] [blame] | 25 | from u_boot_pylib import gitutil |
Simon Glass | 131444f | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 26 | from u_boot_pylib import terminal |
| 27 | from u_boot_pylib import tools |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 28 | |
Tom Rini | 488ea97 | 2021-02-26 07:52:31 -0500 | [diff] [blame] | 29 | import pygit2 |
| 30 | from patman import status |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 31 | |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 32 | PATMAN_DIR = pathlib.Path(__file__).parent |
| 33 | TEST_DATA_DIR = PATMAN_DIR / 'test/' |
Maxim Cournoyer | 0331edb | 2022-12-19 17:32:39 -0500 | [diff] [blame] | 34 | |
Maxim Cournoyer | 0331edb | 2022-12-19 17:32:39 -0500 | [diff] [blame] | 35 | |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 36 | @contextlib.contextmanager |
| 37 | def directory_excursion(directory): |
| 38 | """Change directory to `directory` for a limited to the context block.""" |
| 39 | current = os.getcwd() |
| 40 | try: |
| 41 | os.chdir(directory) |
| 42 | yield |
| 43 | finally: |
| 44 | os.chdir(current) |
| 45 | |
Maxim Cournoyer | 0331edb | 2022-12-19 17:32:39 -0500 | [diff] [blame] | 46 | |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 47 | class TestFunctional(unittest.TestCase): |
Simon Glass | eb209e5 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 48 | """Functional tests for checking that patman behaves correctly""" |
Simon Glass | 06202d6 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 49 | leb = (b'Lord Edmund Blackadd\xc3\xabr <weasel@blackadder.org>'. |
| 50 | decode('utf-8')) |
Simon Glass | 3b762cc | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 51 | fred = 'Fred Bloggs <f.bloggs@napier.net>' |
| 52 | joe = 'Joe Bloggs <joe@napierwallies.co.nz>' |
| 53 | mary = 'Mary Bloggs <mary@napierwallies.co.nz>' |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 54 | commits = None |
| 55 | patches = None |
Simon Glass | 06202d6 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 56 | |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 57 | def setUp(self): |
| 58 | self.tmpdir = tempfile.mkdtemp(prefix='patman.') |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 59 | self.gitdir = os.path.join(self.tmpdir, 'git') |
| 60 | self.repo = None |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 61 | |
| 62 | def tearDown(self): |
| 63 | shutil.rmtree(self.tmpdir) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 64 | terminal.set_print_test_mode(False) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 65 | |
| 66 | @staticmethod |
Simon Glass | eb209e5 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 67 | def _get_path(fname): |
| 68 | """Get the path to a test file |
| 69 | |
| 70 | Args: |
| 71 | fname (str): Filename to obtain |
| 72 | |
| 73 | Returns: |
| 74 | str: Full path to file in the test directory |
| 75 | """ |
Maxim Cournoyer | 0331edb | 2022-12-19 17:32:39 -0500 | [diff] [blame] | 76 | return TEST_DATA_DIR / fname |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 77 | |
| 78 | @classmethod |
Simon Glass | eb209e5 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 79 | def _get_text(cls, fname): |
| 80 | """Read a file as text |
| 81 | |
| 82 | Args: |
| 83 | fname (str): Filename to read |
| 84 | |
| 85 | Returns: |
| 86 | str: Contents of file |
| 87 | """ |
| 88 | return open(cls._get_path(fname), encoding='utf-8').read() |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 89 | |
| 90 | @classmethod |
Simon Glass | eb209e5 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 91 | def _get_patch_name(cls, subject): |
| 92 | """Get the filename of a patch given its subject |
| 93 | |
| 94 | Args: |
| 95 | subject (str): Patch subject |
| 96 | |
| 97 | Returns: |
| 98 | str: Filename for that patch |
| 99 | """ |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 100 | fname = re.sub('[ :]', '-', subject) |
| 101 | return fname.replace('--', '-') |
| 102 | |
Simon Glass | eb209e5 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 103 | def _create_patches_for_test(self, series): |
| 104 | """Create patch files for use by tests |
| 105 | |
| 106 | This copies patch files from the test directory as needed by the series |
| 107 | |
| 108 | Args: |
| 109 | series (Series): Series containing commits to convert |
| 110 | |
| 111 | Returns: |
| 112 | tuple: |
| 113 | str: Cover-letter filename, or None if none |
| 114 | fname_list: list of str, each a patch filename |
| 115 | """ |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 116 | cover_fname = None |
| 117 | fname_list = [] |
| 118 | for i, commit in enumerate(series.commits): |
Simon Glass | eb209e5 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 119 | clean_subject = self._get_patch_name(commit.subject) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 120 | src_fname = '%04d-%s.patch' % (i + 1, clean_subject[:52]) |
| 121 | fname = os.path.join(self.tmpdir, src_fname) |
Simon Glass | eb209e5 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 122 | shutil.copy(self._get_path(src_fname), fname) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 123 | fname_list.append(fname) |
| 124 | if series.get('cover'): |
| 125 | src_fname = '0000-cover-letter.patch' |
| 126 | cover_fname = os.path.join(self.tmpdir, src_fname) |
| 127 | fname = os.path.join(self.tmpdir, src_fname) |
Simon Glass | eb209e5 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 128 | shutil.copy(self._get_path(src_fname), fname) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 129 | |
| 130 | return cover_fname, fname_list |
| 131 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 132 | def test_basic(self): |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 133 | """Tests the basic flow of patman |
| 134 | |
| 135 | This creates a series from some hard-coded patches build from a simple |
| 136 | tree with the following metadata in the top commit: |
| 137 | |
| 138 | Series-to: u-boot |
| 139 | Series-prefix: RFC |
Sean Anderson | dc1cd13 | 2021-10-22 19:07:04 -0400 | [diff] [blame] | 140 | Series-postfix: some-branch |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 141 | Series-cc: Stefan Brüns <stefan.bruens@rwth-aachen.de> |
| 142 | Cover-letter-cc: Lord Mëlchett <clergy@palace.gov> |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 143 | Series-version: 3 |
| 144 | Patch-cc: fred |
| 145 | Series-process-log: sort, uniq |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 146 | Series-changes: 4 |
| 147 | - Some changes |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 148 | - Multi |
| 149 | line |
| 150 | change |
| 151 | |
| 152 | Commit-changes: 2 |
| 153 | - Changes only for this commit |
| 154 | |
Simon Glass | f1aab6f | 2025-04-29 07:22:07 -0600 | [diff] [blame] | 155 | Cover-changes: 4 |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 156 | - Some notes for the cover letter |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 157 | |
| 158 | Cover-letter: |
| 159 | test: A test patch series |
| 160 | This is a test of how the cover |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 161 | letter |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 162 | works |
| 163 | END |
| 164 | |
| 165 | and this in the first commit: |
| 166 | |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 167 | Commit-changes: 2 |
| 168 | - second revision change |
| 169 | |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 170 | Series-notes: |
| 171 | some notes |
| 172 | about some things |
| 173 | from the first commit |
| 174 | END |
| 175 | |
| 176 | Commit-notes: |
| 177 | Some notes about |
| 178 | the first commit |
| 179 | END |
| 180 | |
| 181 | with the following commands: |
| 182 | |
| 183 | git log -n2 --reverse >/path/to/tools/patman/test/test01.txt |
| 184 | git format-patch --subject-prefix RFC --cover-letter HEAD~2 |
| 185 | mv 00* /path/to/tools/patman/test |
| 186 | |
| 187 | It checks these aspects: |
| 188 | - git log can be processed by patchstream |
| 189 | - emailing patches uses the correct command |
| 190 | - CC file has information on each commit |
| 191 | - cover letter has the expected text and subject |
| 192 | - each patch has the correct subject |
| 193 | - dry-run information prints out correctly |
| 194 | - unicode is handled correctly |
Sean Anderson | dc1cd13 | 2021-10-22 19:07:04 -0400 | [diff] [blame] | 195 | - Series-to, Series-cc, Series-prefix, Series-postfix, Cover-letter |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 196 | - Cover-letter-cc, Series-version, Series-changes, Series-notes |
| 197 | - Commit-notes |
| 198 | """ |
| 199 | process_tags = True |
Simon Glass | 1f975b9 | 2021-01-23 08:56:15 -0700 | [diff] [blame] | 200 | ignore_bad_tags = False |
Simon Glass | 4f81789 | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 201 | stefan = b'Stefan Br\xc3\xbcns <stefan.bruens@rwth-aachen.de>'.decode('utf-8') |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 202 | rick = 'Richard III <richard@palace.gov>' |
Simon Glass | 4f81789 | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 203 | mel = b'Lord M\xc3\xablchett <clergy@palace.gov>'.decode('utf-8') |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 204 | add_maintainers = [stefan, rick] |
| 205 | dry_run = True |
| 206 | in_reply_to = mel |
| 207 | count = 2 |
| 208 | settings.alias = { |
Simon Glass | 95745aa | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 209 | 'fdt': ['simon'], |
| 210 | 'u-boot': ['u-boot@lists.denx.de'], |
Simon Glass | 06202d6 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 211 | 'simon': [self.leb], |
Simon Glass | 3b762cc | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 212 | 'fred': [self.fred], |
Sean Anderson | 2597809 | 2024-04-18 22:36:31 -0400 | [diff] [blame] | 213 | 'joe': [self.joe], |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 214 | } |
| 215 | |
Simon Glass | eb209e5 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 216 | text = self._get_text('test01.txt') |
Simon Glass | 93f61c0 | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 217 | series = patchstream.get_metadata_for_test(text) |
Simon Glass | 414f1e0 | 2025-02-27 12:27:30 -0700 | [diff] [blame] | 218 | series.base_commit = Commit('1a44532') |
| 219 | series.branch = 'mybranch' |
Simon Glass | eb209e5 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 220 | cover_fname, args = self._create_patches_for_test(series) |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 221 | get_maintainer_script = str(pathlib.Path(__file__).parent.parent.parent |
| 222 | / 'get_maintainer.pl') + ' --norolestats' |
Simon Glass | 14d64e3 | 2025-04-29 07:21:59 -0600 | [diff] [blame] | 223 | with terminal.capture() as out: |
Simon Glass | 93f61c0 | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 224 | patchstream.fix_patches(series, args) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 225 | if cover_fname and series.get('cover'): |
Simon Glass | 93f61c0 | 2020-10-29 21:46:19 -0600 | [diff] [blame] | 226 | patchstream.insert_cover_letter(cover_fname, series, count) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 227 | series.DoChecks() |
| 228 | cc_file = series.MakeCcFile(process_tags, cover_fname, |
Chris Packham | b84fb48 | 2018-06-07 20:45:06 +1200 | [diff] [blame] | 229 | not ignore_bad_tags, add_maintainers, |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 230 | None, get_maintainer_script) |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 231 | cmd = gitutil.email_patches( |
Simon Glass | 95745aa | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 232 | series, cover_fname, args, dry_run, not ignore_bad_tags, |
| 233 | cc_file, in_reply_to=in_reply_to, thread=None) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 234 | series.ShowActions(args, cmd, process_tags) |
Simon Glass | f544a2d | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 235 | cc_lines = open(cc_file, encoding='utf-8').read().splitlines() |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 236 | os.remove(cc_file) |
| 237 | |
Simon Glass | 42e3d39 | 2020-10-29 21:46:29 -0600 | [diff] [blame] | 238 | lines = iter(out[0].getvalue().splitlines()) |
| 239 | self.assertEqual('Cleaned %s patches' % len(series.commits), |
| 240 | next(lines)) |
| 241 | self.assertEqual('Change log missing for v2', next(lines)) |
| 242 | self.assertEqual('Change log missing for v3', next(lines)) |
| 243 | self.assertEqual('Change log for unknown version v4', next(lines)) |
| 244 | self.assertEqual("Alias 'pci' not found", next(lines)) |
Simon Glass | 620639c | 2023-03-08 10:52:54 -0800 | [diff] [blame] | 245 | while next(lines) != 'Cc processing complete': |
| 246 | pass |
Simon Glass | 42e3d39 | 2020-10-29 21:46:29 -0600 | [diff] [blame] | 247 | self.assertIn('Dry run', next(lines)) |
| 248 | self.assertEqual('', next(lines)) |
| 249 | self.assertIn('Send a total of %d patches' % count, next(lines)) |
| 250 | prev = next(lines) |
| 251 | for i, commit in enumerate(series.commits): |
| 252 | self.assertEqual(' %s' % args[i], prev) |
| 253 | while True: |
| 254 | prev = next(lines) |
| 255 | if 'Cc:' not in prev: |
| 256 | break |
| 257 | self.assertEqual('To: u-boot@lists.denx.de', prev) |
Simon Glass | 9dfb311 | 2020-11-08 20:36:18 -0700 | [diff] [blame] | 258 | self.assertEqual('Cc: %s' % stefan, next(lines)) |
Simon Glass | 42e3d39 | 2020-10-29 21:46:29 -0600 | [diff] [blame] | 259 | self.assertEqual('Version: 3', next(lines)) |
| 260 | self.assertEqual('Prefix:\t RFC', next(lines)) |
Sean Anderson | dc1cd13 | 2021-10-22 19:07:04 -0400 | [diff] [blame] | 261 | self.assertEqual('Postfix:\t some-branch', next(lines)) |
Simon Glass | 42e3d39 | 2020-10-29 21:46:29 -0600 | [diff] [blame] | 262 | self.assertEqual('Cover: 4 lines', next(lines)) |
| 263 | self.assertEqual(' Cc: %s' % self.fred, next(lines)) |
Sean Anderson | 2597809 | 2024-04-18 22:36:31 -0400 | [diff] [blame] | 264 | self.assertEqual(' Cc: %s' % self.joe, next(lines)) |
Simon Glass | 9dfb311 | 2020-11-08 20:36:18 -0700 | [diff] [blame] | 265 | self.assertEqual(' Cc: %s' % self.leb, |
Simon Glass | 42e3d39 | 2020-10-29 21:46:29 -0600 | [diff] [blame] | 266 | next(lines)) |
Simon Glass | 9dfb311 | 2020-11-08 20:36:18 -0700 | [diff] [blame] | 267 | self.assertEqual(' Cc: %s' % mel, next(lines)) |
Simon Glass | 42e3d39 | 2020-10-29 21:46:29 -0600 | [diff] [blame] | 268 | self.assertEqual(' Cc: %s' % rick, next(lines)) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 269 | expected = ('Git command: git send-email --annotate ' |
| 270 | '--in-reply-to="%s" --to "u-boot@lists.denx.de" ' |
Simon Glass | 1ee91c1 | 2020-11-03 13:54:10 -0700 | [diff] [blame] | 271 | '--cc "%s" --cc-cmd "%s send --cc-cmd %s" %s %s' |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 272 | % (in_reply_to, stefan, sys.argv[0], cc_file, cover_fname, |
Simon Glass | 4f81789 | 2019-05-14 15:53:53 -0600 | [diff] [blame] | 273 | ' '.join(args))) |
Simon Glass | 9dfb311 | 2020-11-08 20:36:18 -0700 | [diff] [blame] | 274 | self.assertEqual(expected, next(lines)) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 275 | |
Simon Glass | 9dfb311 | 2020-11-08 20:36:18 -0700 | [diff] [blame] | 276 | self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)), cc_lines[0]) |
Simon Glass | 95745aa | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 277 | self.assertEqual( |
Sean Anderson | 2597809 | 2024-04-18 22:36:31 -0400 | [diff] [blame] | 278 | '%s %s\0%s\0%s\0%s\0%s' % (args[1], self.fred, self.joe, self.leb, |
| 279 | rick, stefan), |
Simon Glass | 9dfb311 | 2020-11-08 20:36:18 -0700 | [diff] [blame] | 280 | cc_lines[1]) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 281 | |
| 282 | expected = ''' |
| 283 | This is a test of how the cover |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 284 | letter |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 285 | works |
| 286 | |
| 287 | some notes |
| 288 | about some things |
| 289 | from the first commit |
| 290 | |
| 291 | Changes in v4: |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 292 | - Multi |
| 293 | line |
| 294 | change |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 295 | - Some changes |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 296 | - Some notes for the cover letter |
Sean Anderson | e45678c | 2024-04-18 22:36:32 -0400 | [diff] [blame] | 297 | - fdt: Correct cast for sandbox in fdtdec_setup_mem_size_base() |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 298 | |
| 299 | Simon Glass (2): |
| 300 | pci: Correct cast for sandbox |
Siva Durga Prasad Paladugu | b3d55ea | 2018-07-16 15:56:11 +0530 | [diff] [blame] | 301 | fdt: Correct cast for sandbox in fdtdec_setup_mem_size_base() |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 302 | |
| 303 | cmd/pci.c | 3 ++- |
| 304 | fs/fat/fat.c | 1 + |
| 305 | lib/efi_loader/efi_memory.c | 1 + |
| 306 | lib/fdtdec.c | 3 ++- |
| 307 | 4 files changed, 6 insertions(+), 2 deletions(-) |
| 308 | |
| 309 | --\x20 |
| 310 | 2.7.4 |
| 311 | |
Simon Glass | 414f1e0 | 2025-02-27 12:27:30 -0700 | [diff] [blame] | 312 | base-commit: 1a44532 |
| 313 | branch: mybranch |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 314 | ''' |
Simon Glass | f544a2d | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 315 | lines = open(cover_fname, encoding='utf-8').read().splitlines() |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 316 | self.assertEqual( |
Sean Anderson | dc1cd13 | 2021-10-22 19:07:04 -0400 | [diff] [blame] | 317 | 'Subject: [RFC PATCH some-branch v3 0/2] test: A test patch series', |
Simon Glass | 95745aa | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 318 | lines[3]) |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 319 | self.assertEqual(expected.splitlines(), lines[7:]) |
| 320 | |
| 321 | for i, fname in enumerate(args): |
Simon Glass | f544a2d | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 322 | lines = open(fname, encoding='utf-8').read().splitlines() |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 323 | subject = [line for line in lines if line.startswith('Subject')] |
| 324 | self.assertEqual('Subject: [RFC %d/%d]' % (i + 1, count), |
| 325 | subject[0][:18]) |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 326 | |
| 327 | # Check that we got our commit notes |
| 328 | start = 0 |
| 329 | expected = '' |
| 330 | |
Simon Glass | df1bc5c | 2017-05-29 15:31:31 -0600 | [diff] [blame] | 331 | if i == 0: |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 332 | start = 17 |
| 333 | expected = '''--- |
| 334 | Some notes about |
| 335 | the first commit |
| 336 | |
| 337 | (no changes since v2) |
| 338 | |
| 339 | Changes in v2: |
| 340 | - second revision change''' |
| 341 | elif i == 1: |
| 342 | start = 17 |
| 343 | expected = '''--- |
| 344 | |
| 345 | Changes in v4: |
| 346 | - Multi |
| 347 | line |
| 348 | change |
Sean Anderson | e45678c | 2024-04-18 22:36:32 -0400 | [diff] [blame] | 349 | - New |
Sean Anderson | cf13b86 | 2020-05-04 16:28:36 -0400 | [diff] [blame] | 350 | - Some changes |
| 351 | |
| 352 | Changes in v2: |
| 353 | - Changes only for this commit''' |
| 354 | |
| 355 | if expected: |
| 356 | expected = expected.splitlines() |
| 357 | self.assertEqual(expected, lines[start:(start+len(expected))]) |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 358 | |
Simon Glass | da1a6ec | 2025-03-28 07:02:20 -0600 | [diff] [blame] | 359 | def test_base_commit(self): |
| 360 | """Test adding a base commit with no cover letter""" |
| 361 | orig_text = self._get_text('test01.txt') |
| 362 | pos = orig_text.index('commit 5ab48490f03051875ab13d288a4bf32b507d76fd') |
| 363 | text = orig_text[:pos] |
| 364 | series = patchstream.get_metadata_for_test(text) |
| 365 | series.base_commit = Commit('1a44532') |
| 366 | series.branch = 'mybranch' |
| 367 | cover_fname, args = self._create_patches_for_test(series) |
| 368 | self.assertFalse(cover_fname) |
Simon Glass | 14d64e3 | 2025-04-29 07:21:59 -0600 | [diff] [blame] | 369 | with terminal.capture() as out: |
Simon Glass | da1a6ec | 2025-03-28 07:02:20 -0600 | [diff] [blame] | 370 | patchstream.fix_patches(series, args, insert_base_commit=True) |
| 371 | self.assertEqual('Cleaned 1 patch\n', out[0].getvalue()) |
| 372 | lines = tools.read_file(args[0], binary=False).splitlines() |
| 373 | pos = lines.index('-- ') |
| 374 | |
| 375 | # We expect these lines at the end: |
| 376 | # -- (with trailing space) |
| 377 | # 2.7.4 |
| 378 | # (empty) |
| 379 | # base-commit: xxx |
| 380 | # branch: xxx |
| 381 | self.assertEqual('base-commit: 1a44532', lines[pos + 3]) |
| 382 | self.assertEqual('branch: mybranch', lines[pos + 4]) |
| 383 | |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 384 | def make_commit_with_file(self, subject, body, fname, text): |
| 385 | """Create a file and add it to the git repo with a new commit |
| 386 | |
| 387 | Args: |
| 388 | subject (str): Subject for the commit |
| 389 | body (str): Body text of the commit |
| 390 | fname (str): Filename of file to create |
| 391 | text (str): Text to put into the file |
| 392 | """ |
| 393 | path = os.path.join(self.gitdir, fname) |
Simon Glass | 8002552 | 2022-01-29 14:14:04 -0700 | [diff] [blame] | 394 | tools.write_file(path, text, binary=False) |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 395 | index = self.repo.index |
| 396 | index.add(fname) |
Simon Glass | 547cba6 | 2022-02-11 13:23:18 -0700 | [diff] [blame] | 397 | # pylint doesn't seem to find this |
| 398 | # pylint: disable=E1101 |
Simon Glass | 95745aa | 2020-10-29 21:46:13 -0600 | [diff] [blame] | 399 | author = pygit2.Signature('Test user', 'test@email.com') |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 400 | committer = author |
| 401 | tree = index.write_tree() |
| 402 | message = subject + '\n' + body |
| 403 | self.repo.create_commit('HEAD', author, committer, message, tree, |
| 404 | [self.repo.head.target]) |
| 405 | |
| 406 | def make_git_tree(self): |
| 407 | """Make a simple git tree suitable for testing |
| 408 | |
| 409 | It has three branches: |
| 410 | 'base' has two commits: PCI, main |
| 411 | 'first' has base as upstream and two more commits: I2C, SPI |
| 412 | 'second' has base as upstream and three more: video, serial, bootm |
| 413 | |
| 414 | Returns: |
Simon Glass | eb209e5 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 415 | pygit2.Repository: repository |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 416 | """ |
| 417 | repo = pygit2.init_repository(self.gitdir) |
| 418 | self.repo = repo |
| 419 | new_tree = repo.TreeBuilder().write() |
| 420 | |
Simon Glass | 547cba6 | 2022-02-11 13:23:18 -0700 | [diff] [blame] | 421 | # pylint doesn't seem to find this |
| 422 | # pylint: disable=E1101 |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 423 | author = pygit2.Signature('Test user', 'test@email.com') |
| 424 | committer = author |
Simon Glass | eb209e5 | 2020-10-29 21:46:15 -0600 | [diff] [blame] | 425 | _ = repo.create_commit('HEAD', author, committer, 'Created master', |
| 426 | new_tree, []) |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 427 | |
| 428 | self.make_commit_with_file('Initial commit', ''' |
| 429 | Add a README |
| 430 | |
| 431 | ''', 'README', '''This is the README file |
| 432 | describing this project |
| 433 | in very little detail''') |
| 434 | |
| 435 | self.make_commit_with_file('pci: PCI implementation', ''' |
| 436 | Here is a basic PCI implementation |
| 437 | |
| 438 | ''', 'pci.c', '''This is a file |
| 439 | it has some contents |
| 440 | and some more things''') |
| 441 | self.make_commit_with_file('main: Main program', ''' |
| 442 | Hello here is the second commit. |
| 443 | ''', 'main.c', '''This is the main file |
| 444 | there is very little here |
| 445 | but we can always add more later |
| 446 | if we want to |
| 447 | |
| 448 | Series-to: u-boot |
| 449 | Series-cc: Barry Crump <bcrump@whataroa.nz> |
| 450 | ''') |
| 451 | base_target = repo.revparse_single('HEAD') |
| 452 | self.make_commit_with_file('i2c: I2C things', ''' |
| 453 | This has some stuff to do with I2C |
| 454 | ''', 'i2c.c', '''And this is the file contents |
| 455 | with some I2C-related things in it''') |
| 456 | self.make_commit_with_file('spi: SPI fixes', ''' |
| 457 | SPI needs some fixes |
| 458 | and here they are |
Simon Glass | d0a0a58 | 2020-10-29 21:46:36 -0600 | [diff] [blame] | 459 | |
| 460 | Signed-off-by: %s |
| 461 | |
| 462 | Series-to: u-boot |
| 463 | Commit-notes: |
| 464 | title of the series |
| 465 | This is the cover letter for the series |
| 466 | with various details |
| 467 | END |
| 468 | ''' % self.leb, 'spi.c', '''Some fixes for SPI in this |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 469 | file to make SPI work |
| 470 | better than before''') |
| 471 | first_target = repo.revparse_single('HEAD') |
| 472 | |
| 473 | target = repo.revparse_single('HEAD~2') |
Simon Glass | 547cba6 | 2022-02-11 13:23:18 -0700 | [diff] [blame] | 474 | # pylint doesn't seem to find this |
| 475 | # pylint: disable=E1101 |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 476 | repo.reset(target.oid, pygit2.GIT_CHECKOUT_FORCE) |
| 477 | self.make_commit_with_file('video: Some video improvements', ''' |
| 478 | Fix up the video so that |
| 479 | it looks more purple. Purple is |
| 480 | a very nice colour. |
| 481 | ''', 'video.c', '''More purple here |
| 482 | Purple and purple |
| 483 | Even more purple |
| 484 | Could not be any more purple''') |
| 485 | self.make_commit_with_file('serial: Add a serial driver', ''' |
| 486 | Here is the serial driver |
| 487 | for my chip. |
| 488 | |
| 489 | Cover-letter: |
| 490 | Series for my board |
| 491 | This series implements support |
| 492 | for my glorious board. |
| 493 | END |
Simon Glass | a80986c | 2020-10-29 21:46:16 -0600 | [diff] [blame] | 494 | Series-links: 183237 |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 495 | ''', 'serial.c', '''The code for the |
| 496 | serial driver is here''') |
| 497 | self.make_commit_with_file('bootm: Make it boot', ''' |
| 498 | This makes my board boot |
| 499 | with a fix to the bootm |
| 500 | command |
| 501 | ''', 'bootm.c', '''Fix up the bootm |
| 502 | command to make the code as |
| 503 | complicated as possible''') |
| 504 | second_target = repo.revparse_single('HEAD') |
| 505 | |
| 506 | repo.branches.local.create('first', first_target) |
| 507 | repo.config.set_multivar('branch.first.remote', '', '.') |
| 508 | repo.config.set_multivar('branch.first.merge', '', 'refs/heads/base') |
| 509 | |
| 510 | repo.branches.local.create('second', second_target) |
| 511 | repo.config.set_multivar('branch.second.remote', '', '.') |
| 512 | repo.config.set_multivar('branch.second.merge', '', 'refs/heads/base') |
| 513 | |
| 514 | repo.branches.local.create('base', base_target) |
| 515 | return repo |
| 516 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 517 | def test_branch(self): |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 518 | """Test creating patches from a branch""" |
| 519 | repo = self.make_git_tree() |
| 520 | target = repo.lookup_reference('refs/heads/first') |
Simon Glass | 547cba6 | 2022-02-11 13:23:18 -0700 | [diff] [blame] | 521 | # pylint doesn't seem to find this |
| 522 | # pylint: disable=E1101 |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 523 | self.repo.checkout(target, strategy=pygit2.GIT_CHECKOUT_FORCE) |
| 524 | control.setup() |
Heinrich Schuchardt | d01d667 | 2023-04-20 20:07:29 +0200 | [diff] [blame] | 525 | orig_dir = os.getcwd() |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 526 | try: |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 527 | os.chdir(self.gitdir) |
| 528 | |
| 529 | # Check that it can detect the current branch |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 530 | self.assertEqual(2, gitutil.count_commits_to_branch(None)) |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 531 | col = terminal.Color() |
Simon Glass | 14d64e3 | 2025-04-29 07:21:59 -0600 | [diff] [blame] | 532 | with terminal.capture() as _: |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 533 | _, cover_fname, patch_files = control.prepare_patches( |
Simon Glass | b3bf4e1 | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 534 | col, branch=None, count=-1, start=0, end=0, |
Philipp Tomsich | 858531a | 2020-11-24 18:14:52 +0100 | [diff] [blame] | 535 | ignore_binary=False, signoff=True) |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 536 | self.assertIsNone(cover_fname) |
| 537 | self.assertEqual(2, len(patch_files)) |
Simon Glass | 2eb4da7 | 2020-07-05 21:41:51 -0600 | [diff] [blame] | 538 | |
| 539 | # Check that it can detect a different branch |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 540 | self.assertEqual(3, gitutil.count_commits_to_branch('second')) |
Simon Glass | 14d64e3 | 2025-04-29 07:21:59 -0600 | [diff] [blame] | 541 | with terminal.capture() as _: |
Simon Glass | 414f1e0 | 2025-02-27 12:27:30 -0700 | [diff] [blame] | 542 | series, cover_fname, patch_files = control.prepare_patches( |
Simon Glass | b3bf4e1 | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 543 | col, branch='second', count=-1, start=0, end=0, |
Philipp Tomsich | 858531a | 2020-11-24 18:14:52 +0100 | [diff] [blame] | 544 | ignore_binary=False, signoff=True) |
Simon Glass | 2eb4da7 | 2020-07-05 21:41:51 -0600 | [diff] [blame] | 545 | self.assertIsNotNone(cover_fname) |
| 546 | self.assertEqual(3, len(patch_files)) |
Simon Glass | b3bf4e1 | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 547 | |
Simon Glass | 414f1e0 | 2025-02-27 12:27:30 -0700 | [diff] [blame] | 548 | cover = tools.read_file(cover_fname, binary=False) |
| 549 | lines = cover.splitlines()[-2:] |
| 550 | base = repo.lookup_reference('refs/heads/base').target |
| 551 | self.assertEqual(f'base-commit: {base}', lines[0]) |
| 552 | self.assertEqual('branch: second', lines[1]) |
| 553 | |
Simon Glass | da1a6ec | 2025-03-28 07:02:20 -0600 | [diff] [blame] | 554 | # Make sure that the base-commit is not present when it is in the |
| 555 | # cover letter |
| 556 | for fname in patch_files: |
| 557 | self.assertNotIn(b'base-commit:', tools.read_file(fname)) |
| 558 | |
Simon Glass | b3bf4e1 | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 559 | # Check that it can skip patches at the end |
Simon Glass | 14d64e3 | 2025-04-29 07:21:59 -0600 | [diff] [blame] | 560 | with terminal.capture() as _: |
Simon Glass | b3bf4e1 | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 561 | _, cover_fname, patch_files = control.prepare_patches( |
| 562 | col, branch='second', count=-1, start=0, end=1, |
Philipp Tomsich | 858531a | 2020-11-24 18:14:52 +0100 | [diff] [blame] | 563 | ignore_binary=False, signoff=True) |
Simon Glass | b3bf4e1 | 2020-07-05 21:41:52 -0600 | [diff] [blame] | 564 | self.assertIsNotNone(cover_fname) |
| 565 | self.assertEqual(2, len(patch_files)) |
Simon Glass | 414f1e0 | 2025-02-27 12:27:30 -0700 | [diff] [blame] | 566 | |
| 567 | cover = tools.read_file(cover_fname, binary=False) |
| 568 | lines = cover.splitlines()[-2:] |
| 569 | base2 = repo.lookup_reference('refs/heads/second') |
| 570 | ref = base2.peel(pygit2.GIT_OBJ_COMMIT).parents[0].parents[0].id |
| 571 | self.assertEqual(f'base-commit: {ref}', lines[0]) |
| 572 | self.assertEqual('branch: second', lines[1]) |
Simon Glass | 54f1c5b | 2020-07-05 21:41:50 -0600 | [diff] [blame] | 573 | finally: |
| 574 | os.chdir(orig_dir) |
Simon Glass | 06202d6 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 575 | |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 576 | def test_custom_get_maintainer_script(self): |
| 577 | """Validate that a custom get_maintainer script gets used.""" |
| 578 | self.make_git_tree() |
| 579 | with directory_excursion(self.gitdir): |
| 580 | # Setup git. |
| 581 | os.environ['GIT_CONFIG_GLOBAL'] = '/dev/null' |
| 582 | os.environ['GIT_CONFIG_SYSTEM'] = '/dev/null' |
| 583 | tools.run('git', 'config', 'user.name', 'Dummy') |
| 584 | tools.run('git', 'config', 'user.email', 'dumdum@dummy.com') |
| 585 | tools.run('git', 'branch', 'upstream') |
| 586 | tools.run('git', 'branch', '--set-upstream-to=upstream') |
| 587 | tools.run('git', 'add', '.') |
| 588 | tools.run('git', 'commit', '-m', 'new commit') |
| 589 | |
| 590 | # Setup patman configuration. |
| 591 | with open('.patman', 'w', buffering=1) as f: |
| 592 | f.write('[settings]\n' |
| 593 | 'get_maintainer_script: dummy-script.sh\n' |
Sean Anderson | a06df74 | 2024-04-18 22:36:30 -0400 | [diff] [blame] | 594 | 'check_patch: False\n' |
| 595 | 'add_maintainers: True\n') |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 596 | with open('dummy-script.sh', 'w', buffering=1) as f: |
| 597 | f.write('#!/usr/bin/env python\n' |
| 598 | 'print("hello@there.com")\n') |
| 599 | os.chmod('dummy-script.sh', 0x555) |
| 600 | |
| 601 | # Finally, do the test |
Simon Glass | 14d64e3 | 2025-04-29 07:21:59 -0600 | [diff] [blame] | 602 | with terminal.capture(): |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 603 | output = tools.run(PATMAN_DIR / 'patman', '--dry-run') |
| 604 | # Assert the email address is part of the dry-run |
| 605 | # output. |
| 606 | self.assertIn('hello@there.com', output) |
| 607 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 608 | def test_tags(self): |
Simon Glass | 06202d6 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 609 | """Test collection of tags in a patchstream""" |
| 610 | text = '''This is a patch |
| 611 | |
| 612 | Signed-off-by: Terminator |
Simon Glass | 3b762cc | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 613 | Reviewed-by: %s |
| 614 | Reviewed-by: %s |
Simon Glass | 06202d6 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 615 | Tested-by: %s |
Simon Glass | 3b762cc | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 616 | ''' % (self.joe, self.mary, self.leb) |
Simon Glass | 06202d6 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 617 | pstrm = PatchStream.process_text(text) |
| 618 | self.assertEqual(pstrm.commit.rtags, { |
Simon Glass | 3b762cc | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 619 | 'Reviewed-by': {self.joe, self.mary}, |
Simon Glass | 06202d6 | 2020-10-29 21:46:27 -0600 | [diff] [blame] | 620 | 'Tested-by': {self.leb}}) |
Simon Glass | 3b762cc | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 621 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 622 | def test_invalid_tag(self): |
Patrick Delaunay | 6bbdd0c | 2021-07-22 16:51:42 +0200 | [diff] [blame] | 623 | """Test invalid tag in a patchstream""" |
| 624 | text = '''This is a patch |
| 625 | |
| 626 | Serie-version: 2 |
| 627 | ''' |
| 628 | with self.assertRaises(ValueError) as exc: |
| 629 | pstrm = PatchStream.process_text(text) |
| 630 | self.assertEqual("Line 3: Invalid tag = 'Serie-version: 2'", |
| 631 | str(exc.exception)) |
| 632 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 633 | def test_missing_end(self): |
Simon Glass | 3b762cc | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 634 | """Test a missing END tag""" |
| 635 | text = '''This is a patch |
| 636 | |
| 637 | Cover-letter: |
| 638 | This is the title |
| 639 | missing END after this line |
| 640 | Signed-off-by: Fred |
| 641 | ''' |
| 642 | pstrm = PatchStream.process_text(text) |
| 643 | self.assertEqual(["Missing 'END' in section 'cover'"], |
| 644 | pstrm.commit.warn) |
| 645 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 646 | def test_missing_blank_line(self): |
Simon Glass | 3b762cc | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 647 | """Test a missing blank line after a tag""" |
| 648 | text = '''This is a patch |
| 649 | |
| 650 | Series-changes: 2 |
| 651 | - First line of changes |
| 652 | - Missing blank line after this line |
| 653 | Signed-off-by: Fred |
| 654 | ''' |
| 655 | pstrm = PatchStream.process_text(text) |
| 656 | self.assertEqual(["Missing 'blank line' in section 'Series-changes'"], |
| 657 | pstrm.commit.warn) |
| 658 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 659 | def test_invalid_commit_tag(self): |
Simon Glass | 3b762cc | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 660 | """Test an invalid Commit-xxx tag""" |
| 661 | text = '''This is a patch |
| 662 | |
| 663 | Commit-fred: testing |
| 664 | ''' |
| 665 | pstrm = PatchStream.process_text(text) |
| 666 | self.assertEqual(["Line 3: Ignoring Commit-fred"], pstrm.commit.warn) |
| 667 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 668 | def test_self_test(self): |
Simon Glass | 3b762cc | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 669 | """Test a tested by tag by this user""" |
| 670 | test_line = 'Tested-by: %s@napier.com' % os.getenv('USER') |
| 671 | text = '''This is a patch |
| 672 | |
| 673 | %s |
| 674 | ''' % test_line |
| 675 | pstrm = PatchStream.process_text(text) |
| 676 | self.assertEqual(["Ignoring '%s'" % test_line], pstrm.commit.warn) |
| 677 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 678 | def test_space_before_tab(self): |
Simon Glass | 3b762cc | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 679 | """Test a space before a tab""" |
| 680 | text = '''This is a patch |
| 681 | |
| 682 | + \tSomething |
| 683 | ''' |
| 684 | pstrm = PatchStream.process_text(text) |
| 685 | self.assertEqual(["Line 3/0 has space before tab"], pstrm.commit.warn) |
| 686 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 687 | def test_lines_after_test(self): |
Simon Glass | 3b762cc | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 688 | """Test detecting lines after TEST= line""" |
| 689 | text = '''This is a patch |
| 690 | |
| 691 | TEST=sometest |
| 692 | more lines |
| 693 | here |
| 694 | ''' |
| 695 | pstrm = PatchStream.process_text(text) |
| 696 | self.assertEqual(["Found 2 lines after TEST="], pstrm.commit.warn) |
| 697 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 698 | def test_blank_line_at_end(self): |
Simon Glass | 3b762cc | 2020-10-29 21:46:28 -0600 | [diff] [blame] | 699 | """Test detecting a blank line at the end of a file""" |
| 700 | text = '''This is a patch |
| 701 | |
| 702 | diff --git a/lib/fdtdec.c b/lib/fdtdec.c |
| 703 | index c072e54..942244f 100644 |
| 704 | --- a/lib/fdtdec.c |
| 705 | +++ b/lib/fdtdec.c |
| 706 | @@ -1200,7 +1200,8 @@ int fdtdec_setup_mem_size_base(void) |
| 707 | } |
| 708 | |
| 709 | gd->ram_size = (phys_size_t)(res.end - res.start + 1); |
| 710 | - debug("%s: Initial DRAM size %llx\n", __func__, (u64)gd->ram_size); |
| 711 | + debug("%s: Initial DRAM size %llx\n", __func__, |
| 712 | + (unsigned long long)gd->ram_size); |
| 713 | + |
| 714 | diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c |
| 715 | |
| 716 | -- |
| 717 | 2.7.4 |
| 718 | |
| 719 | ''' |
| 720 | pstrm = PatchStream.process_text(text) |
| 721 | self.assertEqual( |
| 722 | ["Found possible blank line(s) at end of file 'lib/fdtdec.c'"], |
| 723 | pstrm.commit.warn) |
Simon Glass | 1c1f207 | 2020-10-29 21:46:34 -0600 | [diff] [blame] | 724 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 725 | def test_no_upstream(self): |
Simon Glass | 1c1f207 | 2020-10-29 21:46:34 -0600 | [diff] [blame] | 726 | """Test CountCommitsToBranch when there is no upstream""" |
| 727 | repo = self.make_git_tree() |
| 728 | target = repo.lookup_reference('refs/heads/base') |
Simon Glass | 547cba6 | 2022-02-11 13:23:18 -0700 | [diff] [blame] | 729 | # pylint doesn't seem to find this |
| 730 | # pylint: disable=E1101 |
Simon Glass | 1c1f207 | 2020-10-29 21:46:34 -0600 | [diff] [blame] | 731 | self.repo.checkout(target, strategy=pygit2.GIT_CHECKOUT_FORCE) |
| 732 | |
| 733 | # Check that it can detect the current branch |
Heinrich Schuchardt | d01d667 | 2023-04-20 20:07:29 +0200 | [diff] [blame] | 734 | orig_dir = os.getcwd() |
Simon Glass | 1c1f207 | 2020-10-29 21:46:34 -0600 | [diff] [blame] | 735 | try: |
Simon Glass | 1c1f207 | 2020-10-29 21:46:34 -0600 | [diff] [blame] | 736 | os.chdir(self.gitdir) |
| 737 | with self.assertRaises(ValueError) as exc: |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 738 | gitutil.count_commits_to_branch(None) |
Simon Glass | 1c1f207 | 2020-10-29 21:46:34 -0600 | [diff] [blame] | 739 | self.assertIn( |
| 740 | "Failed to determine upstream: fatal: no upstream configured for branch 'base'", |
| 741 | str(exc.exception)) |
| 742 | finally: |
| 743 | os.chdir(orig_dir) |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 744 | |
| 745 | @staticmethod |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 746 | def _fake_patchwork(url, subpath): |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 747 | """Fake Patchwork server for the function below |
| 748 | |
| 749 | This handles accessing a series, providing a list consisting of a |
| 750 | single patch |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 751 | |
| 752 | Args: |
| 753 | url (str): URL of patchwork server |
| 754 | subpath (str): URL subpath to use |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 755 | """ |
| 756 | re_series = re.match(r'series/(\d*)/$', subpath) |
| 757 | if re_series: |
| 758 | series_num = re_series.group(1) |
| 759 | if series_num == '1234': |
| 760 | return {'patches': [ |
| 761 | {'id': '1', 'name': 'Some patch'}]} |
| 762 | raise ValueError('Fake Patchwork does not understand: %s' % subpath) |
| 763 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 764 | def test_status_mismatch(self): |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 765 | """Test Patchwork patches not matching the series""" |
| 766 | series = Series() |
| 767 | |
Simon Glass | 14d64e3 | 2025-04-29 07:21:59 -0600 | [diff] [blame] | 768 | with terminal.capture() as (_, err): |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 769 | status.collect_patches(series, 1234, None, self._fake_patchwork) |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 770 | self.assertIn('Warning: Patchwork reports 1 patches, series has 0', |
| 771 | err.getvalue()) |
| 772 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 773 | def test_status_read_patch(self): |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 774 | """Test handling a single patch in Patchwork""" |
| 775 | series = Series() |
| 776 | series.commits = [Commit('abcd')] |
| 777 | |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 778 | patches = status.collect_patches(series, 1234, None, |
| 779 | self._fake_patchwork) |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 780 | self.assertEqual(1, len(patches)) |
| 781 | patch = patches[0] |
| 782 | self.assertEqual('1', patch.id) |
| 783 | self.assertEqual('Some patch', patch.raw_subject) |
| 784 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 785 | def test_parse_subject(self): |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 786 | """Test parsing of the patch subject""" |
| 787 | patch = status.Patch('1') |
| 788 | |
| 789 | # Simple patch not in a series |
| 790 | patch.parse_subject('Testing') |
| 791 | self.assertEqual('Testing', patch.raw_subject) |
| 792 | self.assertEqual('Testing', patch.subject) |
| 793 | self.assertEqual(1, patch.seq) |
| 794 | self.assertEqual(1, patch.count) |
| 795 | self.assertEqual(None, patch.prefix) |
| 796 | self.assertEqual(None, patch.version) |
| 797 | |
| 798 | # First patch in a series |
| 799 | patch.parse_subject('[1/2] Testing') |
| 800 | self.assertEqual('[1/2] Testing', patch.raw_subject) |
| 801 | self.assertEqual('Testing', patch.subject) |
| 802 | self.assertEqual(1, patch.seq) |
| 803 | self.assertEqual(2, patch.count) |
| 804 | self.assertEqual(None, patch.prefix) |
| 805 | self.assertEqual(None, patch.version) |
| 806 | |
| 807 | # Second patch in a series |
| 808 | patch.parse_subject('[2/2] Testing') |
| 809 | self.assertEqual('Testing', patch.subject) |
| 810 | self.assertEqual(2, patch.seq) |
| 811 | self.assertEqual(2, patch.count) |
| 812 | self.assertEqual(None, patch.prefix) |
| 813 | self.assertEqual(None, patch.version) |
| 814 | |
| 815 | # RFC patch |
| 816 | patch.parse_subject('[RFC,3/7] Testing') |
| 817 | self.assertEqual('Testing', patch.subject) |
| 818 | self.assertEqual(3, patch.seq) |
| 819 | self.assertEqual(7, patch.count) |
| 820 | self.assertEqual('RFC', patch.prefix) |
| 821 | self.assertEqual(None, patch.version) |
| 822 | |
| 823 | # Version patch |
| 824 | patch.parse_subject('[v2,3/7] Testing') |
| 825 | self.assertEqual('Testing', patch.subject) |
| 826 | self.assertEqual(3, patch.seq) |
| 827 | self.assertEqual(7, patch.count) |
| 828 | self.assertEqual(None, patch.prefix) |
| 829 | self.assertEqual('v2', patch.version) |
| 830 | |
| 831 | # All fields |
| 832 | patch.parse_subject('[RESEND,v2,3/7] Testing') |
| 833 | self.assertEqual('Testing', patch.subject) |
| 834 | self.assertEqual(3, patch.seq) |
| 835 | self.assertEqual(7, patch.count) |
| 836 | self.assertEqual('RESEND', patch.prefix) |
| 837 | self.assertEqual('v2', patch.version) |
| 838 | |
| 839 | # RFC only |
| 840 | patch.parse_subject('[RESEND] Testing') |
| 841 | self.assertEqual('Testing', patch.subject) |
| 842 | self.assertEqual(1, patch.seq) |
| 843 | self.assertEqual(1, patch.count) |
| 844 | self.assertEqual('RESEND', patch.prefix) |
| 845 | self.assertEqual(None, patch.version) |
| 846 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 847 | def test_compare_series(self): |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 848 | """Test operation of compare_with_series()""" |
| 849 | commit1 = Commit('abcd') |
| 850 | commit1.subject = 'Subject 1' |
| 851 | commit2 = Commit('ef12') |
| 852 | commit2.subject = 'Subject 2' |
| 853 | commit3 = Commit('3456') |
| 854 | commit3.subject = 'Subject 2' |
| 855 | |
| 856 | patch1 = status.Patch('1') |
| 857 | patch1.subject = 'Subject 1' |
| 858 | patch2 = status.Patch('2') |
| 859 | patch2.subject = 'Subject 2' |
| 860 | patch3 = status.Patch('3') |
| 861 | patch3.subject = 'Subject 2' |
| 862 | |
| 863 | series = Series() |
| 864 | series.commits = [commit1] |
| 865 | patches = [patch1] |
| 866 | patch_for_commit, commit_for_patch, warnings = ( |
| 867 | status.compare_with_series(series, patches)) |
| 868 | self.assertEqual(1, len(patch_for_commit)) |
| 869 | self.assertEqual(patch1, patch_for_commit[0]) |
| 870 | self.assertEqual(1, len(commit_for_patch)) |
| 871 | self.assertEqual(commit1, commit_for_patch[0]) |
| 872 | |
| 873 | series.commits = [commit1] |
| 874 | patches = [patch1, patch2] |
| 875 | patch_for_commit, commit_for_patch, warnings = ( |
| 876 | status.compare_with_series(series, patches)) |
| 877 | self.assertEqual(1, len(patch_for_commit)) |
| 878 | self.assertEqual(patch1, patch_for_commit[0]) |
| 879 | self.assertEqual(1, len(commit_for_patch)) |
| 880 | self.assertEqual(commit1, commit_for_patch[0]) |
| 881 | self.assertEqual(["Cannot find commit for patch 2 ('Subject 2')"], |
| 882 | warnings) |
| 883 | |
| 884 | series.commits = [commit1, commit2] |
| 885 | patches = [patch1] |
| 886 | patch_for_commit, commit_for_patch, warnings = ( |
| 887 | status.compare_with_series(series, patches)) |
| 888 | self.assertEqual(1, len(patch_for_commit)) |
| 889 | self.assertEqual(patch1, patch_for_commit[0]) |
| 890 | self.assertEqual(1, len(commit_for_patch)) |
| 891 | self.assertEqual(commit1, commit_for_patch[0]) |
| 892 | self.assertEqual(["Cannot find patch for commit 2 ('Subject 2')"], |
| 893 | warnings) |
| 894 | |
| 895 | series.commits = [commit1, commit2, commit3] |
| 896 | patches = [patch1, patch2] |
| 897 | patch_for_commit, commit_for_patch, warnings = ( |
| 898 | status.compare_with_series(series, patches)) |
| 899 | self.assertEqual(2, len(patch_for_commit)) |
| 900 | self.assertEqual(patch1, patch_for_commit[0]) |
| 901 | self.assertEqual(patch2, patch_for_commit[1]) |
| 902 | self.assertEqual(1, len(commit_for_patch)) |
| 903 | self.assertEqual(commit1, commit_for_patch[0]) |
| 904 | self.assertEqual(["Cannot find patch for commit 3 ('Subject 2')", |
| 905 | "Multiple commits match patch 2 ('Subject 2'):\n" |
| 906 | ' Subject 2\n Subject 2'], |
| 907 | warnings) |
| 908 | |
| 909 | series.commits = [commit1, commit2] |
| 910 | patches = [patch1, patch2, patch3] |
| 911 | patch_for_commit, commit_for_patch, warnings = ( |
| 912 | status.compare_with_series(series, patches)) |
| 913 | self.assertEqual(1, len(patch_for_commit)) |
| 914 | self.assertEqual(patch1, patch_for_commit[0]) |
| 915 | self.assertEqual(2, len(commit_for_patch)) |
| 916 | self.assertEqual(commit1, commit_for_patch[0]) |
| 917 | self.assertEqual(["Multiple patches match commit 2 ('Subject 2'):\n" |
| 918 | ' Subject 2\n Subject 2', |
| 919 | "Cannot find commit for patch 3 ('Subject 2')"], |
| 920 | warnings) |
| 921 | |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 922 | def _fake_patchwork2(self, url, subpath): |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 923 | """Fake Patchwork server for the function below |
| 924 | |
| 925 | This handles accessing series, patches and comments, providing the data |
| 926 | in self.patches to the caller |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 927 | |
| 928 | Args: |
| 929 | url (str): URL of patchwork server |
| 930 | subpath (str): URL subpath to use |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 931 | """ |
| 932 | re_series = re.match(r'series/(\d*)/$', subpath) |
| 933 | re_patch = re.match(r'patches/(\d*)/$', subpath) |
| 934 | re_comments = re.match(r'patches/(\d*)/comments/$', subpath) |
| 935 | if re_series: |
| 936 | series_num = re_series.group(1) |
| 937 | if series_num == '1234': |
| 938 | return {'patches': self.patches} |
| 939 | elif re_patch: |
| 940 | patch_num = int(re_patch.group(1)) |
| 941 | patch = self.patches[patch_num - 1] |
| 942 | return patch |
| 943 | elif re_comments: |
| 944 | patch_num = int(re_comments.group(1)) |
| 945 | patch = self.patches[patch_num - 1] |
| 946 | return patch.comments |
| 947 | raise ValueError('Fake Patchwork does not understand: %s' % subpath) |
| 948 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 949 | def test_find_new_responses(self): |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 950 | """Test operation of find_new_responses()""" |
| 951 | commit1 = Commit('abcd') |
| 952 | commit1.subject = 'Subject 1' |
| 953 | commit2 = Commit('ef12') |
| 954 | commit2.subject = 'Subject 2' |
| 955 | |
| 956 | patch1 = status.Patch('1') |
| 957 | patch1.parse_subject('[1/2] Subject 1') |
| 958 | patch1.name = patch1.raw_subject |
| 959 | patch1.content = 'This is my patch content' |
| 960 | comment1a = {'content': 'Reviewed-by: %s\n' % self.joe} |
| 961 | |
| 962 | patch1.comments = [comment1a] |
| 963 | |
| 964 | patch2 = status.Patch('2') |
| 965 | patch2.parse_subject('[2/2] Subject 2') |
| 966 | patch2.name = patch2.raw_subject |
| 967 | patch2.content = 'Some other patch content' |
| 968 | comment2a = { |
| 969 | 'content': 'Reviewed-by: %s\nTested-by: %s\n' % |
| 970 | (self.mary, self.leb)} |
| 971 | comment2b = {'content': 'Reviewed-by: %s' % self.fred} |
| 972 | patch2.comments = [comment2a, comment2b] |
| 973 | |
| 974 | # This test works by setting up commits and patch for use by the fake |
| 975 | # Rest API function _fake_patchwork2(). It calls various functions in |
| 976 | # the status module after setting up tags in the commits, checking that |
| 977 | # things behaves as expected |
| 978 | self.commits = [commit1, commit2] |
| 979 | self.patches = [patch1, patch2] |
| 980 | count = 2 |
| 981 | new_rtag_list = [None] * count |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 982 | review_list = [None, None] |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 983 | |
| 984 | # Check that the tags are picked up on the first patch |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 985 | status.find_new_responses(new_rtag_list, review_list, 0, commit1, |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 986 | patch1, None, self._fake_patchwork2) |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 987 | self.assertEqual(new_rtag_list[0], {'Reviewed-by': {self.joe}}) |
| 988 | |
| 989 | # Now the second patch |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 990 | status.find_new_responses(new_rtag_list, review_list, 1, commit2, |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 991 | patch2, None, self._fake_patchwork2) |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 992 | self.assertEqual(new_rtag_list[1], { |
| 993 | 'Reviewed-by': {self.mary, self.fred}, |
| 994 | 'Tested-by': {self.leb}}) |
| 995 | |
| 996 | # Now add some tags to the commit, which means they should not appear as |
| 997 | # 'new' tags when scanning comments |
| 998 | new_rtag_list = [None] * count |
| 999 | commit1.rtags = {'Reviewed-by': {self.joe}} |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 1000 | status.find_new_responses(new_rtag_list, review_list, 0, commit1, |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 1001 | patch1, None, self._fake_patchwork2) |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 1002 | self.assertEqual(new_rtag_list[0], {}) |
| 1003 | |
| 1004 | # For the second commit, add Ed and Fred, so only Mary should be left |
| 1005 | commit2.rtags = { |
| 1006 | 'Tested-by': {self.leb}, |
| 1007 | 'Reviewed-by': {self.fred}} |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 1008 | status.find_new_responses(new_rtag_list, review_list, 1, commit2, |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 1009 | patch2, None, self._fake_patchwork2) |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 1010 | self.assertEqual(new_rtag_list[1], {'Reviewed-by': {self.mary}}) |
| 1011 | |
| 1012 | # Check that the output patches expectations: |
| 1013 | # 1 Subject 1 |
| 1014 | # Reviewed-by: Joe Bloggs <joe@napierwallies.co.nz> |
| 1015 | # 2 Subject 2 |
| 1016 | # Tested-by: Lord Edmund Blackaddër <weasel@blackadder.org> |
| 1017 | # Reviewed-by: Fred Bloggs <f.bloggs@napier.net> |
| 1018 | # + Reviewed-by: Mary Bloggs <mary@napierwallies.co.nz> |
| 1019 | # 1 new response available in patchwork |
| 1020 | |
| 1021 | series = Series() |
| 1022 | series.commits = [commit1, commit2] |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1023 | terminal.set_print_test_mode() |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 1024 | status.check_patchwork_status(series, '1234', None, None, False, False, |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 1025 | None, self._fake_patchwork2) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1026 | lines = iter(terminal.get_print_test_lines()) |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 1027 | col = terminal.Color() |
| 1028 | self.assertEqual(terminal.PrintLine(' 1 Subject 1', col.BLUE), |
| 1029 | next(lines)) |
| 1030 | self.assertEqual( |
| 1031 | terminal.PrintLine(' Reviewed-by: ', col.GREEN, newline=False, |
| 1032 | bright=False), |
| 1033 | next(lines)) |
| 1034 | self.assertEqual(terminal.PrintLine(self.joe, col.WHITE, bright=False), |
| 1035 | next(lines)) |
| 1036 | |
| 1037 | self.assertEqual(terminal.PrintLine(' 2 Subject 2', col.BLUE), |
| 1038 | next(lines)) |
| 1039 | self.assertEqual( |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 1040 | terminal.PrintLine(' Reviewed-by: ', col.GREEN, newline=False, |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 1041 | bright=False), |
| 1042 | next(lines)) |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 1043 | self.assertEqual(terminal.PrintLine(self.fred, col.WHITE, bright=False), |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 1044 | next(lines)) |
| 1045 | self.assertEqual( |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 1046 | terminal.PrintLine(' Tested-by: ', col.GREEN, newline=False, |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 1047 | bright=False), |
| 1048 | next(lines)) |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 1049 | self.assertEqual(terminal.PrintLine(self.leb, col.WHITE, bright=False), |
Simon Glass | 3db916d | 2020-10-29 21:46:35 -0600 | [diff] [blame] | 1050 | next(lines)) |
| 1051 | self.assertEqual( |
| 1052 | terminal.PrintLine(' + Reviewed-by: ', col.GREEN, newline=False), |
| 1053 | next(lines)) |
| 1054 | self.assertEqual(terminal.PrintLine(self.mary, col.WHITE), |
| 1055 | next(lines)) |
| 1056 | self.assertEqual(terminal.PrintLine( |
Simon Glass | d0a0a58 | 2020-10-29 21:46:36 -0600 | [diff] [blame] | 1057 | '1 new response available in patchwork (use -d to write them to a new branch)', |
| 1058 | None), next(lines)) |
| 1059 | |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 1060 | def _fake_patchwork3(self, url, subpath): |
Simon Glass | d0a0a58 | 2020-10-29 21:46:36 -0600 | [diff] [blame] | 1061 | """Fake Patchwork server for the function below |
| 1062 | |
| 1063 | This handles accessing series, patches and comments, providing the data |
| 1064 | in self.patches to the caller |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 1065 | |
| 1066 | Args: |
| 1067 | url (str): URL of patchwork server |
| 1068 | subpath (str): URL subpath to use |
Simon Glass | d0a0a58 | 2020-10-29 21:46:36 -0600 | [diff] [blame] | 1069 | """ |
| 1070 | re_series = re.match(r'series/(\d*)/$', subpath) |
| 1071 | re_patch = re.match(r'patches/(\d*)/$', subpath) |
| 1072 | re_comments = re.match(r'patches/(\d*)/comments/$', subpath) |
| 1073 | if re_series: |
| 1074 | series_num = re_series.group(1) |
| 1075 | if series_num == '1234': |
| 1076 | return {'patches': self.patches} |
| 1077 | elif re_patch: |
| 1078 | patch_num = int(re_patch.group(1)) |
| 1079 | patch = self.patches[patch_num - 1] |
| 1080 | return patch |
| 1081 | elif re_comments: |
| 1082 | patch_num = int(re_comments.group(1)) |
| 1083 | patch = self.patches[patch_num - 1] |
| 1084 | return patch.comments |
| 1085 | raise ValueError('Fake Patchwork does not understand: %s' % subpath) |
| 1086 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 1087 | def test_create_branch(self): |
Simon Glass | d0a0a58 | 2020-10-29 21:46:36 -0600 | [diff] [blame] | 1088 | """Test operation of create_branch()""" |
| 1089 | repo = self.make_git_tree() |
| 1090 | branch = 'first' |
| 1091 | dest_branch = 'first2' |
| 1092 | count = 2 |
| 1093 | gitdir = os.path.join(self.gitdir, '.git') |
| 1094 | |
| 1095 | # Set up the test git tree. We use branch 'first' which has two commits |
| 1096 | # in it |
| 1097 | series = patchstream.get_metadata_for_list(branch, gitdir, count) |
| 1098 | self.assertEqual(2, len(series.commits)) |
| 1099 | |
| 1100 | patch1 = status.Patch('1') |
| 1101 | patch1.parse_subject('[1/2] %s' % series.commits[0].subject) |
| 1102 | patch1.name = patch1.raw_subject |
| 1103 | patch1.content = 'This is my patch content' |
| 1104 | comment1a = {'content': 'Reviewed-by: %s\n' % self.joe} |
| 1105 | |
| 1106 | patch1.comments = [comment1a] |
| 1107 | |
| 1108 | patch2 = status.Patch('2') |
| 1109 | patch2.parse_subject('[2/2] %s' % series.commits[1].subject) |
| 1110 | patch2.name = patch2.raw_subject |
| 1111 | patch2.content = 'Some other patch content' |
| 1112 | comment2a = { |
| 1113 | 'content': 'Reviewed-by: %s\nTested-by: %s\n' % |
| 1114 | (self.mary, self.leb)} |
| 1115 | comment2b = { |
| 1116 | 'content': 'Reviewed-by: %s' % self.fred} |
| 1117 | patch2.comments = [comment2a, comment2b] |
| 1118 | |
| 1119 | # This test works by setting up patches for use by the fake Rest API |
| 1120 | # function _fake_patchwork3(). The fake patch comments above should |
| 1121 | # result in new review tags that are collected and added to the commits |
| 1122 | # created in the destination branch. |
| 1123 | self.patches = [patch1, patch2] |
| 1124 | count = 2 |
| 1125 | |
| 1126 | # Expected output: |
| 1127 | # 1 i2c: I2C things |
| 1128 | # + Reviewed-by: Joe Bloggs <joe@napierwallies.co.nz> |
| 1129 | # 2 spi: SPI fixes |
| 1130 | # + Reviewed-by: Fred Bloggs <f.bloggs@napier.net> |
| 1131 | # + Reviewed-by: Mary Bloggs <mary@napierwallies.co.nz> |
| 1132 | # + Tested-by: Lord Edmund Blackaddër <weasel@blackadder.org> |
| 1133 | # 4 new responses available in patchwork |
| 1134 | # 4 responses added from patchwork into new branch 'first2' |
| 1135 | # <unittest.result.TestResult run=8 errors=0 failures=0> |
| 1136 | |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1137 | terminal.set_print_test_mode() |
Simon Glass | d0a0a58 | 2020-10-29 21:46:36 -0600 | [diff] [blame] | 1138 | status.check_patchwork_status(series, '1234', branch, dest_branch, |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 1139 | False, False, None, self._fake_patchwork3, |
| 1140 | repo) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1141 | lines = terminal.get_print_test_lines() |
Simon Glass | d0a0a58 | 2020-10-29 21:46:36 -0600 | [diff] [blame] | 1142 | self.assertEqual(12, len(lines)) |
| 1143 | self.assertEqual( |
| 1144 | "4 responses added from patchwork into new branch 'first2'", |
| 1145 | lines[11].text) |
| 1146 | |
| 1147 | # Check that the destination branch has the new tags |
| 1148 | new_series = patchstream.get_metadata_for_list(dest_branch, gitdir, |
| 1149 | count) |
| 1150 | self.assertEqual( |
| 1151 | {'Reviewed-by': {self.joe}}, |
| 1152 | new_series.commits[0].rtags) |
| 1153 | self.assertEqual( |
| 1154 | {'Tested-by': {self.leb}, |
| 1155 | 'Reviewed-by': {self.fred, self.mary}}, |
| 1156 | new_series.commits[1].rtags) |
| 1157 | |
| 1158 | # Now check the actual test of the first commit message. We expect to |
| 1159 | # see the new tags immediately below the old ones. |
| 1160 | stdout = patchstream.get_list(dest_branch, count=count, git_dir=gitdir) |
| 1161 | lines = iter([line.strip() for line in stdout.splitlines() |
| 1162 | if '-by:' in line]) |
| 1163 | |
| 1164 | # First patch should have the review tag |
| 1165 | self.assertEqual('Reviewed-by: %s' % self.joe, next(lines)) |
| 1166 | |
| 1167 | # Second patch should have the sign-off then the tested-by and two |
| 1168 | # reviewed-by tags |
| 1169 | self.assertEqual('Signed-off-by: %s' % self.leb, next(lines)) |
| 1170 | self.assertEqual('Reviewed-by: %s' % self.fred, next(lines)) |
| 1171 | self.assertEqual('Reviewed-by: %s' % self.mary, next(lines)) |
| 1172 | self.assertEqual('Tested-by: %s' % self.leb, next(lines)) |
Simon Glass | da8a292 | 2020-10-29 21:46:37 -0600 | [diff] [blame] | 1173 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 1174 | def test_parse_snippets(self): |
Simon Glass | da8a292 | 2020-10-29 21:46:37 -0600 | [diff] [blame] | 1175 | """Test parsing of review snippets""" |
| 1176 | text = '''Hi Fred, |
| 1177 | |
| 1178 | This is a comment from someone. |
| 1179 | |
| 1180 | Something else |
| 1181 | |
| 1182 | On some recent date, Fred wrote: |
| 1183 | > This is why I wrote the patch |
| 1184 | > so here it is |
| 1185 | |
| 1186 | Now a comment about the commit message |
| 1187 | A little more to say |
| 1188 | |
| 1189 | Even more |
| 1190 | |
| 1191 | > diff --git a/file.c b/file.c |
| 1192 | > Some more code |
| 1193 | > Code line 2 |
| 1194 | > Code line 3 |
| 1195 | > Code line 4 |
| 1196 | > Code line 5 |
| 1197 | > Code line 6 |
| 1198 | > Code line 7 |
| 1199 | > Code line 8 |
| 1200 | > Code line 9 |
| 1201 | |
| 1202 | And another comment |
| 1203 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 1204 | > @@ -153,8 +143,13 @@ def check_patch(fname, show_types=False): |
Simon Glass | da8a292 | 2020-10-29 21:46:37 -0600 | [diff] [blame] | 1205 | > further down on the file |
| 1206 | > and more code |
| 1207 | > +Addition here |
| 1208 | > +Another addition here |
| 1209 | > codey |
| 1210 | > more codey |
| 1211 | |
| 1212 | and another thing in same file |
| 1213 | |
| 1214 | > @@ -253,8 +243,13 @@ |
| 1215 | > with no function context |
| 1216 | |
| 1217 | one more thing |
| 1218 | |
| 1219 | > diff --git a/tools/patman/main.py b/tools/patman/main.py |
| 1220 | > +line of code |
| 1221 | now a very long comment in a different file |
| 1222 | line2 |
| 1223 | line3 |
| 1224 | line4 |
| 1225 | line5 |
| 1226 | line6 |
| 1227 | line7 |
| 1228 | line8 |
| 1229 | ''' |
| 1230 | pstrm = PatchStream.process_text(text, True) |
| 1231 | self.assertEqual([], pstrm.commit.warn) |
| 1232 | |
| 1233 | # We expect to the filename and up to 5 lines of code context before |
| 1234 | # each comment. The 'On xxx wrote:' bit should be removed. |
| 1235 | self.assertEqual( |
| 1236 | [['Hi Fred,', |
| 1237 | 'This is a comment from someone.', |
| 1238 | 'Something else'], |
| 1239 | ['> This is why I wrote the patch', |
| 1240 | '> so here it is', |
| 1241 | 'Now a comment about the commit message', |
| 1242 | 'A little more to say', 'Even more'], |
| 1243 | ['> File: file.c', '> Code line 5', '> Code line 6', |
| 1244 | '> Code line 7', '> Code line 8', '> Code line 9', |
| 1245 | 'And another comment'], |
| 1246 | ['> File: file.c', |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 1247 | '> Line: 153 / 143: def check_patch(fname, show_types=False):', |
Simon Glass | da8a292 | 2020-10-29 21:46:37 -0600 | [diff] [blame] | 1248 | '> and more code', '> +Addition here', '> +Another addition here', |
| 1249 | '> codey', '> more codey', 'and another thing in same file'], |
| 1250 | ['> File: file.c', '> Line: 253 / 243', |
| 1251 | '> with no function context', 'one more thing'], |
| 1252 | ['> File: tools/patman/main.py', '> +line of code', |
| 1253 | 'now a very long comment in a different file', |
| 1254 | 'line2', 'line3', 'line4', 'line5', 'line6', 'line7', 'line8']], |
| 1255 | pstrm.snippets) |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 1256 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 1257 | def test_review_snippets(self): |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 1258 | """Test showing of review snippets""" |
| 1259 | def _to_submitter(who): |
| 1260 | m_who = re.match('(.*) <(.*)>', who) |
| 1261 | return { |
| 1262 | 'name': m_who.group(1), |
| 1263 | 'email': m_who.group(2) |
| 1264 | } |
| 1265 | |
| 1266 | commit1 = Commit('abcd') |
| 1267 | commit1.subject = 'Subject 1' |
| 1268 | commit2 = Commit('ef12') |
| 1269 | commit2.subject = 'Subject 2' |
| 1270 | |
| 1271 | patch1 = status.Patch('1') |
| 1272 | patch1.parse_subject('[1/2] Subject 1') |
| 1273 | patch1.name = patch1.raw_subject |
| 1274 | patch1.content = 'This is my patch content' |
| 1275 | comment1a = {'submitter': _to_submitter(self.joe), |
| 1276 | 'content': '''Hi Fred, |
| 1277 | |
| 1278 | On some date Fred wrote: |
| 1279 | |
| 1280 | > diff --git a/file.c b/file.c |
| 1281 | > Some code |
| 1282 | > and more code |
| 1283 | |
| 1284 | Here is my comment above the above... |
| 1285 | |
| 1286 | |
| 1287 | Reviewed-by: %s |
| 1288 | ''' % self.joe} |
| 1289 | |
| 1290 | patch1.comments = [comment1a] |
| 1291 | |
| 1292 | patch2 = status.Patch('2') |
| 1293 | patch2.parse_subject('[2/2] Subject 2') |
| 1294 | patch2.name = patch2.raw_subject |
| 1295 | patch2.content = 'Some other patch content' |
| 1296 | comment2a = { |
| 1297 | 'content': 'Reviewed-by: %s\nTested-by: %s\n' % |
| 1298 | (self.mary, self.leb)} |
| 1299 | comment2b = {'submitter': _to_submitter(self.fred), |
| 1300 | 'content': '''Hi Fred, |
| 1301 | |
| 1302 | On some date Fred wrote: |
| 1303 | |
| 1304 | > diff --git a/tools/patman/commit.py b/tools/patman/commit.py |
| 1305 | > @@ -41,6 +41,9 @@ class Commit: |
| 1306 | > self.rtags = collections.defaultdict(set) |
| 1307 | > self.warn = [] |
| 1308 | > |
| 1309 | > + def __str__(self): |
| 1310 | > + return self.subject |
| 1311 | > + |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 1312 | > def add_change(self, version, info): |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 1313 | > """Add a new change line to the change list for a version. |
| 1314 | > |
| 1315 | A comment |
| 1316 | |
| 1317 | Reviewed-by: %s |
| 1318 | ''' % self.fred} |
| 1319 | patch2.comments = [comment2a, comment2b] |
| 1320 | |
| 1321 | # This test works by setting up commits and patch for use by the fake |
| 1322 | # Rest API function _fake_patchwork2(). It calls various functions in |
| 1323 | # the status module after setting up tags in the commits, checking that |
| 1324 | # things behaves as expected |
| 1325 | self.commits = [commit1, commit2] |
| 1326 | self.patches = [patch1, patch2] |
| 1327 | |
| 1328 | # Check that the output patches expectations: |
| 1329 | # 1 Subject 1 |
| 1330 | # Reviewed-by: Joe Bloggs <joe@napierwallies.co.nz> |
| 1331 | # 2 Subject 2 |
| 1332 | # Tested-by: Lord Edmund Blackaddër <weasel@blackadder.org> |
| 1333 | # Reviewed-by: Fred Bloggs <f.bloggs@napier.net> |
| 1334 | # + Reviewed-by: Mary Bloggs <mary@napierwallies.co.nz> |
| 1335 | # 1 new response available in patchwork |
| 1336 | |
| 1337 | series = Series() |
| 1338 | series.commits = [commit1, commit2] |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1339 | terminal.set_print_test_mode() |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 1340 | status.check_patchwork_status(series, '1234', None, None, False, True, |
Simon Glass | f9b03cf | 2020-11-03 13:54:14 -0700 | [diff] [blame] | 1341 | None, self._fake_patchwork2) |
Simon Glass | 0281158 | 2022-01-29 14:14:18 -0700 | [diff] [blame] | 1342 | lines = iter(terminal.get_print_test_lines()) |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 1343 | col = terminal.Color() |
| 1344 | self.assertEqual(terminal.PrintLine(' 1 Subject 1', col.BLUE), |
| 1345 | next(lines)) |
| 1346 | self.assertEqual( |
| 1347 | terminal.PrintLine(' + Reviewed-by: ', col.GREEN, newline=False), |
| 1348 | next(lines)) |
| 1349 | self.assertEqual(terminal.PrintLine(self.joe, col.WHITE), next(lines)) |
| 1350 | |
| 1351 | self.assertEqual(terminal.PrintLine('Review: %s' % self.joe, col.RED), |
| 1352 | next(lines)) |
| 1353 | self.assertEqual(terminal.PrintLine(' Hi Fred,', None), next(lines)) |
| 1354 | self.assertEqual(terminal.PrintLine('', None), next(lines)) |
| 1355 | self.assertEqual(terminal.PrintLine(' > File: file.c', col.MAGENTA), |
| 1356 | next(lines)) |
| 1357 | self.assertEqual(terminal.PrintLine(' > Some code', col.MAGENTA), |
| 1358 | next(lines)) |
| 1359 | self.assertEqual(terminal.PrintLine(' > and more code', col.MAGENTA), |
| 1360 | next(lines)) |
| 1361 | self.assertEqual(terminal.PrintLine( |
| 1362 | ' Here is my comment above the above...', None), next(lines)) |
| 1363 | self.assertEqual(terminal.PrintLine('', None), next(lines)) |
| 1364 | |
| 1365 | self.assertEqual(terminal.PrintLine(' 2 Subject 2', col.BLUE), |
| 1366 | next(lines)) |
| 1367 | self.assertEqual( |
| 1368 | terminal.PrintLine(' + Reviewed-by: ', col.GREEN, newline=False), |
| 1369 | next(lines)) |
| 1370 | self.assertEqual(terminal.PrintLine(self.fred, col.WHITE), |
| 1371 | next(lines)) |
| 1372 | self.assertEqual( |
| 1373 | terminal.PrintLine(' + Reviewed-by: ', col.GREEN, newline=False), |
| 1374 | next(lines)) |
| 1375 | self.assertEqual(terminal.PrintLine(self.mary, col.WHITE), |
| 1376 | next(lines)) |
| 1377 | self.assertEqual( |
| 1378 | terminal.PrintLine(' + Tested-by: ', col.GREEN, newline=False), |
| 1379 | next(lines)) |
| 1380 | self.assertEqual(terminal.PrintLine(self.leb, col.WHITE), |
| 1381 | next(lines)) |
| 1382 | |
| 1383 | self.assertEqual(terminal.PrintLine('Review: %s' % self.fred, col.RED), |
| 1384 | next(lines)) |
| 1385 | self.assertEqual(terminal.PrintLine(' Hi Fred,', None), next(lines)) |
| 1386 | self.assertEqual(terminal.PrintLine('', None), next(lines)) |
| 1387 | self.assertEqual(terminal.PrintLine( |
| 1388 | ' > File: tools/patman/commit.py', col.MAGENTA), next(lines)) |
| 1389 | self.assertEqual(terminal.PrintLine( |
| 1390 | ' > Line: 41 / 41: class Commit:', col.MAGENTA), next(lines)) |
| 1391 | self.assertEqual(terminal.PrintLine( |
| 1392 | ' > + return self.subject', col.MAGENTA), next(lines)) |
| 1393 | self.assertEqual(terminal.PrintLine( |
| 1394 | ' > +', col.MAGENTA), next(lines)) |
| 1395 | self.assertEqual( |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 1396 | terminal.PrintLine(' > def add_change(self, version, info):', |
Simon Glass | 2112d07 | 2020-10-29 21:46:38 -0600 | [diff] [blame] | 1397 | col.MAGENTA), |
| 1398 | next(lines)) |
| 1399 | self.assertEqual(terminal.PrintLine( |
| 1400 | ' > """Add a new change line to the change list for a version.', |
| 1401 | col.MAGENTA), next(lines)) |
| 1402 | self.assertEqual(terminal.PrintLine( |
| 1403 | ' >', col.MAGENTA), next(lines)) |
| 1404 | self.assertEqual(terminal.PrintLine( |
| 1405 | ' A comment', None), next(lines)) |
| 1406 | self.assertEqual(terminal.PrintLine('', None), next(lines)) |
| 1407 | |
| 1408 | self.assertEqual(terminal.PrintLine( |
| 1409 | '4 new responses available in patchwork (use -d to write them to a new branch)', |
| 1410 | None), next(lines)) |
Simon Glass | 6a222e6 | 2021-08-01 16:02:39 -0600 | [diff] [blame] | 1411 | |
Simon Glass | d85bb8f | 2022-01-29 14:14:09 -0700 | [diff] [blame] | 1412 | def test_insert_tags(self): |
Simon Glass | 6a222e6 | 2021-08-01 16:02:39 -0600 | [diff] [blame] | 1413 | """Test inserting of review tags""" |
| 1414 | msg = '''first line |
| 1415 | second line.''' |
| 1416 | tags = [ |
| 1417 | 'Reviewed-by: Bin Meng <bmeng.cn@gmail.com>', |
| 1418 | 'Tested-by: Bin Meng <bmeng.cn@gmail.com>' |
| 1419 | ] |
| 1420 | signoff = 'Signed-off-by: Simon Glass <sjg@chromium.com>' |
| 1421 | tag_str = '\n'.join(tags) |
| 1422 | |
| 1423 | new_msg = patchstream.insert_tags(msg, tags) |
| 1424 | self.assertEqual(msg + '\n\n' + tag_str, new_msg) |
| 1425 | |
| 1426 | new_msg = patchstream.insert_tags(msg + '\n', tags) |
| 1427 | self.assertEqual(msg + '\n\n' + tag_str, new_msg) |
| 1428 | |
| 1429 | msg += '\n\n' + signoff |
| 1430 | new_msg = patchstream.insert_tags(msg, tags) |
| 1431 | self.assertEqual(msg + '\n' + tag_str, new_msg) |