| 1 |
#!/usr/bin/env python3 |
| 2 |
"""Test the running system for features availability. Exit with zero |
| 3 |
if all features are there, non-zero otherwise. If a feature name is |
| 4 |
prefixed with "no-", the absence of feature is tested. |
| 5 |
""" |
| 6 |
|
| 7 |
|
| 8 |
import hghave |
| 9 |
import optparse |
| 10 |
import os |
| 11 |
import sys |
| 12 |
|
| 13 |
checks = hghave.checks |
| 14 |
|
| 15 |
|
| 16 |
def list_features(): |
| 17 |
for name, feature in sorted(checks.items()): |
| 18 |
desc = feature[1] |
| 19 |
print(name + ':', desc) |
| 20 |
|
| 21 |
|
| 22 |
def test_features(): |
| 23 |
failed = 0 |
| 24 |
for name, feature in checks.items(): |
| 25 |
check, _ = feature |
| 26 |
try: |
| 27 |
check() |
| 28 |
except Exception as e: |
| 29 |
print("feature %s failed: %s" % (name, e)) |
| 30 |
failed += 1 |
| 31 |
return failed |
| 32 |
|
| 33 |
|
| 34 |
parser = optparse.OptionParser("%prog [options] [features]") |
| 35 |
parser.add_option( |
| 36 |
"--test-features", action="store_true", help="test available features" |
| 37 |
) |
| 38 |
parser.add_option( |
| 39 |
"--list-features", action="store_true", help="list available features" |
| 40 |
) |
| 41 |
|
| 42 |
|
| 43 |
def _loadaddon(): |
| 44 |
if 'TESTDIR' in os.environ: |
| 45 |
# loading from '.' isn't needed, because `hghave` should be |
| 46 |
# running at TESTTMP in this case |
| 47 |
path = os.environ['TESTDIR'] |
| 48 |
else: |
| 49 |
path = '.' |
| 50 |
|
| 51 |
if not os.path.exists(os.path.join(path, 'hghaveaddon.py')): |
| 52 |
return |
| 53 |
|
| 54 |
sys.path.insert(0, path) |
| 55 |
try: |
| 56 |
import hghaveaddon |
| 57 |
|
| 58 |
assert hghaveaddon # silence pyflakes |
| 59 |
except BaseException as inst: |
| 60 |
sys.stderr.write( |
| 61 |
'failed to import hghaveaddon.py from %r: %s\n' % (path, inst) |
| 62 |
) |
| 63 |
sys.exit(2) |
| 64 |
sys.path.pop(0) |
| 65 |
|
| 66 |
|
| 67 |
if __name__ == '__main__': |
| 68 |
options, args = parser.parse_args() |
| 69 |
_loadaddon() |
| 70 |
if options.list_features: |
| 71 |
list_features() |
| 72 |
sys.exit(0) |
| 73 |
|
| 74 |
if options.test_features: |
| 75 |
sys.exit(test_features()) |
| 76 |
|
| 77 |
hghave.require(args) |