]> Git Repo - VerusCoin.git/blame - src/test/bctest.py
Merge pull request #5360
[VerusCoin.git] / src / test / bctest.py
CommitLineData
d7893863 1# Copyright 2014 BitPay, Inc.
78253fcb 2# Distributed under the MIT software license, see the accompanying
d7893863
JG
3# file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5import subprocess
6import os
7import json
8import sys
9
41d67c78 10def bctest(testDir, testObj, exeext):
fb14452c 11
41d67c78
CF
12 execprog = testObj['exec'] + exeext
13 execargs = testObj['args']
14 execrun = [execprog] + execargs
fb14452c
JG
15 stdinCfg = None
16 inputData = None
17 if "input" in testObj:
18 filename = testDir + "/" + testObj['input']
19 inputData = open(filename).read()
20 stdinCfg = subprocess.PIPE
21
df4d61e6
JG
22 outputFn = None
23 outputData = None
24 if "output_cmp" in testObj:
25 outputFn = testObj['output_cmp']
26 outputData = open(testDir + "/" + outputFn).read()
41d67c78 27 proc = subprocess.Popen(execrun, stdin=stdinCfg, stdout=subprocess.PIPE, stderr=subprocess.PIPE,universal_newlines=True)
d7893863 28 try:
fb14452c 29 outs = proc.communicate(input=inputData)
d7893863 30 except OSError:
41d67c78 31 print("OSError, Failed to execute " + execprog)
d7893863
JG
32 sys.exit(1)
33
df4d61e6 34 if outputData and (outs[0] != outputData):
d7893863
JG
35 print("Output data mismatch for " + outputFn)
36 sys.exit(1)
37
df4d61e6
JG
38 wantRC = 0
39 if "return_code" in testObj:
40 wantRC = testObj['return_code']
41 if proc.returncode != wantRC:
42 print("Return code mismatch for " + outputFn)
43 sys.exit(1)
44
41d67c78 45def bctester(testDir, input_basename, buildenv):
d7893863
JG
46 input_filename = testDir + "/" + input_basename
47 raw_data = open(input_filename).read()
48 input_data = json.loads(raw_data)
49
50 for testObj in input_data:
41d67c78 51 bctest(testDir, testObj, buildenv.exeext)
d7893863
JG
52
53 sys.exit(0)
54
This page took 0.052699 seconds and 4 git commands to generate.