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

Implement the Stryker HTML report #1149

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
197 changes: 197 additions & 0 deletions mutation-testing-report-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://stryker-mutator.io/report.schema.json",
"title": "Schema for a mutation testing report.",
"type": "object",
"required": [
"schemaVersion",
"thresholds",
"files"
],
"properties": {
"schemaVersion": {
"type": "string",
"pattern": "^1(\\.\\d*)?$",
"title": "Major version of this report. Used for compatibility.",
"examples": [
"1"
]
},
"thresholds": {
"type": "object",
"title": "Thresholds for the status of the reported application.",
"required": [
"high",
"low"
],
"properties": {
"high": {
"type": "integer",
"title": "Higher bound threshold.",
"minimum": 0,
"maximum": 100,
"examples": [
80
]
},
"low": {
"type": "integer",
"title": "Lower bound threshold.",
"minimum": 0,
"maximum": 100,
"examples": [
60
]
}
}
},
"files": {
"type": "object",
"title": "All mutated files.",
"definitions": {
"position": {
"type": "object",
"title": "Position of a mutation. Both line and column start at one.",
"required": [
"line",
"column"
],
"properties": {
"line": {
"type": "integer",
"minimum": 1,
"examples": [
4
]
},
"column": {
"type": "integer",
"minimum": 1,
"examples": [
3
]
}
}
}
},
"additionalProperties": {
"type": "object",
"title": "Mutated file, with the relative path of the file as the key.",
"required": [
"language",
"source",
"mutants"
],
"properties": {
"language": {
"type": "string",
"title": "Programming language that is used. Used for code highlighting, see https://highlightjs.org/static/demo/.",
"examples": [
"javascript",
"typescript",
"cs",
"scala",
"java"
]
},
"source": {
"type": "string",
"title": "Full source code of the mutated file, this is used for highlighting.",
"examples": [
"using System; using....."
]
},
"mutants": {
"type": "array",
"uniqueItems": true,
"items": {
"type": "object",
"title": "Single mutation.",
"required": [
"id",
"mutatorName",
"location",
"status"
],
"properties": {
"id": {
"type": "string",
"title": "Unique id, can be used to correlate this mutant with other reports.",
"examples": [
"321321"
]
},
"mutatorName": {
"type": "string",
"title": "Category of the mutation.",
"examples": [
"ConditionalExpression",
"EqualityOperator",
"LogicalOperator"
]
},
"replacement": {
"type": "string",
"title": "Actual mutation that has been applied.",
"examples": [
"-",
"+",
"&&",
"||"
]
},
"description": {
"type": "string",
"title": "Description of the applied mutation.",
"examples": [
"removed call to java/io/Writer::write"
]
},
"location": {
"type": "object",
"title": "Location of the applied mutation.",
"required": [
"start",
"end"
],
"properties": {
"start": {
"$ref": "#/properties/files/definitions/position",
"title": "Start position of the mutation. Inclusive."
},
"end": {
"$ref": "#/properties/files/definitions/position",
"title": "End position of the mutation. Exclusive."
}
}
},
"status": {
"type": "string",
"title": "Result of the mutation.",
"enum": [
"Killed",
"Survived",
"NoCoverage",
"CompileError",
"RuntimeError",
"Timeout",
"Ignored"
],
"examples": [
"Killed",
"Survived",
"NoCoverage",
"CompileError",
"RuntimeError",
"Timeout",
"Ignored"
]
}
}
}
}
}
}
}
}
}
16 changes: 16 additions & 0 deletions report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>

<head>
<title>Install local example - Mutation test elements</title>
<script defer src="https://www.unpkg.com/mutation-testing-elements"></script>
</head>

<body>
<a href="/">Back</a></li>
<mutation-test-report-app></mutation-test-report-app>
<script>
document.getElementsByTagName('mutation-test-report-app').item(0).report = {"schemaVersion":1,"mutationScore":53.84615384615385,"thresholds":{"low":20,"high":80},"files":{"\/Users\/tfidry\/Project\/Humbug\/infection\/src\/Logger\/TextFileLogger.php":{"language":"php","source":"<?php\n\/**\n * This code is licensed under the BSD 3-Clause License.\n *\n * Copyright (c) 2017, Maks Rafalko\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n *\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation\n * and\/or other materials provided with the distribution.\n *\n * * Neither the name of the copyright holder nor the names of its\n * contributors may be used to endorse or promote products derived from\n * this software without specific prior written permission.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n *\/\n\ndeclare(strict_types=1);\n\nnamespace Infection\\Logger;\n\nuse function array_map;\nuse function explode;\nuse function implode;\nuse Infection\\Mutant\\MetricsCalculator;\nuse Infection\\Mutant\\MutantExecutionResult;\nuse Infection\\Str;\nuse const PHP_EOL;\nuse function Safe\\sprintf;\nuse function str_repeat;\nuse function strlen;\n\n\/**\n * @internal\n *\/\nfinal class TextFileLogger implements LineMutationTestingResultsLogger\n{\n private $metricsCalculator;\n private $debugVerbosity;\n private $onlyCoveredMode;\n private $debugMode;\n\n public function __construct(\n MetricsCalculator $metricsCalculator,\n bool $debugVerbosity,\n bool $onlyCoveredMode,\n bool $debugMode\n ) {\n $this->metricsCalculator = $metricsCalculator;\n $this->debugVerbosity = $debugVerbosity;\n $this->onlyCoveredMode = $onlyCoveredMode;\n $this->debugMode = $debugMode;\n }\n\n public function getLogLines(): array\n {\n $separateSections = false;\n\n $logs[] = $this->getResultsLine(\n $this->metricsCalculator->getEscapedExecutionResults(),\n 'Escaped',\n $separateSections\n );\n $logs[] = $this->getResultsLine(\n $this->metricsCalculator->getTimedOutExecutionResults(),\n 'Timed Out',\n $separateSections\n );\n\n if ($this->debugVerbosity) {\n $logs[] = $this->getResultsLine(\n $this->metricsCalculator->getKilledExecutionResults(),\n 'Killed',\n $separateSections\n );\n $logs[] = $this->getResultsLine(\n $this->metricsCalculator->getErrorExecutionResults(),\n 'Errors',\n $separateSections\n );\n }\n\n if (!$this->onlyCoveredMode) {\n $logs[] = $this->getResultsLine(\n $this->metricsCalculator->getNotCoveredExecutionResults(),\n 'Not Covered',\n $separateSections\n );\n }\n\n if ($separateSections) {\n $logs[] = '';\n }\n\n return $logs;\n }\n\n \/**\n * @param MutantExecutionResult[] $executionResults\n *\/\n private function getResultsLine(\n array $executionResults,\n string $headlinePrefix,\n bool &$separateSections\n ): string {\n $lines = [];\n\n if ($separateSections) {\n $lines[] = '';\n $lines[] = '';\n }\n\n $lines[] = self::getHeadlineLines($headlinePrefix);\n\n $separateSections = false;\n\n foreach ($executionResults as $index => $executionResult) {\n if ($separateSections) {\n $lines[] = '';\n $lines[] = '';\n }\n\n $lines[] = self::getMutatorLine($index, $executionResult);\n $lines[] = '';\n $lines[] = Str::trimLineReturns($executionResult->getMutationDiff());\n\n if ($this->debugMode) {\n $lines[] = '';\n $lines[] = '$ ' . $executionResult->getProcessCommandLine();\n }\n\n if ($this->debugVerbosity) {\n if (!$this->debugMode) {\n $lines[] = '';\n }\n\n $lines[] = self::getProcessOutputLine($executionResult->getProcessOutput());\n }\n\n $separateSections = true;\n }\n\n return implode(PHP_EOL, $lines);\n }\n\n private static function getHeadlineLines(string $headlinePrefix): string\n {\n $headline = sprintf('%s mutants:', $headlinePrefix);\n\n return implode(\n PHP_EOL,\n [\n $headline,\n str_repeat('=', strlen($headline)),\n '',\n ]\n );\n }\n\n private static function getMutatorLine(int $index, MutantExecutionResult $mutantProcess): string\n {\n return sprintf(\n '%d) %s:%d [M] %s',\n $index + 1,\n $mutantProcess->getOriginalFilePath(),\n $mutantProcess->getOriginalStartingLine(),\n $mutantProcess->getMutatorName()\n );\n }\n\n private static function getProcessOutputLine(string $value): string\n {\n return implode(\n PHP_EOL,\n array_map(\n static function (string $line): string {\n return ' ' . $line;\n },\n explode(PHP_EOL, Str::trimLineReturns($value))\n )\n );\n }\n}\n","mutants":[{"id":"49e4c033e82152deffaff902aa51ac0e","mutatorName":"FalseValue","replacement":" $separateSections = true;","description":"yo","location":{"start":{"line":73,"column":9},"end":{"line":73,"column":35}},"status":"Killed"},{"id":"20a5ecac3e1b72a7e9165b2561d915f6","mutatorName":"LogicalNot","replacement":" if ($this->onlyCoveredMode) {","description":"yo","location":{"start":{"line":99,"column":9},"end":{"line":99,"column":39}},"status":"Killed"},{"id":"38059b5b328cbcf554448979bd91f0a0","mutatorName":"ArrayOneItem","replacement":" return count($logs) > 1 ? array_slice($logs, 0, 1, true) : $logs;","description":"yo","location":{"start":{"line":111,"column":9},"end":{"line":111,"column":75}},"status":"Killed"},{"id":"a75a4009b933f26f9c429376eddd3523","mutatorName":"FalseValue","replacement":" $separateSections = true;","description":"yo","location":{"start":{"line":131,"column":9},"end":{"line":131,"column":35}},"status":"Killed"},{"id":"3de83231228d28dd3a9a8fd29dc27e16","mutatorName":"Foreach_","replacement":" foreach (array() as $index => $executionResult) {","description":"yo","location":{"start":{"line":133,"column":9},"end":{"line":157,"column":59}},"status":"Killed"},{"id":"ebf143eb565188ddd7959bfbe70f631f","mutatorName":"LogicalNot","replacement":" if ($this->debugMode) {","description":"yo","location":{"start":{"line":149,"column":17},"end":{"line":149,"column":41}},"status":"NoCoverage"},{"id":"78df83645d5862a489725a1ca83c2e46","mutatorName":"TrueValue","replacement":" $separateSections = false;","description":"yo","location":{"start":{"line":156,"column":13},"end":{"line":156,"column":40}},"status":"NoCoverage"},{"id":"f846f1fb950a4effa3412240e7f47824","mutatorName":"ArrayItemRemoval","replacement":" return implode(PHP_EOL, [str_repeat('=', strlen($headline)), '']);","description":"yo","location":{"start":{"line":168,"column":9},"end":{"line":172,"column":76}},"status":"Killed"},{"id":"8054ad82df5a2551ed9626773f43a04d","mutatorName":"UnwrapStrRepeat","replacement":" return implode(PHP_EOL, [$headline, '=', '']);","description":"yo","location":{"start":{"line":170,"column":9},"end":{"line":170,"column":56}},"status":"Killed"},{"id":"bf33233e4af421b6a9847e7e74496280","mutatorName":"IncrementInteger","replacement":" return sprintf('%d) %s:%d [M] %s', $index + 2, $mutantProcess->getOriginalFilePath(), $mutantProcess->getOriginalStartingLine(), $mutantProcess->getMutatorName());","description":"yo","location":{"start":{"line":180,"column":9},"end":{"line":180,"column":176}},"status":"NoCoverage"},{"id":"2b8250c49e391d4977b8845335444060","mutatorName":"OneZeroInteger","replacement":" return sprintf('%d) %s:%d [M] %s', $index + 0, $mutantProcess->getOriginalFilePath(), $mutantProcess->getOriginalStartingLine(), $mutantProcess->getMutatorName());","description":"yo","location":{"start":{"line":180,"column":9},"end":{"line":180,"column":176}},"status":"NoCoverage"},{"id":"69422fbd0d5e80c9838c02bacc4e280f","mutatorName":"Plus","replacement":" return sprintf('%d) %s:%d [M] %s', $index - 1, $mutantProcess->getOriginalFilePath(), $mutantProcess->getOriginalStartingLine(), $mutantProcess->getMutatorName());","description":"yo","location":{"start":{"line":180,"column":9},"end":{"line":180,"column":176}},"status":"NoCoverage"},{"id":"2e34f5a6b5f690e84959724852b8a05c","mutatorName":"UnwrapArrayMap","replacement":" return implode(PHP_EOL, explode(PHP_EOL, Str::trimLineReturns($value)));","description":"yo","location":{"start":{"line":191,"column":9},"end":{"line":196,"column":82}},"status":"NoCoverage"}]}}};
</script>
</body>

</html>