Mercurial > hg
changeset 37342:4e6a6d0dccee
tests: conditionalize tests based on presence of custom extensions
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.
Differential Revision: https://phab.mercurial-scm.org/D3039
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 04 Apr 2018 13:21:34 -0700 |
parents | d62d2e346acf |
children | 0611c954da90 |
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 |
diffstat | 8 files changed, 47 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/helpers-testrepo.sh Wed Apr 04 12:16:50 2018 -0700 +++ b/tests/helpers-testrepo.sh Wed Apr 04 13:21:34 2018 -0700 @@ -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
--- a/tests/hghave.py Wed Apr 04 12:16:50 2018 -0700 +++ b/tests/hghave.py Wed Apr 04 13:21:34 2018 -0700 @@ -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.
--- a/tests/run-tests.py Wed Apr 04 12:16:50 2018 -0700 +++ b/tests/run-tests.py Wed Apr 04 13:21:34 2018 -0700 @@ -1070,6 +1070,17 @@ env["HGENCODINGMODE"] = "strict" env['HGIPV6'] = str(int(self._useipv6)) + extraextensions = [] + for opt in self._extraconfigopts: + section, key = opt.encode('utf-8').split(b'.', 1) + if section != 'extensions': + continue + 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()
--- a/tests/test-basic.t Wed Apr 04 12:16:50 2018 -0700 +++ b/tests/test-basic.t Wed Apr 04 13:21:34 2018 -0700 @@ -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
--- a/tests/test-debugextensions.t Wed Apr 04 12:16:50 2018 -0700 +++ b/tests/test-debugextensions.t Wed Apr 04 13:21:34 2018 -0700 @@ -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!)
--- a/tests/test-extension.t Wed Apr 04 12:16:50 2018 -0700 +++ b/tests/test-extension.t Wed Apr 04 13:21:34 2018 -0700 @@ -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
--- a/tests/test-globalopts.t Wed Apr 04 12:16:50 2018 -0700 +++ b/tests/test-globalopts.t Wed Apr 04 13:21:34 2018 -0700 @@ -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
--- a/tests/test-help.t Wed Apr 04 12:16:50 2018 -0700 +++ b/tests/test-help.t Wed Apr 04 13:21:34 2018 -0700 @@ -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