Patchwork D3039: tests: conditionalize tests based on presence of custom extensions

login
register
mail settings
Submitter phabricator
Date April 3, 2018, 5:54 p.m.
Message ID <differential-rev-PHID-DREV-nfoetgsctf4ccf5tf5q4-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/30202/
State Superseded
Headers show

Comments

phabricator - April 3, 2018, 5:54 p.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The test harness supports injecting extensions via --extra-config-opt.
  However, if you do this, various tests that print state about loaded
  extensions fail.
  
  This commit teaches the test harness to recognize when custom
  extensions are loaded so that tests can use feature sniffing to
  conditionalize tests based on that.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3039

AFFECTED FILES
  tests/helpers-testrepo.sh
  tests/hghave.py
  tests/run-tests.py
  tests/test-basic.t
  tests/test-debugextensions.t
  tests/test-extension.t
  tests/test-globalopts.t
  tests/test-help.t

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel
phabricator - April 4, 2018, 6:08 p.m.
durin42 added a comment.


  Could this be more tightly integrated with --extra-config-opt?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3039

To: indygreg, #hg-reviewers
Cc: durin42, mercurial-devel
phabricator - April 4, 2018, 6:18 p.m.
indygreg added a comment.


  In https://phab.mercurial-scm.org/D3039#49541, @durin42 wrote:
  
  > Could this be more tightly integrated with --extra-config-opt?
  
  
  What do you mean by that?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3039

To: indygreg, #hg-reviewers
Cc: durin42, mercurial-devel
phabricator - April 4, 2018, 6:59 p.m.
durin42 added a comment.


  In https://phab.mercurial-scm.org/D3039#49575, @indygreg wrote:
  
  > In https://phab.mercurial-scm.org/D3039#49541, @durin42 wrote:
  >
  > > Could this be more tightly integrated with --extra-config-opt?
  >
  >
  > What do you mean by that?
  
  
  Broadly, I'm wondering why we're adding support for an environment variable that's duplicating the functionality of --extra-config-opt, when the latter can already be used for this, and maybe we could get the test runner to read the --extra-config-opts and expose those somehow to hghave. Does that make sense? Am I talking crazy?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3039

To: indygreg, #hg-reviewers
Cc: durin42, mercurial-devel
phabricator - April 4, 2018, 7:16 p.m.
indygreg added a comment.


  In https://phab.mercurial-scm.org/D3039#49612, @durin42 wrote:
  
  > In https://phab.mercurial-scm.org/D3039#49575, @indygreg wrote:
  >
  > > In https://phab.mercurial-scm.org/D3039#49541, @durin42 wrote:
  > >
  > > > Could this be more tightly integrated with --extra-config-opt?
  > >
  > >
  > > What do you mean by that?
  >
  >
  > Broadly, I'm wondering why we're adding support for an environment variable that's duplicating the functionality of --extra-config-opt, when the latter can already be used for this, and maybe we could get the test runner to read the --extra-config-opts and expose those somehow to hghave. Does that make sense? Am I talking crazy?
  
  
  So you are advocating for a more generic solution? This patch already exposes the list of extensions as an environment variable. So you want the list of extra options to be exposed instead?
  
  One reason I didn't do that is complexity: I don't want to have to parse config options from bash. It was easier to just set the list of extensions.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3039

To: indygreg, #hg-reviewers
Cc: durin42, mercurial-devel
phabricator - April 4, 2018, 8:16 p.m.
durin42 added inline comments.

INLINE COMMENTS

> run-tests.py:1075
> +        for opt in self._extraconfigopts:
> +            section, key = opt.encode('utf-8').split(b'.', 1)
> +            name = key.split(b'=', 1)[0]

Soooooooo I'm dumb and misread this the last couple of times. Should this be doing

if section != 'extensions':

  continue?

Other than that this is what I was proposing, and I'm not sure how I misread it so badly before. :(

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3039

To: indygreg, #hg-reviewers
Cc: durin42, mercurial-devel

Patch

diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -44,6 +44,10 @@ 
    summary       summarize working directory state
    update        update working directory (or switch revisions)
 
+Extra extensions will be printed in help output in a non-reliable order since
+the extension is unknown.
+#if no-extraextensions
+
   $ hg help
   Mercurial Distributed SCM
   
@@ -283,6 +287,8 @@ 
        win32mbcs     allow the use of MBCS paths with problematic encodings
        zeroconf      discover and advertise repositories on the local network
 
+#endif
+
 Verify that deprecated extensions are included if --verbose:
 
   $ hg -v help extensions | grep children
@@ -816,6 +822,8 @@ 
 
 Test that default list of commands omits extension commands
 
+#if no-extraextensions
+
   $ hg help
   Mercurial Distributed SCM
   
@@ -903,6 +911,7 @@ 
   
   (use 'hg help -v' to show built-in aliases and global options)
 
+#endif
 
 Test list of internal help commands
 
diff --git a/tests/test-globalopts.t b/tests/test-globalopts.t
--- a/tests/test-globalopts.t
+++ b/tests/test-globalopts.t
@@ -289,6 +289,8 @@ 
 
 Testing -h/--help:
 
+#if no-extraextensions
+
   $ hg -h
   Mercurial Distributed SCM
   
@@ -372,8 +374,6 @@ 
   
   (use 'hg help -v' to show built-in aliases and global options)
 
-
-
   $ hg --help
   Mercurial Distributed SCM
   
@@ -457,5 +457,7 @@ 
   
   (use 'hg help -v' to show built-in aliases and global options)
 
+#endif
+
 Not tested: --debugger
 
diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -867,9 +867,11 @@ 
 Show extensions:
 (note that mq force load strip, also checking it's not loaded twice)
 
+#if no-extraextensions
   $ hg debugextensions
   mq
   strip
+#endif
 
 For extensions, which name matches one of its commands, help
 message should ask '-v -e' to get list of built-in aliases
diff --git a/tests/test-debugextensions.t b/tests/test-debugextensions.t
--- a/tests/test-debugextensions.t
+++ b/tests/test-debugextensions.t
@@ -1,4 +1,6 @@ 
+#if no-extraextensions
   $ hg debugextensions
+#endif
 
   $ debugpath=`pwd`/extwithoutinfos.py
 
@@ -19,6 +21,10 @@ 
   > ext2 = `pwd`/extwithinfos.py
   > EOF
 
+  $ for extension in $HGTESTEXTRAEXTENSIONS; do
+  >     echo "$extension=!" >> $HGRCPATH
+  > done
+
   $ hg debugextensions
   ext1 (untested!)
   ext2 (3.2.1!)
diff --git a/tests/test-basic.t b/tests/test-basic.t
--- a/tests/test-basic.t
+++ b/tests/test-basic.t
@@ -1,5 +1,6 @@ 
 Create a repository:
 
+#if no-extraextensions
   $ hg config
   devel.all-warnings=true
   devel.default-date=0 0
@@ -13,6 +14,8 @@ 
   web.address=localhost
   web\.ipv6=(?:True|False) (re)
   web.server-header=testing stub value
+#endif
+
   $ hg init t
   $ cd t
 
diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1070,6 +1070,15 @@ 
         env["HGENCODINGMODE"] = "strict"
         env['HGIPV6'] = str(int(self._useipv6))
 
+        extraextensions = []
+        for opt in self._extraconfigopts:
+            section, key = opt.encode('utf-8').split(b'.', 1)
+            name = key.split(b'=', 1)[0]
+            extraextensions.append(name)
+
+        if extraextensions:
+            env['HGTESTEXTRAEXTENSIONS'] = b' '.join(extraextensions)
+
         # LOCALIP could be ::1 or 127.0.0.1. Useful for tests that require raw
         # IP addresses.
         env['LOCALIP'] = self._localip()
diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -718,6 +718,10 @@ 
     except (ImportError, AttributeError):
         return False
 
+@check('extraextensions', 'whether tests are running with extra extensions')
+def has_extraextensions():
+    return 'HGTESTEXTRAEXTENSIONS' in os.environ
+
 def getrepofeatures():
     """Obtain set of repository features in use.
 
diff --git a/tests/helpers-testrepo.sh b/tests/helpers-testrepo.sh
--- a/tests/helpers-testrepo.sh
+++ b/tests/helpers-testrepo.sh
@@ -9,6 +9,13 @@ 
 # The mercurial source repository was typically orignally cloned with the
 # system mercurial installation, and may require extensions or settings from
 # the system installation.
+
+if [ -n $HGTESTEXTRAEXTENSIONS ]; then
+    for extension in $HGTESTEXTRAEXTENSIONS; do
+        extraoptions="$extraoptions --config extensions.$extension=!"
+    done
+fi
+
 syshg () {
     (
         syshgenv
@@ -48,6 +55,6 @@ 
     alias testrepohg=syshg
     alias testrepohgenv=syshgenv
 else
-    alias testrepohg=hg
+    alias testrepohg="hg $extraoptions"
     alias testrepohgenv=:
 fi