[PATCH 2 of 5] tests: basic support for unified tests

Matt Mackall mpm at selenic.com
Wed Aug 4 10:20:29 CDT 2010


On Wed, 2010-08-04 at 09:34 -0400, Greg Ward wrote:
> On Tue, Aug 3, 2010 at 1:15 AM, Matt Mackall <mpm at selenic.com> wrote:
> > # HG changeset patch
> > # User Matt Mackall <mpm at selenic.com>
> > # Date 1280809642 18000
> > # Node ID 431e2bf37ae7d09ff44ce564252321c205a47d00
> > # Parent  e5c79e31feb643655aa6a2e201d46479457c2626
> > tests: basic support for unified tests
> 
> Neat.
> 
> > --- a/tests/run-tests.py        Mon Aug 02 15:44:54 2010 -0500
> > +++ b/tests/run-tests.py        Mon Aug 02 23:27:22 2010 -0500
> > @@ -52,6 +52,7 @@
> >  import sys
> >  import tempfile
> >  import time
> > +import re
> >
> >  closefds = os.name == 'posix'
> >  def Popen4(cmd, bufsize=-1):
> > @@ -459,6 +460,69 @@
> >     vlog("# Running", cmd)
> >     return run(cmd, options)
> >
> > +def tsttest(test, options):
> > +    t = open(test)
> > +    out = []
> > +    script = []
> > +    salt = "SALT" + str(time.time())
> > +
> > +    pos = prepos = -1
> > +    after = {}
> > +    expected = {}
> > +    for n, l in enumerate(t):
> > +        if l.startswith('  $ '): # commands
> > +            after.setdefault(pos, []).append(l)
> > +            prepos = pos
> > +            pos = n
> > +            script.append('echo %s %s\n' % (salt, n))
> > +            script.append(l[4:])
> > +        elif l.startswith('  > '): # continuations
> > +            after.setdefault(prepos, []).append(l)
> > +            script.append(l[4:])
> 
> Is this just for breaking long commands across multiple lines?  E.g.:
> 
>   $ hg log
>   > --template "really long template"
> 
> Or is it something more subtle that I'm missing?

It's for things like 

  $ dumptags() {
  >     rev=$1
  >     echo "rev $rev: .hgtags:"
  >     hg cat -r$rev .hgtags
  > }

...where our insertion of marker echos will break things.


> > +        elif l.startswith('  '): # results
> > +            # queue up a list of expected results
> > +            expected.setdefault(pos, []).append(l[2:])
> 
> So there's no distinction between stdout and stderr?

Nope.

> And no way to
> verify the exit status?

hg pull ; echo $?

> Err, what about Windows?

Not addressed here. But there are various possibilities now that we're
actually preprocessing the test. For instance:

$ hg init
U$ echo blah > a
U: some Unix output
W$ type blah > a
W: some Windows output
$ hg ci -qAm0

And we can obviously improve this by converting 'echo' to 'type' on the
fly. This sort of thing should be enough to get a decent percentage of
tests working.

> I suspect we will ultimately need to turn those .t files in to Python
> code.  Or have a Python library that directly executes the specified
> commands and tests their outcomes.

Or we can do something like the latter.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list