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