[PATCH 1 of 2 RFC] tests: asciify test output marked as (escape)

Yuya Nishihara yuya at tcha.org
Thu Sep 30 11:24:11 CDT 2010


Brodie Rao wrote:
> On Wed, Sep 29, 2010 at 11:31 AM, Yuya Nishihara <yuya at tcha.org> wrote:
> > # HG changeset patch
> > # User Yuya Nishihara <yuya at tcha.org>
> > # Date 1285773571 -32400
> > # Node ID 497c8c87e8f0882b4a6bd347888e428390827f7b
> > # Parent  385fd0eee00524733b7f500a032214b72af78937
> > tests: asciify test output marked as (escape)
> >
> > It encodes non-ascii and most control characters of outputs to python-style
> > \-escapes. It aims to avoid trouble with outputs for non-ascii, color
> > and progress tests.
> >
> > diff --git a/tests/run-tests.py b/tests/run-tests.py
> > --- a/tests/run-tests.py
> > +++ b/tests/run-tests.py
> > @@ -532,6 +532,11 @@ def tsttest(test, options):
> >                 res += re.escape(c)
> >         return rematch(res, l)
> >
> > +    def escapematch(el, l):
> > +        # escape everything except for last '\n' character
> > +        escl = l[:-1].encode('string-escape').replace(r"\'", "'") + l[-1:]
> > +        return el == escl
> > +
> >     pos = -1
> >     postout = []
> >     ret = 0
> > @@ -553,7 +558,9 @@ def tsttest(test, options):
> >                 postout.append("  " + l)
> >             elif (el and
> >                   (el.endswith(" (re)\n") and rematch(el[:-6] + '\n', l) or
> > -                   el.endswith(" (glob)\n") and globmatch(el[:-8] + '\n', l))):
> > +                   el.endswith(" (glob)\n") and globmatch(el[:-8] + '\n', l) or
> > +                   el.endswith(" (escape)\n") and escapematch(el[:-10] + '\n',
> > +                                                              l))):
> 
> I think it'd be cleaner if we tested the matches without the trailing
> newline from either string. This would also make silly regexes like
> "foo\ (re)" not match "foo".

Like this?

+                 (el.endswith(" (re)\n") and rematch(el[:-6], l[:-1]) or
+                   el.endswith(" (glob)\n") and globmatch(el[:-8], l[:-1]))):
+                   el.endswith(" (glob)\n") and globmatch(el[:-8], l[:-1]) or
+                   el.endswith(" (escape)\n") and escapematch(el[:-10], l[:-1]))):

Yuya,


More information about the Mercurial-devel mailing list