Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mutation testing element transformation #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions action.yml

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MegaLinter] reported by reviewdog 🐶

name: SonarQube Issue Conversion
description: Transform tool output into generic SonarQube format(s)
inputs:
input:
description: Single or multiple tool output files to convert
required: true
output:
description: Output file for converted issues
required: true
transformation:
description: Type of transformation to apply (one of gtest-to-generic-execution, mutation-test-to-generic-issue)
required: true
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'
- shell: bash
run: |
python -m pip install --upgrade pip==24.3.1
pip install lxml
- shell: bash
run: |
echo 'Using transformation: ${{ inputs.transformation }} to convert ${{ inputs.input }} to ${{ inputs.output }}'
case ${{ inputs.transformation }} in
'gtest-to-generic-execution')
{ 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 }}'
exit 1
;;
esac

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
}
)
}
Loading