generated from MeilCli/action-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add junit compatibility of cpplint
- Loading branch information
Showing
9 changed files
with
168 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
1. `pip install cpplint` | ||
1. `cpplint --output junit data/cpplint/test.cpp` | ||
1. write stdout to `data/junit_cpplint.xml` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
void method(){ | ||
println("test"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<testsuite errors="0" failures="3" name="cpplint" tests="3"><testcase name="data/cpplint/test.cpp"><failure>0: No copyright message found. You should have a line: "Copyright [year] <Copyright Owner>" [legal/copyright] [5] | ||
1: Missing space before { [whitespace/braces] [5] | ||
3: Could not find a newline character at the end of the file. [whitespace/ending_newline] [5]</failure></testcase></testsuite> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { JunitTestSuite, JunitTestCase } from "./entity"; | ||
import { LintResult } from "../../lint-result"; | ||
import { JunitHandler } from "./junit-handler"; | ||
import * as he from "he"; | ||
|
||
export class CpplintJunitHandler implements JunitHandler { | ||
match(testSuites: JunitTestSuite[]): boolean { | ||
if (testSuites.length == 0) { | ||
return false; | ||
} | ||
return testSuites[0].name == "cpplint"; | ||
} | ||
|
||
handle(testSuites: JunitTestSuite[]): LintResult[] { | ||
const result: LintResult[] = []; | ||
this.handleTestSuites(result, testSuites); | ||
return result; | ||
} | ||
|
||
private handleTestSuites(result: LintResult[], testSuites: JunitTestSuite[]) { | ||
for (const testSuite of testSuites) { | ||
this.handleTestSuite(result, testSuite); | ||
} | ||
} | ||
|
||
private handleTestSuite(result: LintResult[], testSuite: JunitTestSuite) { | ||
this.handleTestCases(result, testSuite.testCases); | ||
this.handleTestSuites(result, testSuite.testSuites); | ||
} | ||
|
||
private handleTestCases(result: LintResult[], testCases: JunitTestCase[]) { | ||
for (const testCase of testCases) { | ||
this.handleTestCase(result, testCase); | ||
} | ||
} | ||
|
||
private handleTestCase(result: LintResult[], testCase: JunitTestCase) { | ||
for (const failure of testCase.failures) { | ||
for (const message of this.parseBody(failure.body)) { | ||
result.push({ | ||
path: testCase.name, | ||
message: message[1], | ||
level: message[3] == 5 ? "failure" : 3 <= message[3] ? "warning" : "notice", | ||
rule: message[2], | ||
startLine: message[0], | ||
startColumn: undefined, | ||
endLine: undefined, | ||
endColumn: undefined, | ||
}); | ||
} | ||
} | ||
for (const error of testCase.errors) { | ||
for (const message of this.parseBody(error.body)) { | ||
result.push({ | ||
path: testCase.name, | ||
message: message[1], | ||
level: message[3] == 5 ? "failure" : 3 <= message[3] ? "warning" : "notice", | ||
rule: message[2], | ||
startLine: message[0], | ||
startColumn: undefined, | ||
endLine: undefined, | ||
endColumn: undefined, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
private parseBody(body: string): [number, string, string, number][] { | ||
const result: [number, string, string, number][] = []; | ||
for (const line of body.split(/(\r\n)|\n|\r/g)) { | ||
if (line == undefined || line.length == 0) { | ||
continue; | ||
} | ||
|
||
const rawStartLine = line.replace(/^(\d+):\s(.+)\s\[(.+?)\]\s\[(\d)\]$/, "$1"); | ||
const rawMessage = line.replace(/^(\d+):\s(.+)\s\[(.+?)\]\s\[(\d)\]$/, "$2"); | ||
const rawRule = line.replace(/^(\d+):\s(.+)\s\[(.+?)\]\s\[(\d)\]$/, "$3"); | ||
const rawConfidence = line.replace(/^(\d+):\s(.+)\s\[(.+?)\]\s\[(\d)\]$/, "$4"); | ||
if ( | ||
rawStartLine.length == 0 || | ||
rawMessage.length == 0 || | ||
rawRule.length == 0 || | ||
rawConfidence.length == 0 | ||
) { | ||
continue; | ||
} | ||
const startLine = parseInt(rawStartLine); | ||
const message = he.decode(rawMessage); | ||
const rule = he.decode(rawRule); | ||
const confidence = parseInt(rawConfidence); | ||
if (Number.isInteger(startLine) == false || Number.isInteger(confidence) == false) { | ||
continue; | ||
} | ||
|
||
result.push([startLine == 0 ? 1 : startLine, message, rule, confidence]); | ||
} | ||
return result; | ||
} | ||
} |