run_tests.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/python
  2. #
  3. # Any copyright is dedicated to the Public Domain.
  4. # http://creativecommons.org/publicdomain/zero/1.0/
  5. #
  6. from __future__ import print_function
  7. from modules.scm import detect_scm_system
  8. from contextlib import closing
  9. import checkmozstyle
  10. import os
  11. import modules.cpplint as cpplint
  12. import StringIO
  13. TESTS = [
  14. # Empty patch
  15. {
  16. "patch": "tests/test1.patch",
  17. "cpp": "tests/test1.cpp",
  18. "out": "tests/test1.out"
  19. },
  20. # Bad header
  21. {
  22. "patch": "tests/test2.patch",
  23. "cpp": "tests/test2.cpp",
  24. "out": "tests/test2.out"
  25. },
  26. # Bad Description
  27. {
  28. "patch": "tests/test3.patch",
  29. "cpp": "tests/test3.cpp",
  30. "out": "tests/test3.out"
  31. },
  32. # readability tests
  33. {
  34. "patch": "tests/test4.patch",
  35. "cpp": "tests/test4.cpp",
  36. "out": "tests/test4.out"
  37. },
  38. # runtime tests
  39. {
  40. "patch": "tests/test5.patch",
  41. "cpp": "tests/test5.cpp",
  42. "out": "tests/test5.out"
  43. },
  44. ]
  45. def main():
  46. cwd = os.path.abspath('.')
  47. scm = detect_scm_system(cwd)
  48. cpplint.use_mozilla_styles()
  49. (args, flags) = cpplint.parse_arguments([])
  50. for test in TESTS:
  51. with open(test["patch"]) as fh:
  52. patch = fh.read()
  53. with closing(StringIO.StringIO()) as output:
  54. cpplint.set_stream(output)
  55. checkmozstyle.process_patch(patch, cwd, cwd, scm)
  56. result = output.getvalue()
  57. with open(test["out"]) as fh:
  58. expected_output = fh.read()
  59. test_status = "PASSED"
  60. if result != expected_output:
  61. test_status = "FAILED"
  62. print("TEST " + test["patch"] + " " + test_status)
  63. print("Got result:\n" + result + "Expected:\n" + expected_output)
  64. else:
  65. print("TEST " + test["patch"] + " " + test_status)
  66. if __name__ == "__main__":
  67. main()