mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-24 10:17:45 -03:00
test: Print CompletedProcess object on error
This commit is contained in:
parent
5fb9455063
commit
fa43c4f93c
1 changed files with 11 additions and 14 deletions
|
@ -83,13 +83,11 @@ def bctest(testDir, testObj, buildenv):
|
||||||
execrun = [execprog] + execargs
|
execrun = [execprog] + execargs
|
||||||
|
|
||||||
# Read the input data (if there is any)
|
# Read the input data (if there is any)
|
||||||
stdinCfg = None
|
|
||||||
inputData = None
|
inputData = None
|
||||||
if "input" in testObj:
|
if "input" in testObj:
|
||||||
filename = os.path.join(testDir, testObj["input"])
|
filename = os.path.join(testDir, testObj["input"])
|
||||||
with open(filename, encoding="utf8") as f:
|
with open(filename, encoding="utf8") as f:
|
||||||
inputData = f.read()
|
inputData = f.read()
|
||||||
stdinCfg = subprocess.PIPE
|
|
||||||
|
|
||||||
# Read the expected output data (if there is any)
|
# Read the expected output data (if there is any)
|
||||||
outputFn = None
|
outputFn = None
|
||||||
|
@ -112,9 +110,8 @@ def bctest(testDir, testObj, buildenv):
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
# Run the test
|
# Run the test
|
||||||
proc = subprocess.Popen(execrun, stdin=stdinCfg, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
|
||||||
try:
|
try:
|
||||||
outs = proc.communicate(input=inputData)
|
res = subprocess.run(execrun, capture_output=True, text=True, input=inputData)
|
||||||
except OSError:
|
except OSError:
|
||||||
logging.error("OSError, Failed to execute " + execprog)
|
logging.error("OSError, Failed to execute " + execprog)
|
||||||
raise
|
raise
|
||||||
|
@ -123,9 +120,9 @@ def bctest(testDir, testObj, buildenv):
|
||||||
data_mismatch, formatting_mismatch = False, False
|
data_mismatch, formatting_mismatch = False, False
|
||||||
# Parse command output and expected output
|
# Parse command output and expected output
|
||||||
try:
|
try:
|
||||||
a_parsed = parse_output(outs[0], outputType)
|
a_parsed = parse_output(res.stdout, outputType)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error('Error parsing command output as %s: %s' % (outputType, e))
|
logging.error(f"Error parsing command output as {outputType}: '{str(e)}'; res: {str(res)}")
|
||||||
raise
|
raise
|
||||||
try:
|
try:
|
||||||
b_parsed = parse_output(outputData, outputType)
|
b_parsed = parse_output(outputData, outputType)
|
||||||
|
@ -134,13 +131,13 @@ def bctest(testDir, testObj, buildenv):
|
||||||
raise
|
raise
|
||||||
# Compare data
|
# Compare data
|
||||||
if a_parsed != b_parsed:
|
if a_parsed != b_parsed:
|
||||||
logging.error("Output data mismatch for " + outputFn + " (format " + outputType + ")")
|
logging.error(f"Output data mismatch for {outputFn} (format {outputType}); res: {str(res)}")
|
||||||
data_mismatch = True
|
data_mismatch = True
|
||||||
# Compare formatting
|
# Compare formatting
|
||||||
if outs[0] != outputData:
|
if res.stdout != outputData:
|
||||||
error_message = "Output formatting mismatch for " + outputFn + ":\n"
|
error_message = f"Output formatting mismatch for {outputFn}:\nres: {str(res)}\n"
|
||||||
error_message += "".join(difflib.context_diff(outputData.splitlines(True),
|
error_message += "".join(difflib.context_diff(outputData.splitlines(True),
|
||||||
outs[0].splitlines(True),
|
res.stdout.splitlines(True),
|
||||||
fromfile=outputFn,
|
fromfile=outputFn,
|
||||||
tofile="returned"))
|
tofile="returned"))
|
||||||
logging.error(error_message)
|
logging.error(error_message)
|
||||||
|
@ -152,8 +149,8 @@ def bctest(testDir, testObj, buildenv):
|
||||||
wantRC = 0
|
wantRC = 0
|
||||||
if "return_code" in testObj:
|
if "return_code" in testObj:
|
||||||
wantRC = testObj['return_code']
|
wantRC = testObj['return_code']
|
||||||
if proc.returncode != wantRC:
|
if res.returncode != wantRC:
|
||||||
logging.error("Return code mismatch for " + outputFn)
|
logging.error(f"Return code mismatch for {outputFn}; res: {str(res)}")
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
if "error_txt" in testObj:
|
if "error_txt" in testObj:
|
||||||
|
@ -164,8 +161,8 @@ def bctest(testDir, testObj, buildenv):
|
||||||
# emits DISPLAY errors when running as a windows application on
|
# emits DISPLAY errors when running as a windows application on
|
||||||
# linux through wine. Just assert that the expected error text appears
|
# linux through wine. Just assert that the expected error text appears
|
||||||
# somewhere in stderr.
|
# somewhere in stderr.
|
||||||
if want_error not in outs[1]:
|
if want_error not in res.stderr:
|
||||||
logging.error("Error mismatch:\n" + "Expected: " + want_error + "\nReceived: " + outs[1].rstrip())
|
logging.error(f"Error mismatch:\nExpected: {want_error}\nReceived: {res.stderr.rstrip()}\nres: {str(res)}")
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
def parse_output(a, fmt):
|
def parse_output(a, fmt):
|
||||||
|
|
Loading…
Add table
Reference in a new issue