diff tests/test-revset.t @ 27586:42910f9fffeb

revset: use delayregistrar to register predicate in extension easily Previous patch introduced 'revset.predicate' decorator to register revset predicate function easily. But it shouldn't be used in extension directly, because it registers specified function immediately. Registration itself can't be restored, even if extension loading fails after that. Therefore, registration should be delayed until 'uisetup()' or so. This patch uses 'extpredicate' decorator derived from 'delayregistrar' to register predicate in extension easily. This patch also tests whether 'registrar.delayregistrar' avoids function registration if 'setup()' isn't invoked on it, because 'extpredicate' is the first user of it.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 29 Dec 2015 23:58:30 +0900
parents c60a9c16ae25
children b3376fba4ab9
line wrap: on
line diff
--- a/tests/test-revset.t	Tue Dec 29 23:58:30 2015 +0900
+++ b/tests/test-revset.t	Tue Dec 29 23:58:30 2015 +0900
@@ -2189,3 +2189,43 @@
   [255]
 
   $ cd ..
+
+Test registrar.delayregistrar via revset.extpredicate
+
+'extpredicate' decorator shouldn't register any functions until
+'setup()' on it.
+
+  $ cd repo
+
+  $ cat <<EOF > $TESTTMP/custompredicate.py
+  > from mercurial import revset
+  > 
+  > revsetpredicate = revset.extpredicate()
+  > 
+  > @revsetpredicate('custom1()')
+  > def custom1(repo, subset, x):
+  >     return revset.baseset([1])
+  > @revsetpredicate('custom2()')
+  > def custom2(repo, subset, x):
+  >     return revset.baseset([2])
+  > 
+  > def uisetup(ui):
+  >     if ui.configbool('custompredicate', 'enabled'):
+  >         revsetpredicate.setup()
+  > EOF
+  $ cat <<EOF > .hg/hgrc
+  > [extensions]
+  > custompredicate = $TESTTMP/custompredicate.py
+  > EOF
+
+  $ hg debugrevspec "custom1()"
+  hg: parse error: unknown identifier: custom1
+  [255]
+  $ hg debugrevspec "custom2()"
+  hg: parse error: unknown identifier: custom2
+  [255]
+  $ hg debugrevspec "custom1() or custom2()" --config custompredicate.enabled=true
+  1
+  2
+
+  $ cd ..