tests/hghave.py
changeset 46870 41d43d12c2c4
parent 46737 78e6700ab009
child 47039 94c0c36299b1
equal deleted inserted replaced
46869:ed286d150aa8 46870:41d43d12c2c4
   138 
   138 
   139 def matchoutput(cmd, regexp, ignorestatus=False):
   139 def matchoutput(cmd, regexp, ignorestatus=False):
   140     """Return the match object if cmd executes successfully and its output
   140     """Return the match object if cmd executes successfully and its output
   141     is matched by the supplied regular expression.
   141     is matched by the supplied regular expression.
   142     """
   142     """
       
   143 
       
   144     # Tests on Windows have to fake USERPROFILE to point to the test area so
       
   145     # that `~` is properly expanded on py3.8+.  However, some tools like black
       
   146     # make calls that need the real USERPROFILE in order to run `foo --version`.
       
   147     env = os.environ
       
   148     if os.name == 'nt':
       
   149         env = os.environ.copy()
       
   150         env['USERPROFILE'] = env['REALUSERPROFILE']
       
   151 
   143     r = re.compile(regexp)
   152     r = re.compile(regexp)
   144     p = subprocess.Popen(
   153     p = subprocess.Popen(
   145         cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
   154         cmd,
       
   155         shell=True,
       
   156         stdout=subprocess.PIPE,
       
   157         stderr=subprocess.STDOUT,
       
   158         env=env,
   146     )
   159     )
   147     s = p.communicate()[0]
   160     s = p.communicate()[0]
   148     ret = p.returncode
   161     ret = p.returncode
   149     return (ignorestatus or not ret) and r.search(s)
   162     return (ignorestatus or not ret) and r.search(s)
   150 
   163