diff --git a/tests/hghave b/tests/hghave index cd1daab5d03650305ba6aa3b44a5c8ced147ff6b_dGVzdHMvaGdoYXZl..b94df10cc3b5a72175143c38bc2283279c406f59_dGVzdHMvaGdoYXZl 100755 --- a/tests/hghave +++ b/tests/hghave @@ -4,7 +4,7 @@ prefixed with "no-", the absence of feature is tested. """ import optparse -import sys +import os, sys import hghave checks = hghave.checks @@ -33,5 +33,26 @@ parser.add_option("-q", "--quiet", action="store_true", help="check features silently") +def _loadaddon(quiet): + if 'TESTDIR' in os.environ: + # loading from '.' isn't needed, because `hghave` should be + # running at TESTTMP in this case + path = os.environ['TESTDIR'] + else: + path = '.' + + if not os.path.exists(os.path.join(path, 'hghaveaddon.py')): + return + + sys.path.insert(0, path) + try: + import hghaveaddon + except BaseException, inst: + if not quiet: + sys.stderr.write('failed to import hghaveaddon.py from %r: %s\n' + % (path, inst)) + sys.exit(2) + sys.path.pop(0) + if __name__ == '__main__': options, args = parser.parse_args() @@ -36,5 +57,6 @@ if __name__ == '__main__': options, args = parser.parse_args() + _loadaddon(options.quiet) if options.list_features: list_features() sys.exit(0) diff --git a/tests/test-hghave.t b/tests/test-hghave.t index cd1daab5d03650305ba6aa3b44a5c8ced147ff6b_dGVzdHMvdGVzdC1oZ2hhdmUudA==..b94df10cc3b5a72175143c38bc2283279c406f59_dGVzdHMvdGVzdC1oZ2hhdmUudA== 100644 --- a/tests/test-hghave.t +++ b/tests/test-hghave.t @@ -1,3 +1,39 @@ Testing that hghave does not crash when checking features $ hghave --test-features 2>/dev/null + +Testing hghave extensibility for third party tools + + $ cat > hghaveaddon.py <<EOF + > import hghave + > @hghave.check("custom", "custom hghave feature") + > def has_custom(): + > return True + > EOF + +(invocation via run-tests.py) + + $ cat > test-hghaveaddon.t <<EOF + > #require custom + > $ echo foo + > foo + > EOF + $ run-tests.py test-hghaveaddon.t + . + # Ran 1 tests, 0 skipped, 0 warned, 0 failed. + +(invocation via command line) + + $ unset TESTDIR + $ hghave custom + +(terminate with exit code 2 at failure of importing hghaveaddon.py) + + $ rm hghaveaddon.* + $ cat > hghaveaddon.py <<EOF + > importing this file should cause syntax error + > EOF + + $ hghave custom + failed to import hghaveaddon.py from '.': invalid syntax (hghaveaddon.py, line 1) + [2]