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