##// END OF EJS Templates
tests/hghave: test that a fifo actually can be created on the filesystem...
Mads Kiilerich -
r16969:6d167310 default
parent child Browse files
Show More
@@ -1,274 +1,282 b''
1 1 import os, stat
2 2 import re
3 3 import sys
4 4 import tempfile
5 5
6 6 tempprefix = 'hg-hghave-'
7 7
8 8 def matchoutput(cmd, regexp, ignorestatus=False):
9 9 """Return True if cmd executes successfully and its output
10 10 is matched by the supplied regular expression.
11 11 """
12 12 r = re.compile(regexp)
13 13 fh = os.popen(cmd)
14 14 s = fh.read()
15 15 try:
16 16 ret = fh.close()
17 17 except IOError:
18 18 # Happen in Windows test environment
19 19 ret = 1
20 20 return (ignorestatus or ret is None) and r.search(s)
21 21
22 22 def has_baz():
23 23 return matchoutput('baz --version 2>&1', r'baz Bazaar version')
24 24
25 25 def has_bzr():
26 26 try:
27 27 import bzrlib
28 28 return bzrlib.__doc__ is not None
29 29 except ImportError:
30 30 return False
31 31
32 32 def has_bzr114():
33 33 try:
34 34 import bzrlib
35 35 return (bzrlib.__doc__ is not None
36 36 and bzrlib.version_info[:2] >= (1, 14))
37 37 except ImportError:
38 38 return False
39 39
40 40 def has_cvs():
41 41 re = r'Concurrent Versions System.*?server'
42 42 return matchoutput('cvs --version 2>&1', re) and not has_msys()
43 43
44 44 def has_darcs():
45 45 return matchoutput('darcs --version', r'2\.[2-9]', True)
46 46
47 47 def has_mtn():
48 48 return matchoutput('mtn --version', r'monotone', True) and not matchoutput(
49 49 'mtn --version', r'monotone 0\.', True)
50 50
51 51 def has_eol_in_paths():
52 52 try:
53 53 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix, suffix='\n\r')
54 54 os.close(fd)
55 55 os.remove(path)
56 56 return True
57 57 except (IOError, OSError):
58 58 return False
59 59
60 60 def has_executablebit():
61 61 try:
62 62 EXECFLAGS = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
63 63 fh, fn = tempfile.mkstemp(dir='.', prefix=tempprefix)
64 64 try:
65 65 os.close(fh)
66 66 m = os.stat(fn).st_mode & 0777
67 67 new_file_has_exec = m & EXECFLAGS
68 68 os.chmod(fn, m ^ EXECFLAGS)
69 69 exec_flags_cannot_flip = ((os.stat(fn).st_mode & 0777) == m)
70 70 finally:
71 71 os.unlink(fn)
72 72 except (IOError, OSError):
73 73 # we don't care, the user probably won't be able to commit anyway
74 74 return False
75 75 return not (new_file_has_exec or exec_flags_cannot_flip)
76 76
77 77 def has_icasefs():
78 78 # Stolen from mercurial.util
79 79 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
80 80 os.close(fd)
81 81 try:
82 82 s1 = os.stat(path)
83 83 d, b = os.path.split(path)
84 84 p2 = os.path.join(d, b.upper())
85 85 if path == p2:
86 86 p2 = os.path.join(d, b.lower())
87 87 try:
88 88 s2 = os.stat(p2)
89 89 return s2 == s1
90 90 except OSError:
91 91 return False
92 92 finally:
93 93 os.remove(path)
94 94
95 95 def has_inotify():
96 96 try:
97 97 import hgext.inotify.linux.watcher
98 98 return True
99 99 except ImportError:
100 100 return False
101 101
102 102 def has_fifo():
103 return getattr(os, "mkfifo", None) is not None
103 if getattr(os, "mkfifo", None) is None:
104 return False
105 name = tempfile.mktemp(dir='.', prefix=tempprefix)
106 try:
107 os.mkfifo(name)
108 os.unlink(name)
109 return True
110 except OSError:
111 return False
104 112
105 113 def has_cacheable_fs():
106 114 from mercurial import util
107 115
108 116 fd, path = tempfile.mkstemp(dir='.', prefix=tempprefix)
109 117 os.close(fd)
110 118 try:
111 119 return util.cachestat(path).cacheable()
112 120 finally:
113 121 os.remove(path)
114 122
115 123 def has_lsprof():
116 124 try:
117 125 import _lsprof
118 126 return True
119 127 except ImportError:
120 128 return False
121 129
122 130 def has_gettext():
123 131 return matchoutput('msgfmt --version', 'GNU gettext-tools')
124 132
125 133 def has_git():
126 134 return matchoutput('git --version 2>&1', r'^git version')
127 135
128 136 def has_docutils():
129 137 try:
130 138 from docutils.core import publish_cmdline
131 139 return True
132 140 except ImportError:
133 141 return False
134 142
135 143 def getsvnversion():
136 144 m = matchoutput('svn --version 2>&1', r'^svn,\s+version\s+(\d+)\.(\d+)')
137 145 if not m:
138 146 return (0, 0)
139 147 return (int(m.group(1)), int(m.group(2)))
140 148
141 149 def has_svn15():
142 150 return getsvnversion() >= (1, 5)
143 151
144 152 def has_svn13():
145 153 return getsvnversion() >= (1, 3)
146 154
147 155 def has_svn():
148 156 return matchoutput('svn --version 2>&1', r'^svn, version') and \
149 157 matchoutput('svnadmin --version 2>&1', r'^svnadmin, version')
150 158
151 159 def has_svn_bindings():
152 160 try:
153 161 import svn.core
154 162 version = svn.core.SVN_VER_MAJOR, svn.core.SVN_VER_MINOR
155 163 if version < (1, 4):
156 164 return False
157 165 return True
158 166 except ImportError:
159 167 return False
160 168
161 169 def has_p4():
162 170 return (matchoutput('p4 -V', r'Rev\. P4/') and
163 171 matchoutput('p4d -V', r'Rev\. P4D/'))
164 172
165 173 def has_symlink():
166 174 if getattr(os, "symlink", None) is None:
167 175 return False
168 176 name = tempfile.mktemp(dir='.', prefix=tempprefix)
169 177 try:
170 178 os.symlink(".", name)
171 179 os.unlink(name)
172 180 return True
173 181 except (OSError, AttributeError):
174 182 return False
175 183
176 184 def has_tla():
177 185 return matchoutput('tla --version 2>&1', r'The GNU Arch Revision')
178 186
179 187 def has_gpg():
180 188 return matchoutput('gpg --version 2>&1', r'GnuPG')
181 189
182 190 def has_unix_permissions():
183 191 d = tempfile.mkdtemp(dir='.', prefix=tempprefix)
184 192 try:
185 193 fname = os.path.join(d, 'foo')
186 194 for umask in (077, 007, 022):
187 195 os.umask(umask)
188 196 f = open(fname, 'w')
189 197 f.close()
190 198 mode = os.stat(fname).st_mode
191 199 os.unlink(fname)
192 200 if mode & 0777 != ~umask & 0666:
193 201 return False
194 202 return True
195 203 finally:
196 204 os.rmdir(d)
197 205
198 206 def has_pyflakes():
199 207 return matchoutput("sh -c \"echo 'import re' 2>&1 | pyflakes\"",
200 208 r"<stdin>:1: 're' imported but unused",
201 209 True)
202 210
203 211 def has_pygments():
204 212 try:
205 213 import pygments
206 214 return True
207 215 except ImportError:
208 216 return False
209 217
210 218 def has_outer_repo():
211 219 return matchoutput('hg root 2>&1', r'')
212 220
213 221 def has_ssl():
214 222 try:
215 223 import ssl
216 224 import OpenSSL
217 225 OpenSSL.SSL.Context
218 226 return True
219 227 except ImportError:
220 228 return False
221 229
222 230 def has_windows():
223 231 return os.name == 'nt'
224 232
225 233 def has_system_sh():
226 234 return os.name != 'nt'
227 235
228 236 def has_serve():
229 237 return os.name != 'nt' # gross approximation
230 238
231 239 def has_tic():
232 240 return matchoutput('test -x "`which tic`"', '')
233 241
234 242 def has_msys():
235 243 return os.getenv('MSYSTEM')
236 244
237 245 checks = {
238 246 "true": (lambda: True, "yak shaving"),
239 247 "false": (lambda: False, "nail clipper"),
240 248 "baz": (has_baz, "GNU Arch baz client"),
241 249 "bzr": (has_bzr, "Canonical's Bazaar client"),
242 250 "bzr114": (has_bzr114, "Canonical's Bazaar client >= 1.14"),
243 251 "cacheable": (has_cacheable_fs, "cacheable filesystem"),
244 252 "cvs": (has_cvs, "cvs client/server"),
245 253 "darcs": (has_darcs, "darcs client"),
246 254 "docutils": (has_docutils, "Docutils text processing library"),
247 255 "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
248 256 "execbit": (has_executablebit, "executable bit"),
249 257 "fifo": (has_fifo, "named pipes"),
250 258 "gettext": (has_gettext, "GNU Gettext (msgfmt)"),
251 259 "git": (has_git, "git command line client"),
252 260 "gpg": (has_gpg, "gpg client"),
253 261 "icasefs": (has_icasefs, "case insensitive file system"),
254 262 "inotify": (has_inotify, "inotify extension support"),
255 263 "lsprof": (has_lsprof, "python lsprof module"),
256 264 "mtn": (has_mtn, "monotone client (>= 1.0)"),
257 265 "outer-repo": (has_outer_repo, "outer repo"),
258 266 "p4": (has_p4, "Perforce server and client"),
259 267 "pyflakes": (has_pyflakes, "Pyflakes python linter"),
260 268 "pygments": (has_pygments, "Pygments source highlighting library"),
261 269 "serve": (has_serve, "platform and python can manage 'hg serve -d'"),
262 270 "ssl": (has_ssl, "python >= 2.6 ssl module and python OpenSSL"),
263 271 "svn": (has_svn, "subversion client and admin tools"),
264 272 "svn13": (has_svn13, "subversion client and admin tools >= 1.3"),
265 273 "svn15": (has_svn15, "subversion client and admin tools >= 1.5"),
266 274 "svn-bindings": (has_svn_bindings, "subversion python bindings"),
267 275 "symlink": (has_symlink, "symbolic links"),
268 276 "system-sh": (has_system_sh, "system() uses sh"),
269 277 "tic": (has_tic, "terminfo compiler"),
270 278 "tla": (has_tla, "GNU Arch tla client"),
271 279 "unix-permissions": (has_unix_permissions, "unix-style permissions"),
272 280 "windows": (has_windows, "Windows"),
273 281 "msys": (has_msys, "Windows with MSYS"),
274 282 }
General Comments 0
You need to be logged in to leave comments. Login now