Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

bctest.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright 2014 BitPay, Inc.
  2. # Distributed under the MIT software license, see the accompanying
  3. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. import subprocess
  5. import os
  6. import json
  7. import sys
  8. def bctest(testDir, testObj, exeext):
  9. execprog = testObj['exec'] + exeext
  10. execargs = testObj['args']
  11. execrun = [execprog] + execargs
  12. stdinCfg = None
  13. inputData = None
  14. if "input" in testObj:
  15. filename = testDir + "/" + testObj['input']
  16. inputData = open(filename).read()
  17. stdinCfg = subprocess.PIPE
  18. outputFn = None
  19. outputData = None
  20. if "output_cmp" in testObj:
  21. outputFn = testObj['output_cmp']
  22. outputData = open(testDir + "/" + outputFn).read()
  23. proc = subprocess.Popen(execrun, stdin=stdinCfg, stdout=subprocess.PIPE, stderr=subprocess.PIPE,universal_newlines=True)
  24. try:
  25. outs = proc.communicate(input=inputData)
  26. except OSError:
  27. print("OSError, Failed to execute " + execprog)
  28. sys.exit(1)
  29. if outputData and (outs[0] != outputData):
  30. print("Output data mismatch for " + outputFn)
  31. sys.exit(1)
  32. wantRC = 0
  33. if "return_code" in testObj:
  34. wantRC = testObj['return_code']
  35. if proc.returncode != wantRC:
  36. print("Return code mismatch for " + outputFn)
  37. sys.exit(1)
  38. def bctester(testDir, input_basename, buildenv):
  39. input_filename = testDir + "/" + input_basename
  40. raw_data = open(input_filename).read()
  41. input_data = json.loads(raw_data)
  42. for testObj in input_data:
  43. bctest(testDir, testObj, buildenv.exeext)
  44. sys.exit(0)