PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/run_test.py

http://github.com/jocelyn/eMIME
Python | 97 lines | 59 code | 18 blank | 20 comment | 12 complexity | 58e4b35232a7d1097fef78d032bcacd1 MD5 | raw file
  1. #!/usr/local/bin/python
  2. # Small python-script run all tests using ec (the Eiffel compiler)
  3. # we assume that ec outputs everything in english!
  4. #
  5. # Code ported from a ruby script by Niklaus Giger
  6. # For the command line options look at
  7. # http://docs.eiffel.com/book/eiffelstudio/eiffelstudio-command-line-options
  8. # we use often the -batch open.
  9. #
  10. # TODO: Fix problems when compiling takes too long and/or there
  11. # are ec process lingering around from a previous failed build
  12. import os;
  13. import sys;
  14. import tempfile;
  15. import shutil;
  16. import re;
  17. import subprocess;
  18. from time import sleep;
  19. # Override system command.
  20. # run command. if not successful, complain and exit with error
  21. def eval_cmd(cmd):
  22. # print cmd
  23. res = subprocess.call (cmd, shell=True)
  24. if res < 0:
  25. print "Failed running: %s" % (cmd)
  26. sys.exit(2)
  27. return res
  28. def eval_cmd_output(cmd):
  29. # print cmd
  30. p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  31. if p:
  32. return p.communicate()[0]
  33. else:
  34. print "Failed running: %s" % (cmd)
  35. sys.exit(2)
  36. def rm_dir(d):
  37. if os.path.isdir(d):
  38. shutil.rmtree(d)
  39. def runTestForProject(where):
  40. if not os.path.isdir(where):
  41. print "Directory %s does not exist" % (where)
  42. sys.exit(2)
  43. # create a temporary file with input for the
  44. # interactive mode of ec
  45. commands2run="T\nE\nq\n"
  46. fd, fn = tempfile.mkstemp('commands2run')
  47. f = open(fn, 'w');
  48. f.write (commands2run)
  49. f.close()
  50. os.chdir(where)
  51. # First we have to remove old compilation
  52. rm_dir("EIFGENs")
  53. # compile the library
  54. cmd = "ecb -config %s -target emime -batch -c_compile" % (os.path.join ("library", "emime-safe.ecf"))
  55. res = eval_cmd(cmd)
  56. # compile the test
  57. cmd = "ec -config %s -target test -batch -c_compile" % (os.path.join ("test", "test-safe.ecf"))
  58. res = eval_cmd(cmd)
  59. logFile = "%s.log" % (__file__)
  60. sleep(1)
  61. cmd = "ec -config %s -target test -batch -loop < %s" % (os.path.join ("test", "test-safe.ecf"), fn)
  62. res_output = eval_cmd_output(cmd)
  63. lines = re.split ("\n", res_output)
  64. regexp = "^(\d+) tests total \((\d+) executed, (\d+) failing, (\d+) unresolved\)$"
  65. p = re.compile (regexp);
  66. m = [];
  67. for line in lines:
  68. p_res = p.search(line.strip(), 0)
  69. if p_res:
  70. m = [int(p_res.group(1)), int(p_res.group(2)), int(p_res.group(3)), int(p_res.group(4))]
  71. break
  72. print "\n"
  73. if len(m) >= 3 and m[2] == 0 and m[3] == 0:
  74. print "%i tests completed successfully" % (m[0])
  75. else:
  76. print "Failures while running %i failed. %i executed %i failures %i unresolved" % (m[0], m[1], m[2], m[3])
  77. sys.exit(2)
  78. if __name__ == '__main__':
  79. runTestForProject(os.getcwd())