Skip to content

Commit

Permalink
feat: add mutation testing element transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
rjaegers committed Jan 30, 2025
1 parent 574a39d commit 33eab90
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ inputs:
runs:
using: composite
steps:
- uses: dcarbone/install-jq-action@e397bd87438d72198f81efd21f876461183d383a # v3.0.1
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version: '3.12'
Expand All @@ -32,6 +33,9 @@ runs:
{ echo '<testExecutions version="1">'; xsltproc ${GITHUB_ACTION_PATH}/converters/gtest-to-generic-execution.xslt ${{ inputs.input }}; echo '</testExecutions>'; } | tee ${{ inputs.output }} > /dev/null
;;
'mutation-test-to-generic-issue')
MERGED_MUTATION_FILE=$(mktemp)
jq -s 'reduce .[] as $item ({}; . * $item)' ${{ inputs.input }} > ${MERGED_MUTATION_FILE}
jq --arg workspace "${GITHUB_WORKSPACE}" -f ${GITHUB_ACTION_PATH}/converters/mutation-elements-to-generic-issue.jq ${MERGED_MUTATION_FILE} > ${{ inputs.output }}
;;
*)
echo 'Unknown transformation type: ${{ inputs.transformation }}'
Expand Down
52 changes: 52 additions & 0 deletions converters/mutation-elements-to-generic-issue.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This jq filter transforms a mutation testing elements report to the SonarQube generic issue import format.

.framework.name as $frameworkName
| .projectRoot as $projectRoot
| .files
| to_entries
| {
issues: map(
.value.mutants[] as $mutants
| del(.value) as $file
| $mutants
| select(.status == ("Survived", "NoCoverage"))
| (
if .replacement then
"The mutation operator '" + .mutatorName + "' has mutated the input to " + .replacement + " without any tests failing."
else
"The mutation operator '" + .mutatorName + "' has mutated the input without any tests failing."
end
) as $mutation
| {
engineId: ($frameworkName // "Mutation Testing"),
ruleId: ("Mutant" + .status),
primaryLocation: {
message: (
if .status == "NoCoverage" then
"A mutant was not covered by any of the tests. " + $mutation
else
"A mutant survived after running the tests. " + $mutation
end
),
filePath: (
if $ARGS.named["workspace"] != null then
$file.key | sub("^" + $ARGS.named["workspace"] + "/"; "")
elif $projectRoot then
$file.key | sub("^" + $projectRoot + "/"; "")
else
$file.key
end
),
textRange: {
startLine: .location.start.line,
endLine: .location.end.line,
startColumn: (.location.start.column - 1),
endColumn: (.location.end.column - 1)
}
},
type: "CODE_SMELL",
severity: "MAJOR",
effortMinutes: 10
}
)
}

0 comments on commit 33eab90

Please sign in to comment.