Run cppcheck and cppcheck-htmlreport. Yield a tuple containing the resulting HTML report index and the directory path.
(source_filename=None, xml_version='1', xml_filename=None, checkers_filename=None)
| 117 | |
| 118 | @contextlib.contextmanager |
| 119 | def runCheck(source_filename=None, xml_version='1', xml_filename=None, checkers_filename=None): |
| 120 | """Run cppcheck and cppcheck-htmlreport. |
| 121 | |
| 122 | Yield a tuple containing the resulting HTML report index and the directory |
| 123 | path. |
| 124 | |
| 125 | """ |
| 126 | output_directory = tempfile.TemporaryDirectory(dir='.') |
| 127 | if xml_filename is None: |
| 128 | assert source_filename |
| 129 | xml_filename = os.path.join(output_directory.name, 'output.xml') |
| 130 | |
| 131 | with open(xml_filename, 'w') as output_file: |
| 132 | subprocess.check_call( |
| 133 | [CPPCHECK_BIN, '--xml', source_filename, |
| 134 | '--xml-version=' + xml_version], |
| 135 | stderr=output_file) |
| 136 | |
| 137 | assert os.path.exists(xml_filename) |
| 138 | |
| 139 | args = [*HTML_REPORT_BIN, |
| 140 | '--file=' + os.path.realpath(xml_filename), |
| 141 | '--report-dir=' + os.path.realpath(output_directory.name)] |
| 142 | if checkers_filename: |
| 143 | args.append('--checkers-report-file=' + os.path.realpath(checkers_filename)) |
| 144 | |
| 145 | subprocess.check_call( |
| 146 | args, |
| 147 | cwd=TEST_TOOLS_DIR) |
| 148 | |
| 149 | with open(os.path.join(output_directory.name, 'index.html')) as index_file: |
| 150 | index_contents = index_file.read() |
| 151 | |
| 152 | yield index_contents, output_directory |
| 153 | |
| 154 | |
| 155 | if __name__ == '__main__': |
no test coverage detected