Patchwork tests: raise a better error when patterns are wrongly formatted

login
register
mail settings
Submitter Boris Feld
Date Feb. 9, 2018, 1:46 p.m.
Message ID <3fe40329001a42dcbe98.1518183987@FB>
Download mbox | patch
Permalink /patch/27511/
State Accepted
Headers show

Comments

Boris Feld - Feb. 9, 2018, 1:46 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1518176892 -3600
#      Fri Feb 09 12:48:12 2018 +0100
# Node ID 3fe40329001a42dcbe98c69b342aa00ec821fa92
# Parent  80e5210df25c330bd2a4e8f12385422545cb69bf
# EXP-Topic pattern-error
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 3fe40329001a
tests: raise a better error when patterns are wrongly formatted

It is fairly easy to make mistakes when merging conflict in the pattern file.
A common mistake is to forget adding an extra trailing comma changing the
length of the tuple.

We now detect such error and raise a better error message that helps to find
it.
Yuya Nishihara - Feb. 10, 2018, 12:39 a.m.
On Fri, 09 Feb 2018 14:46:27 +0100, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1518176892 -3600
> #      Fri Feb 09 12:48:12 2018 +0100
> # Node ID 3fe40329001a42dcbe98c69b342aa00ec821fa92
> # Parent  80e5210df25c330bd2a4e8f12385422545cb69bf
> # EXP-Topic pattern-error
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 3fe40329001a
> tests: raise a better error when patterns are wrongly formatted

Queued, thanks.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -990,7 +990,12 @@  class Test(unittest.TestCase):
                 # the intermediate 'compile' step help with debugging
                 code = compile(source.read(), replacementfile, 'exec')
                 exec(code, data)
-                r.extend(data.get('substitutions', ()))
+                for value in data.get('substitutions', ()):
+                    if len(value) != 2:
+                        msg = 'malformatted substitution in %s: %r'
+                        msg %= (replacementfile, value)
+                        raise ValueError(msg)
+                    r.append(value)
         return r
 
     def _escapepath(self, p):