Skip to content

Commit

Permalink
Add missing descriptor and test case for Coverity.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Apr 21, 2024
1 parent e38f2d3 commit 5556c81
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package edu.hm.hafner.analysis.registry;

import edu.hm.hafner.analysis.IssueParser;
import edu.hm.hafner.analysis.parser.violations.CoverityAdapter;

/**
* A descriptor for Coverity.
*
* @author Ullrich Hafner
*/
class CoverityDescriptor extends ParserDescriptor {
private static final String ID = "coverity";
private static final String NAME = "Coverity Scan";

CoverityDescriptor() {
super(ID, NAME);
}

@Override
public IssueParser createParser(final Option... options) {
return new CoverityAdapter();
}

@Override
public String getUrl() {
return "https://scan.coverity.com/";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ParserRegistry {
new CodeGeneratorDescriptor(),
new CodeNarcDescriptor(),
new CoolfluxChessccDescriptor(),
new CoverityDescriptor(),
new CpdDescriptor(),
new CppCheckDescriptor(),
new CppLintDescriptor(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package edu.hm.hafner.analysis.parser.violations;

import edu.hm.hafner.analysis.Report;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.assertions.SoftAssertions;
import edu.hm.hafner.analysis.registry.AbstractParserTest;

class CoverityAdapterTest extends AbstractParserTest {
CoverityAdapterTest() {
super("coverity.json");
}

@Override
protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) {
softly.assertThat(report).hasSize(1);
var issue = report.get(0);
softly.assertThat(issue)
.hasFileName("C:/Workspace/workspace/Build_jenkins_development/somefile.cs")
.hasCategory("Integer handling issues")
.hasType("constant_expression_result/bit_and_with_zero")
.hasLineStart(79)
.hasSeverity(Severity.WARNING_NORMAL);
softly.assertThat(issue.getMessage()).startsWith("Bitwise-and ('&') operation applied to zero always produces zero.");
}

@Override
protected CoverityAdapter createParser() {
return new CoverityAdapter();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"type": "Coverity issues",
"formatVersion": 7,
"suppressedIssueCount": 0,
"issues": [
{
"mergeKey": "884ed7531feed32eb916d9038a3b9bd6",
"occurrenceCountForMK": 1,
"occurrenceNumberInMK": 1,
"referenceOccurrenceCountForMK": null,
"checkerName": "CONSTANT_EXPRESSION_RESULT",
"subcategory": "bit_and_with_zero",
"type": "constant_expression_result",
"subtype": "bit_and_with_zero",
"code-language": "c#",
"extra": "status",
"domain": "STATIC_CS",
"language": "C#",
"mainEventFilePathname": "C:\\Workspace\\workspace\\Build_jenkins_development\\somefile.cs",
"strippedMainEventFilePathname": "\\workspace\\Build_jenkins_development\\Architecture\\somefile.cs",
"mainEventLineNumber": 79,
"properties": {},
"functionDisplayName": "somename",
"functionMangledName": "somename",
"localStatus": null,
"ordered": false,
"events": [
{
"covLStrEventDescription": "{CovLStrv2{{t{{0} is always 0.}{{code{status & System.Printing.PrintJobStatus.None}}}}{t{ This occurs as a value.}}}}",
"eventDescription": "\"status & System.Printing.PrintJobStatus.None\" is always 0. This occurs as a value.",
"eventNumber": 1,
"eventTreePosition": "1",
"eventSet": 0,
"eventTag": "bit_and_with_zero",
"filePathname": "C:\\Workspace\\workspace\\Build_jenkins_development\\somefile.cs",
"strippedFilePathname": "\\workspace\\Build_jenkins_development\\Architecture\\somefile.cs",
"lineNumber": 79,
"main": true,
"moreInformationId": null,
"remediation": false,
"events": null
}
],
"stateOnServer": null,
"checkerProperties": {
"category": "Integer handling issues",
"categoryDescription": "Integer handling issues",
"cweCategory": "569",
"issueKinds": ["QUALITY"],
"eventSetCaptions": [],
"impact": "Medium",
"impactDescription": "Medium",
"subcategoryLocalEffect": "The expression's value is always zero; construct may indicate an inadvertent logic error.",
"subcategoryShortDescription": "Bitwise-and with zero",
"subcategoryLongDescription": "Bitwise-and ('&') operation applied to zero always produces zero"
}
}
],
"desktopAnalysisSettings": null,
"error": null,
"warnings": []
}

0 comments on commit 5556c81

Please sign in to comment.