summaryrefslogtreecommitdiff
path: root/tools/ci/scripts/gettests.py
blob: ff2b89faaa0c672cac936b8ea5269da6d13e29cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#! /usr/bin/env python
# -*- coding: utf8 -*-
#
# Copyright (C) 2017  Andrei Karas

import os
import re

testCaseRe = re.compile("^TEST_CASE[(]\"(?P<name1>([\w ()_:.,]*))\",[ ]\"(?P<name2>([\w ()_:.,]*))\"[)]$")
sectionRe = re.compile("^([ ]*)SECTION[(]\"(?P<name>([\w ()_:.,]*))\"[)]$")


def printTestCase(testCase):
#    print("func --test-case=\"{0}\"".format(testCase))
#    print("func \"{0}\" \"\"".format(testCase))
    print("\"{0}\" \"\"".format(testCase))


def printSection(testCase, section):
#    print("func --test-case=\"{0}\" --subcase=\"{1}\"".format(testCase, section))
#    print("func \"{0}\" \"{1}\"".format(testCase, section))
    print("\"{0}\" \"{1}\"".format(testCase, section))


def parseCC(srcFile):
    with open(srcFile, "r") as r:
        testCase = ""
        sectionsCount = 0
        for line in r:
            m = testCaseRe.search(line)
            if m != None:
                if testCase != "" and sectionsCount == 0:
                    printTestCase(testCase)
                testCase = m.group("name1") + " " + m.group("name2")
                sectionsCount = 0
            elif line.find("TEST_CASE(\"") >= 0:
                print("Error: test case regexp failed for: " + line)
                exit(1)
            m = sectionRe.search(line)
            if m != None:
                sectionsCount = sectionsCount + 1
                printSection(testCase, m.group("name"))
            elif line.find("SECTION(\"") >= 0:
                print("Error: section regexp failed for: " + line)
                exit(1)
        if testCase != "" and sectionsCount == 0:
            printTestCase(testCase)


def enumFiles(srcDir):
    files = os.listdir(srcDir)
    for file1 in files:
        if file1[0] == ".":
            continue
        srcPath = os.path.abspath(srcDir + os.path.sep + file1)
        if os.path.isdir(srcPath):
            enumFiles(srcPath)
        elif file1[-3:] == ".cc":
            parseCC(srcPath)


enumFiles("src/unittests")