changeset 5252:c0281c6b40b0

hghave: wrap command output matching
author Patrick Mezard <pmezard@gmail.com>
date Mon, 27 Aug 2007 22:17:51 +0200
parents 90919a6f5c8f
children d82ebcdf20e1
files tests/hghave
diffstat 1 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/tests/hghave	Mon Aug 27 22:17:51 2007 +0200
+++ b/tests/hghave	Mon Aug 27 22:17:51 2007 +0200
@@ -5,11 +5,22 @@
 """
 import optparse
 import os
+import re
 import sys
 import tempfile
 
 tempprefix = 'hg-hghave-'
 
+def matchoutput(cmd, regexp):
+    """Return True if cmd executes successfully and its output
+    is matched by the supplied regular expression.
+    """
+    r = re.compile(regexp)
+    fh = os.popen(cmd)
+    s = fh.read()
+    ret = fh.close()
+    return ret is None and r.search(s)
+
 def has_symlink():
     return hasattr(os, "symlink")
 
@@ -52,10 +63,7 @@
         return False
 
 def has_git():
-    fh = os.popen('git --version 2>&1')
-    s = fh.read()
-    ret = fh.close()
-    return ret is None and s.startswith('git version')
+    return matchoutput('git --version 2>&1', r'^git version')
 
 checks = {
     "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),