1 /** 2 Copyright: Copyright (c) 2018, Joakim Brännström. All rights reserved. 3 License: MPL-2 4 Author: Joakim Brännström (joakim.brannstrom@gmx.com) 5 6 This Source Code Form is subject to the terms of the Mozilla Public License, 7 v.2.0. If a copy of the MPL was not distributed with this file, You can obtain 8 one at http://mozilla.org/MPL/2.0/. 9 */ 10 module dextool.plugin.mutate.backend.report.html.page_minimal_set; 11 12 import logger = std.experimental.logger; 13 import std.format : format; 14 15 import arsd.dom : Document, Element, require, Table, RawSource; 16 17 import dextool.plugin.mutate.backend.database : Database; 18 import dextool.plugin.mutate.backend.report.analyzers : MinimalTestSet, reportMinimalSet; 19 import dextool.plugin.mutate.backend.report.html.constants; 20 import dextool.plugin.mutate.backend.resource; 21 import dextool.plugin.mutate.backend.report.html.tmpl : tmplBasicPage, 22 tmplDefaultTable, dashboardCss, tmplDefaultMatrixTable; 23 import dextool.plugin.mutate.backend.type : Mutation; 24 import dextool.plugin.mutate.config : ConfigReport; 25 26 auto makeMinimalSetAnalyse(ref Database db, ref const ConfigReport conf) @trusted { 27 auto doc = tmplBasicPage.dashboardCss; 28 29 auto s = doc.root.childElements("head")[0].addChild("script"); 30 s.addChild(new RawSource(doc, jsTableOnClick)); 31 32 doc.title("Minimal Set Analyse"); 33 doc.mainBody.setAttribute("onload", "init()"); 34 doc.mainBody.addChild("p", 35 "This are the minimal set of mutants that result in the mutation score."); 36 37 auto p = doc.mainBody.addChild("p"); 38 39 toHtml(reportMinimalSet(db), doc.mainBody); 40 41 return doc.toPrettyString; 42 } 43 44 private: 45 46 void toHtml(MinimalTestSet min_set, Element root) { 47 import core.time : Duration; 48 import std.conv : to; 49 50 { 51 root.addChild("p", 52 "The tables are hidden by default, click on the corresponding header to display a table."); 53 with (root.addChild("button", "expand all")) { 54 setAttribute("type", "button"); 55 setAttribute("id", "expand_all"); 56 } 57 with (root.addChild("button", "collapse all")) { 58 setAttribute("type", "button"); 59 setAttribute("id", "collapse_all"); 60 } 61 auto comp_container = root.addChild("div").addClass("comp_container"); 62 auto heading = comp_container.addChild("h2").addClass("tbl_header"); 63 heading.addChild("i").addClass("right"); 64 heading.appendText(format!" Ineffective Test Cases (%s/%s %s)"(min_set.redundant.length, 65 min_set.total, cast(double) min_set.redundant.length / cast(double) min_set.total)); 66 comp_container.addChild("p", 67 "These test cases do not contribute towards the mutation score."); 68 auto tbl_container = comp_container.addChild("div").addClass("tbl_container"); 69 tbl_container.setAttribute("style", "display: none;"); 70 auto tbl = tmplDefaultTable(tbl_container, [ 71 "Test Case", "Killed", "Sum of test time" 72 ]); 73 74 Duration sum; 75 foreach (const tc; min_set.redundant) { 76 auto r = tbl.appendRow(); 77 r.addChild("td", tc.name); 78 r.addChild("td", min_set.testCaseTime[tc.name].killedMutants.to!string); 79 r.addChild("td", min_set.testCaseTime[tc.name].time.sum.to!string); 80 sum += min_set.testCaseTime[tc.name].time.sum; 81 } 82 tbl_container.addChild("p", format("Total test time: %s", sum)); 83 } 84 { 85 auto comp_container = root.addChild("div").addClass("comp_container"); 86 auto heading = comp_container.addChild("h2").addClass("tbl_header"); 87 heading.addChild("i").addClass("right"); 88 heading.appendText(format!" Minimal Set (%s/%s %s)"(min_set.minimalSet.length, 89 min_set.total, cast(double) min_set.minimalSet.length / cast(double) min_set.total)); 90 comp_container.addChild("p", 91 "This is the minimum set of tests that achieve the mutation score."); 92 93 auto tbl_container = comp_container.addChild("div").addClass("tbl_container"); 94 tbl_container.setAttribute("style", "display: none;"); 95 auto tbl = tmplDefaultTable(tbl_container, [ 96 "Test Case", "Killed", "Sum of test time" 97 ]); 98 99 Duration sum; 100 foreach (const tc; min_set.minimalSet) { 101 auto r = tbl.appendRow(); 102 r.addChild("td", tc.name); 103 r.addChild("td", min_set.testCaseTime[tc.name].killedMutants.to!string); 104 r.addChild("td", min_set.testCaseTime[tc.name].time.sum.to!string); 105 sum += min_set.testCaseTime[tc.name].time.sum; 106 } 107 tbl_container.addChild("p", format("Total test time: %s", sum)); 108 } 109 }