[PATCH] tests: asciify all output

Martin Geisler mg at aragost.com
Wed Sep 1 10:15:49 CDT 2010


Mads Kiilerich <mads at kiilerich.com> writes:

> # HG changeset patch
> # User Mads Kiilerich <mads at kiilerich.com>
> # Date 1283352508 -7200
> # Node ID 48e8c92c6f9ca78f986870482ff0d1ae3961d21a
> # Parent  a55e3c50868fc2e827f44187c7fd3f6c4e2f3f31
> tests: asciify all output
>
> This encodes all non-ascii and control code output from tests with
> python-style \-escapes.
>
> This avoids the problem with handling non-ascii test output as
> non-ascii.

I think this is a nice idea and something which we've already done on a
small scale in those tests that use $TESTDIR/printrepr.py.

> This changes the output of some tests - but to the better, IMHO, even
> though it makes it less sh-ish.
>
> (Some people, when confronted with a problem, think "I know, I'll use
> regular expressions." Now they have two problems.)
>
> diff --git a/tests/run-tests.py b/tests/run-tests.py
> --- a/tests/run-tests.py
> +++ b/tests/run-tests.py
> @@ -460,6 +460,15 @@
>      vlog("# Running", cmd)
>      return run(cmd, options)
>  
> +asciifyre = re.compile(r'[\x00-\x08\x0a-\x1f\\\x7f-\xff]', re.MULTILINE) # match \t=\x09 or not?
> +def asciify(s):
> +    def f(m):
> +        c = m.group(0)
> +        if c in '\r\n\t':
> +            return {'\r': r'\r', '\n': '\n', '\t': r'\t'}[c]
> +        return r'\x%02X' % ord(c)
> +    return asciifyre.sub(f, s)

I think you can just use s.encode('string-escape') to do this.

>  def tsttest(test, options):
>      t = open(test)
>      out = []
> @@ -514,6 +523,7 @@
>                  postout += after.pop(pos)
>              pos = int(l.split()[1])
>          else:
> +            l = asciify(l)
>              el = None
>              if pos in expected and expected[pos]:
>                  el = expected[pos].pop(0)

-- 
Martin Geisler

aragost Trifork
Professional Mercurial support
http://aragost.com/mercurial/


More information about the Mercurial-devel mailing list