Read Cppcheck test file and create data representation
| 70 | |
| 71 | |
| 72 | class Extract: |
| 73 | |
| 74 | """ |
| 75 | Read Cppcheck test file and create data |
| 76 | representation |
| 77 | """ |
| 78 | |
| 79 | # array that stores all the test cases |
| 80 | nodes = [] |
| 81 | |
| 82 | def parseFile(self, filename): |
| 83 | """ |
| 84 | parse test file and add info to the nodes |
| 85 | variable |
| 86 | """ |
| 87 | |
| 88 | name = '[0-9a-zA-Z_]+' |
| 89 | string = '\\"(.+)\\"' |
| 90 | |
| 91 | testclass = None |
| 92 | functionName = None |
| 93 | code = None |
| 94 | start_code = None |
| 95 | disable = False |
| 96 | |
| 97 | for line in open(filename, 'r'): |
| 98 | # testclass starts |
| 99 | res = re.match('class (' + name + ')', line) |
| 100 | if res is not None: |
| 101 | testclass = res.group(1) |
| 102 | |
| 103 | # end of testclass |
| 104 | if re.match('};', line) is not None: |
| 105 | testclass = None |
| 106 | |
| 107 | # function start |
| 108 | res = re.match('\\s+void (' + name + ')\\(\\)', line) |
| 109 | if res is not None: |
| 110 | functionName = res.group(1) |
| 111 | start_code = None |
| 112 | |
| 113 | elif re.match('\\s+}', line) is not None: |
| 114 | functionName = None |
| 115 | |
| 116 | # extracttests commands.. |
| 117 | res = re.match(r'\s*//\s*extracttests.start:(.*)', line) |
| 118 | if res is not None: |
| 119 | start_code = res.group(1).replace('\\n', '\n') + '\n' |
| 120 | elif line.find('extracttests.disable') >= 0: |
| 121 | disable = True |
| 122 | elif line.find('extracttests.enable') >= 0: |
| 123 | disable = False |
| 124 | |
| 125 | if functionName is None or disable: |
| 126 | continue |
| 127 | |
| 128 | # check |
| 129 | for f in check_function: |