comparison tests/test-hghave.t @ 25732:b94df10cc3b5

hghave: allow adding customized features at runtime Before this patch, there is no way to add customized features to `hghave` without changing `hghave` and `hghave.py` themselves. This decreases reusability of `run-tests.py` framework for third party tools, because they may want to examine custom features at runtime (e.g. existence of some external tools). To allow adding customized features at runtime, this patch makes `hghave` import `hghaveaddon` module, only when `hghaveaddon.py` file can be found in directories below: - `TESTDIR` for invocation via `run-tests.py` - `.` for invocation via command line The path to the directory where `hghaveaddon.py` should be placed is added to `sys.path` only while importing `hghaveaddon`, because: - `.` may not be added to `PYTHONPATH` - adding additional path to `sys.path` may change behavior of subsequent `import` for other features `hghave` is terminated with exit code '2' at failure of `import hghaveaddon`, because exit code '2' terminates `run-tests.py` immediately. This is a one of preparations for issue4677.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 03 Jul 2015 06:56:03 +0900
parents 4d2b9b304ad0
children 342ab95a1f4b
comparison
equal deleted inserted replaced
25731:cd1daab5d036 25732:b94df10cc3b5
1 Testing that hghave does not crash when checking features 1 Testing that hghave does not crash when checking features
2 2
3 $ hghave --test-features 2>/dev/null 3 $ hghave --test-features 2>/dev/null
4
5 Testing hghave extensibility for third party tools
6
7 $ cat > hghaveaddon.py <<EOF
8 > import hghave
9 > @hghave.check("custom", "custom hghave feature")
10 > def has_custom():
11 > return True
12 > EOF
13
14 (invocation via run-tests.py)
15
16 $ cat > test-hghaveaddon.t <<EOF
17 > #require custom
18 > $ echo foo
19 > foo
20 > EOF
21 $ run-tests.py test-hghaveaddon.t
22 .
23 # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
24
25 (invocation via command line)
26
27 $ unset TESTDIR
28 $ hghave custom
29
30 (terminate with exit code 2 at failure of importing hghaveaddon.py)
31
32 $ rm hghaveaddon.*
33 $ cat > hghaveaddon.py <<EOF
34 > importing this file should cause syntax error
35 > EOF
36
37 $ hghave custom
38 failed to import hghaveaddon.py from '.': invalid syntax (hghaveaddon.py, line 1)
39 [2]