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