##// END OF EJS Templates
tests: update ssl requirement for test-https.t...
Mads Kiilerich -
r13418:28555e29 default
parent child Browse files
Show More
@@ -1,272 +1,274
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 try:
22 22 ret = fh.close()
23 23 except IOError:
24 24 # Happen in Windows test environment
25 25 ret = 1
26 26 return (ignorestatus or ret is None) and r.search(s)
27 27
28 28 def has_baz():
29 29 return matchoutput('baz --version 2>&1', r'baz Bazaar version')
30 30
31 31 def has_bzr():
32 32 try:
33 33 import bzrlib
34 34 return bzrlib.__doc__ != None
35 35 except ImportError:
36 36 return False
37 37
38 38 def has_bzr114():
39 39 try:
40 40 import bzrlib
41 41 return (bzrlib.__doc__ != None
42 42 and bzrlib.version_info[:2] >= (1, 14))
43 43 except ImportError:
44 44 return False
45 45
46 46 def has_cvs():
47 47 re = r'Concurrent Versions System.*?server'
48 48 return matchoutput('cvs --version 2>&1', re)
49 49
50 50 def has_darcs():
51 51 return matchoutput('darcs --version', r'2\.[2-9]', True)
52 52
53 53 def has_mtn():
54 54 return matchoutput('mtn --version', r'monotone', True) and not matchoutput(
55 55 'mtn --version', r'monotone 0\.(\d|[12]\d|3[01])[^\d]', True)
56 56
57 57 def has_eol_in_paths():
58 58 try:
59 59 fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r')
60 60 os.close(fd)
61 61 os.remove(path)
62 62 return True
63 63 except:
64 64 return False
65 65
66 66 def has_executablebit():
67 67 fd, path = tempfile.mkstemp(prefix=tempprefix)
68 68 os.close(fd)
69 69 try:
70 70 s = os.lstat(path).st_mode
71 71 os.chmod(path, s | 0100)
72 72 return (os.lstat(path).st_mode & 0100 != 0)
73 73 finally:
74 74 os.remove(path)
75 75
76 76 def has_icasefs():
77 77 # Stolen from mercurial.util
78 78 fd, path = tempfile.mkstemp(prefix=tempprefix, dir='.')
79 79 os.close(fd)
80 80 try:
81 81 s1 = os.stat(path)
82 82 d, b = os.path.split(path)
83 83 p2 = os.path.join(d, b.upper())
84 84 if path == p2:
85 85 p2 = os.path.join(d, b.lower())
86 86 try:
87 87 s2 = os.stat(p2)
88 88 return s2 == s1
89 89 except:
90 90 return False
91 91 finally:
92 92 os.remove(path)
93 93
94 94 def has_inotify():
95 95 try:
96 96 import hgext.inotify.linux.watcher
97 97 return True
98 98 except ImportError:
99 99 return False
100 100
101 101 def has_fifo():
102 102 return hasattr(os, "mkfifo")
103 103
104 104 def has_lsprof():
105 105 try:
106 106 import _lsprof
107 107 return True
108 108 except ImportError:
109 109 return False
110 110
111 111 def has_git():
112 112 return matchoutput('git --version 2>&1', r'^git version')
113 113
114 114 def has_docutils():
115 115 try:
116 116 from docutils.core import publish_cmdline
117 117 return True
118 118 except ImportError:
119 119 return False
120 120
121 121 def has_svn():
122 122 return matchoutput('svn --version 2>&1', r'^svn, version') and \
123 123 matchoutput('svnadmin --version 2>&1', r'^svnadmin, version')
124 124
125 125 def has_svn_bindings():
126 126 try:
127 127 import svn.core
128 128 version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
129 129 if version < (1, 4):
130 130 return False
131 131 return True
132 132 except ImportError:
133 133 return False
134 134
135 135 def has_p4():
136 136 return matchoutput('p4 -V', r'Rev\. P4/') and matchoutput('p4d -V', r'Rev\. P4D/')
137 137
138 138 def has_symlink():
139 139 return hasattr(os, "symlink")
140 140
141 141 def has_tla():
142 142 return matchoutput('tla --version 2>&1', r'The GNU Arch Revision')
143 143
144 144 def has_gpg():
145 145 return matchoutput('gpg --version 2>&1', r'GnuPG')
146 146
147 147 def has_unix_permissions():
148 148 d = tempfile.mkdtemp(prefix=tempprefix, dir=".")
149 149 try:
150 150 fname = os.path.join(d, 'foo')
151 151 for umask in (077, 007, 022):
152 152 os.umask(umask)
153 153 f = open(fname, 'w')
154 154 f.close()
155 155 mode = os.stat(fname).st_mode
156 156 os.unlink(fname)
157 157 if mode & 0777 != ~umask & 0666:
158 158 return False
159 159 return True
160 160 finally:
161 161 os.rmdir(d)
162 162
163 163 def has_pygments():
164 164 try:
165 165 import pygments
166 166 return True
167 167 except ImportError:
168 168 return False
169 169
170 170 def has_outer_repo():
171 171 return matchoutput('hg root 2>&1', r'')
172 172
173 173 def has_ssl():
174 174 try:
175 175 import ssl
176 import OpenSSL
177 OpenSSL.SSL.Context
176 178 return True
177 179 except ImportError:
178 180 return False
179 181
180 182 checks = {
181 183 "baz": (has_baz, "GNU Arch baz client"),
182 184 "bzr": (has_bzr, "Canonical's Bazaar client"),
183 185 "bzr114": (has_bzr114, "Canonical's Bazaar client >= 1.14"),
184 186 "cvs": (has_cvs, "cvs client/server"),
185 187 "darcs": (has_darcs, "darcs client"),
186 188 "docutils": (has_docutils, "Docutils text processing library"),
187 189 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
188 190 "execbit": (has_executablebit, "executable bit"),
189 191 "fifo": (has_fifo, "named pipes"),
190 192 "git": (has_git, "git command line client"),
191 193 "gpg": (has_gpg, "gpg client"),
192 194 "icasefs": (has_icasefs, "case insensitive file system"),
193 195 "inotify": (has_inotify, "inotify extension support"),
194 196 "lsprof": (has_lsprof, "python lsprof module"),
195 197 "mtn": (has_mtn, "monotone client (> 0.31)"),
196 198 "outer-repo": (has_outer_repo, "outer repo"),
197 199 "p4": (has_p4, "Perforce server and client"),
198 200 "pygments": (has_pygments, "Pygments source highlighting library"),
199 201 "ssl": (has_ssl, "python >= 2.6 ssl module"),
200 202 "svn": (has_svn, "subversion client and admin tools"),
201 203 "svn-bindings": (has_svn_bindings, "subversion python bindings"),
202 204 "symlink": (has_symlink, "symbolic links"),
203 205 "tla": (has_tla, "GNU Arch tla client"),
204 206 "unix-permissions": (has_unix_permissions, "unix-style permissions"),
205 207 }
206 208
207 209 def list_features():
208 210 for name, feature in checks.iteritems():
209 211 desc = feature[1]
210 212 print name + ':', desc
211 213
212 214 def test_features():
213 215 failed = 0
214 216 for name, feature in checks.iteritems():
215 217 check, _ = feature
216 218 try:
217 219 check()
218 220 except Exception, e:
219 221 print "feature %s failed: %s" % (name, e)
220 222 failed += 1
221 223 return failed
222 224
223 225 parser = optparse.OptionParser("%prog [options] [features]")
224 226 parser.add_option("--test-features", action="store_true",
225 227 help="test available features")
226 228 parser.add_option("--list-features", action="store_true",
227 229 help="list available features")
228 230 parser.add_option("-q", "--quiet", action="store_true",
229 231 help="check features silently")
230 232
231 233 if __name__ == '__main__':
232 234 options, args = parser.parse_args()
233 235 if options.list_features:
234 236 list_features()
235 237 sys.exit(0)
236 238
237 239 if options.test_features:
238 240 sys.exit(test_features())
239 241
240 242 quiet = options.quiet
241 243
242 244 failures = 0
243 245
244 246 def error(msg):
245 247 global failures
246 248 if not quiet:
247 249 sys.stderr.write(msg + '\n')
248 250 failures += 1
249 251
250 252 for feature in args:
251 253 negate = feature.startswith('no-')
252 254 if negate:
253 255 feature = feature[3:]
254 256
255 257 if feature not in checks:
256 258 error('skipped: unknown feature: ' + feature)
257 259 continue
258 260
259 261 check, desc = checks[feature]
260 262 try:
261 263 available = check()
262 264 except Exception, e:
263 265 error('hghave check failed: ' + feature)
264 266 continue
265 267
266 268 if not negate and not available:
267 269 error('skipped: missing feature: ' + desc)
268 270 elif negate and available:
269 271 error('skipped: system supports %s' % desc)
270 272
271 273 if failures != 0:
272 274 sys.exit(1)
General Comments 0
You need to be logged in to leave comments. Login now