##// END OF EJS Templates
tests: don't run test-convert-cvs if there's no cvs server
Dirkjan Ochtman -
r6626:59f7b804 default
parent child Browse files
Show More
@@ -1,186 +1,187 b''
1 1 #!/usr/bin/env python
2 2 """Test the running system for features availability. Exit with zero
3 3 if all features are there, non-zero otherwise. If a feature name is
4 4 prefixed with "no-", the absence of feature is tested.
5 5 """
6 6 import optparse
7 7 import os
8 8 import re
9 9 import sys
10 10 import tempfile
11 11
12 12 tempprefix = 'hg-hghave-'
13 13
14 14 def matchoutput(cmd, regexp, ignorestatus=False):
15 15 """Return True if cmd executes successfully and its output
16 16 is matched by the supplied regular expression.
17 17 """
18 18 r = re.compile(regexp)
19 19 fh = os.popen(cmd)
20 20 s = fh.read()
21 21 ret = fh.close()
22 22 return (ignorestatus or ret is None) and r.search(s)
23 23
24 24 def has_baz():
25 25 return matchoutput('baz --version 2>&1', r'baz Bazaar version')
26 26
27 27 def has_cvs():
28 return matchoutput('cvs --version 2>&1', r'Concurrent Versions System')
28 re = r'Concurrent Versions System.*?server'
29 return matchoutput('cvs --version 2>&1', re)
29 30
30 31 def has_cvsps():
31 32 return matchoutput('cvsps -h -q 2>&1', r'cvsps version', True)
32 33
33 34 def has_darcs():
34 35 return matchoutput('darcs', r'darcs version', True)
35 36
36 37 def has_mtn():
37 38 return matchoutput('mtn --version', r'monotone', True) and not matchoutput(
38 39 'mtn --version', r'monotone 0\.(\d|[12]\d|3[01])[^\d]', True)
39 40
40 41 def has_eol_in_paths():
41 42 try:
42 43 fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r')
43 44 os.close(fd)
44 45 os.remove(path)
45 46 return True
46 47 except:
47 48 return False
48 49
49 50 def has_executablebit():
50 51 fd, path = tempfile.mkstemp(prefix=tempprefix)
51 52 os.close(fd)
52 53 try:
53 54 s = os.lstat(path).st_mode
54 55 os.chmod(path, s | 0100)
55 56 return (os.lstat(path).st_mode & 0100 != 0)
56 57 finally:
57 58 os.remove(path)
58 59
59 60 def has_fifo():
60 61 return hasattr(os, "mkfifo")
61 62
62 63 def has_hotshot():
63 64 try:
64 65 # hotshot.stats tests hotshot and many problematic dependencies
65 66 # like profile.
66 67 import hotshot.stats
67 68 return True
68 69 except ImportError:
69 70 return False
70 71
71 72 def has_lsprof():
72 73 try:
73 74 import _lsprof
74 75 return True
75 76 except ImportError:
76 77 return False
77 78
78 79 def has_git():
79 80 return matchoutput('git --version 2>&1', r'^git version')
80 81
81 82 def has_svn():
82 83 return matchoutput('svn --version 2>&1', r'^svn, version') and \
83 84 matchoutput('svnadmin --version 2>&1', r'^svnadmin, version')
84 85
85 86 def has_svn_bindings():
86 87 try:
87 88 import svn.core
88 89 return True
89 90 except ImportError:
90 91 return False
91 92
92 93 def has_symlink():
93 94 return hasattr(os, "symlink")
94 95
95 96 def has_tla():
96 97 return matchoutput('tla --version 2>&1', r'The GNU Arch Revision')
97 98
98 99 def has_unix_permissions():
99 100 d = tempfile.mkdtemp(prefix=tempprefix, dir=".")
100 101 try:
101 102 fname = os.path.join(d, 'foo')
102 103 for umask in (077, 007, 022):
103 104 os.umask(umask)
104 105 f = open(fname, 'w')
105 106 f.close()
106 107 mode = os.stat(fname).st_mode
107 108 os.unlink(fname)
108 109 if mode & 0777 != ~umask & 0666:
109 110 return False
110 111 return True
111 112 finally:
112 113 os.rmdir(d)
113 114
114 115 def has_pygments():
115 116 try:
116 117 import pygments
117 118 return True
118 119 except ImportError:
119 120 return False
120 121
121 122 checks = {
122 123 "baz": (has_baz, "GNU Arch baz client"),
123 "cvs": (has_cvs, "cvs client"),
124 "cvs": (has_cvs, "cvs client/server"),
124 125 "cvsps": (has_cvsps, "cvsps utility"),
125 126 "darcs": (has_darcs, "darcs client"),
126 127 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
127 128 "execbit": (has_executablebit, "executable bit"),
128 129 "fifo": (has_fifo, "named pipes"),
129 130 "git": (has_git, "git command line client"),
130 131 "hotshot": (has_hotshot, "python hotshot module"),
131 132 "lsprof": (has_lsprof, "python lsprof module"),
132 133 "mtn": (has_mtn, "monotone client (> 0.31)"),
133 134 "svn": (has_svn, "subversion client and admin tools"),
134 135 "svn-bindings": (has_svn_bindings, "subversion python bindings"),
135 136 "symlink": (has_symlink, "symbolic links"),
136 137 "tla": (has_tla, "GNU Arch tla client"),
137 138 "unix-permissions": (has_unix_permissions, "unix-style permissions"),
138 139 "pygments": (has_pygments, "Pygments source highlighting library"),
139 140 }
140 141
141 142 def list_features():
142 143 for name, feature in checks.iteritems():
143 144 desc = feature[1]
144 145 print name + ':', desc
145 146
146 147 parser = optparse.OptionParser("%prog [options] [features]")
147 148 parser.add_option("--list-features", action="store_true",
148 149 help="list available features")
149 150 parser.add_option("-q", "--quiet", action="store_true",
150 151 help="check features silently")
151 152
152 153 if __name__ == '__main__':
153 154 options, args = parser.parse_args()
154 155 if options.list_features:
155 156 list_features()
156 157 sys.exit(0)
157 158
158 159 quiet = options.quiet
159 160
160 161 failures = 0
161 162
162 163 def error(msg):
163 164 global failures
164 165 if not quiet:
165 166 sys.stderr.write(msg + '\n')
166 167 failures += 1
167 168
168 169 for feature in args:
169 170 negate = feature.startswith('no-')
170 171 if negate:
171 172 feature = feature[3:]
172 173
173 174 if feature not in checks:
174 175 error('skipped: unknown feature: ' + feature)
175 176 continue
176 177
177 178 check, desc = checks[feature]
178 179 if not negate and not check():
179 180 error('skipped: missing feature: ' + desc)
180 181 elif negate and check():
181 182 error('skipped: system supports %s' % desc)
182 183
183 184 if failures != 0:
184 185 sys.exit(1)
185 186
186 187
General Comments 0
You need to be logged in to leave comments. Login now