Parse comments via regex

Parse automatically generated comments from any testing framework using regex

For code quality tools that aren't supported at Silver or Gold level, or custom tests that automatically generate comments you can use the cg comments command.

The cg comments command is automatically installed in AutoTest v2. You can also download the command for local testing via the following links:

Backward compatibility

This command was previously cg comments generic. For better scalability, we have opted to move all type or framework specific commands to the root level such as cg comments and cg checkstyle. The cg comments generic command will continue to be supported for backward compatibility.

The cg comments command accepts the following command line arguments:

  • Regex (required) A regex that captures the necessary information about each comment from the test output. This information consists of:

    • file (required) - the file in which the comment should be placed.

    • line (required) - the line on which the comment should be placed.

    • message (required) - the text to be placed in the comment.

    • column (optional) - the column on which the error starts. Defaults to 0.

    • lineEnd (optional) - the end line of the error. Defaults to the line the comment started on.

    • columnEnd (optional) - the end column of the error. Defaults to the end of the line.

    • code (optional) - the error code. Any user string may be used.

    • severity (optional) - the severity of the error. valid values are "fatal", "error", "warning" and "info". Defaults to not being set.

  • --origin (required) The origin of of the comment (the test framework used). Any user string is valid.

  • --no-score (optional) If enabled, the test will not be scored. When not set, the score will be generated based on the comments according to the set deduction for each severity level. To customize these values, add a --deduction-[percentage] flag for each severity you wish to override. The value provided must be an integer between 0 and 100.

    • --deduction-fatal Percentage deduction for comments with the "fatal" severity. Defaults to 100%.

    • --deduction-error Percentage deduction for comments with the "error" severity. Defaults to 20%.

    • --deduction-warning Percentage deduction for comments with the "warning" severity. Defaults to 10%.

    • --deduction-info Percentage deduction for comments with the "info" severity. Defaults to 5%.

    • --deduction-unknown Percentage deduction for comments with no severity set. Defaults to 0%.

  • --output or -o (optional) The output file to to use, if this is a number it will use that file descriptor. Defaults to 3.

  • --buffer-time (optional) The time comments are buffered to be grouped together into a single message. Defaults to 2 seconds.

  • --help or -h The help menu for cg comments

  • --base-path (optional) The base path of the reported files. Files that are not children of this path will not be reported. Pass the empty string to disable this feature.

  • --ignore-parser-errors (optional) ignore lines in the input that cannot be parsed using the regex provided. Defaults to False.

  • --ignore-regex (optional) Lines matching this regex will be ignored. This has higher priority than the parsing regex. If a line matches both regex patterns, it will be ignored.

  • --severities (optional) A lookup mapping for parsed severities. Should be in the format: parsed1:severity,parsed2:severity example: note:info,remark:info

  • --print or -p (optional) Print comments to stderr after parsing them. Defaults to False.

Here is an example of how to use the cg comments generic command:

Input to the command:

filename:1:Some error that has occured on line 1
different_filename:25:An error on line 25 of a different file

Regex to pass to the command to capture the filename, line, and message:

^(?P<file>[^:]*):(?P<line>\d+):(?P<message>.*)$

Resulting in the following invocation piping the input to cg comments generic:

input_to_command | cg comments generic \
    '^(?P<file>[^:]*):(?P<line>\d+):(?P<message>.*)$' \
    --origin "the-linter" \
    --score \
    --deduction-unknown 10

Last updated