[PATCH 1 of 6 STABLE v2] test-glog.t: use printrevset extension to trace rewritten revsets

Patrick Mezard patrick at mezard.eu
Wed Feb 22 11:31:32 UTC 2012


# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1329910214 -3600
# Branch stable
# Node ID 68d017872188e8de77c67826d20fd69a2b09ade9
# Parent  0e0060bf2f440d5cc33e5f36d99868a5380debd4
test-glog.t: use printrevset extension to trace rewritten revsets

Using "hg log -G --print-revset" prints the revset generated by graphlog and
exits. This helps debugging and writing shorter tests.

It has been suggested to handle these tests with doctests. I think the
extension approach is better because:
- It tests the actual parameter set passed to graphlog.revset(), not what we
  expect it to be. 'branch' and 'only-branch' are currently distinct options
  but nothing prevents fancyopts to grow a notion of option aliasing one day,
  where both options would be merged before reaching the command.
- It can be used as debug output interleaved with real log calls.

v2:
- Use a test extension instead of a global deprecated new option

diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -83,8 +83,26 @@
   >   hg commit -Aqd "$rev 0" -m "($rev) $msg"
   > }
 
+  $ cat > printrevset.py <<EOF
+  > from mercurial import extensions, revset, commands
+  > from hgext import graphlog
+  >  
+  > def uisetup(ui):
+  >     def printrevset(orig, ui, repo, *pats, **opts):
+  >         if opts.get('print_revset'):
+  >             expr = graphlog.revset(pats, opts)
+  >             tree = revset.parse(expr)[0]
+  >             ui.write(tree, "\n")
+  >             return 0
+  >         return orig(ui, repo, *pats, **opts)
+  >     entry = extensions.wrapcommand(commands.table, 'log', printrevset)
+  >     entry[1].append(('', 'print-revset', False,
+  >                      'print generated revset and exit (DEPRECATED)'))
+  > EOF
+
   $ echo "[extensions]" >> $HGRCPATH
   $ echo "graphlog=" >> $HGRCPATH
+  $ echo "printrevset=`pwd`/printrevset.py" >> $HGRCPATH
 
   $ hg init repo
   $ cd repo
@@ -1400,7 +1418,8 @@
   $ hg log -G -b 'something nice'
   abort: unknown revision 'something nice'!
   [255]
-  $ hg log -G -k 'something nice'
+  $ hg log -G --print-revset -k 'something' -k 'nice'
+  ('group', ('and', ('func', ('symbol', 'keyword'), ('string', 'something')), ('func', ('symbol', 'keyword'), ('string', 'nice'))))
   $ hg log -G --only-branch 'something nice'
   abort: unknown revision 'something nice'!
   [255]



More information about the Mercurial-devel mailing list