|
16 | 16 |
|
17 | 17 | from .documentation_types import AttributeDocumentation, FunctionDocumentation, MacroDocumentation, \ |
18 | 18 | VariableDocumentation, GenericCommandDocumentation, ClassDocumentation, TestDocumentation, SectionDocumentation, \ |
19 | | - MethodDocumentation, VarType |
| 19 | + MethodDocumentation, VarType, CTestDocumentation |
20 | 20 | from .parser.CMakeListener import CMakeListener |
21 | 21 | # Annoyingly, the Antl4 Python libraries use camelcase since it was originally Java, so we have convention |
22 | 22 | # inconsistencies here |
@@ -363,6 +363,43 @@ def process_cpp_attr(self, ctx: CMakeParser.Command_invocationContext, docstring |
363 | 363 | clazz.attributes.append(AttributeDocumentation( |
364 | 364 | name, docstring, parent_class, default_values)) |
365 | 365 |
|
| 366 | + def process_add_test(self, ctx: CMakeParser.Command_invocationContext, docstring: str): |
| 367 | + """ |
| 368 | + Extracts information from a CTest add_test() command. |
| 369 | + Note: this is not the processor for the CMakeTest ct_add_test() command, |
| 370 | + but the processor for the vanilla CMake add_test() command. |
| 371 | +
|
| 372 | + :param ctx: Documented command context. Constructed by the Antlr4 parser. |
| 373 | +
|
| 374 | + :param docstring: Cleaned docstring. |
| 375 | + """ |
| 376 | + params = [param.getText() for param in ctx.single_argument()] # Extract parameters |
| 377 | + |
| 378 | + if len(params) < 2: |
| 379 | + pretty_text = docstring |
| 380 | + pretty_text += f"\n{ctx.getText()}" |
| 381 | + |
| 382 | + self.logger.error( |
| 383 | + f"ct_add_section() called with incorrect parameters: {params}\n\n{pretty_text}") |
| 384 | + return |
| 385 | + |
| 386 | + name = "" |
| 387 | + for i in range(0, len(params)): |
| 388 | + param = params[i] |
| 389 | + if param.upper() == "NAME": |
| 390 | + try: |
| 391 | + name = params[i + 1] |
| 392 | + except IndexError: |
| 393 | + pretty_text = docstring |
| 394 | + pretty_text += f"\n{ctx.getText()}" |
| 395 | + |
| 396 | + self.logger.error(f"add_test() called with incorrect parameters: {params}\n\n{pretty_text}") |
| 397 | + return |
| 398 | + |
| 399 | + test_doc = CTestDocumentation(name, docstring, filter(lambda p: p != name and p != "NAME", params)) |
| 400 | + self.documented.append(test_doc) |
| 401 | + self.documented_awaiting_function_def = test_doc |
| 402 | + |
366 | 403 | def process_generic_command(self, command_name: str, ctx: CMakeParser.Command_invocationContext, docstring: str): |
367 | 404 | """ |
368 | 405 | Extracts command invocation and arguments for a documented command that does not |
|
0 commit comments