gettests.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #! /usr/bin/env python
  2. # -*- coding: utf8 -*-
  3. #
  4. # Copyright (C) 2017 Andrei Karas
  5. import os
  6. import re
  7. testCaseRe = re.compile("^TEST_CASE[(]\"(?P<name1>([\w ()_:.,]*))\",[ ]\"(?P<name2>([\w ()_:.,]*))\"[)]$")
  8. sectionRe = re.compile("^([ ]*)SECTION[(]\"(?P<name>([\w ()_:.,]*))\"[)]$")
  9. def printTestCase(testCase):
  10. # print("func --test-case=\"{0}\"".format(testCase))
  11. # print("func \"{0}\" \"\"".format(testCase))
  12. print("\"{0}\" \"\"".format(testCase))
  13. def printSection(testCase, section):
  14. # print("func --test-case=\"{0}\" --subcase=\"{1}\"".format(testCase, section))
  15. # print("func \"{0}\" \"{1}\"".format(testCase, section))
  16. print("\"{0}\" \"{1}\"".format(testCase, section))
  17. def parseCC(srcFile):
  18. with open(srcFile, "r") as r:
  19. testCase = ""
  20. sectionsCount = 0
  21. for line in r:
  22. m = testCaseRe.search(line)
  23. if m != None:
  24. if testCase != "" and sectionsCount == 0:
  25. printTestCase(testCase)
  26. testCase = m.group("name1") + " " + m.group("name2")
  27. sectionsCount = 0
  28. elif line.find("TEST_CASE(\"") >= 0:
  29. print("Error: test case regexp failed for: " + line)
  30. exit(1)
  31. m = sectionRe.search(line)
  32. if m != None:
  33. sectionsCount = sectionsCount + 1
  34. printSection(testCase, m.group("name"))
  35. elif line.find("SECTION(\"") >= 0:
  36. print("Error: section regexp failed for: " + line)
  37. exit(1)
  38. if testCase != "" and sectionsCount == 0:
  39. printTestCase(testCase)
  40. def enumFiles(srcDir):
  41. files = os.listdir(srcDir)
  42. for file1 in files:
  43. if file1[0] == ".":
  44. continue
  45. srcPath = os.path.abspath(srcDir + os.path.sep + file1)
  46. if os.path.isdir(srcPath):
  47. enumFiles(srcPath)
  48. elif file1[-3:] == ".cc":
  49. parseCC(srcPath)
  50. enumFiles("src/unittests")