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_nomut; 11 12 import logger = std.experimental.logger; 13 import std.format : format; 14 15 import arsd.dom : Document, Element, require, Table; 16 17 import dextool.plugin.mutate.backend.database : Database, MutantMetaData; 18 import dextool.plugin.mutate.backend.report.html.constants; 19 import dextool.plugin.mutate.backend.report.html.tmpl : tmplBasicPage, tmplDefaultTable; 20 import dextool.plugin.mutate.backend.report.utility; 21 import dextool.plugin.mutate.backend.type : Mutation; 22 import dextool.plugin.mutate.config : ConfigReport; 23 import dextool.plugin.mutate.type : MutationKind; 24 import dextool.type : AbsolutePath; 25 26 auto makeNomut(ref Database db, ref const ConfigReport conf, 27 const(MutationKind)[] humanReadableKinds, const(Mutation.Kind)[] kinds) @trusted { 28 import std.datetime : Clock; 29 30 auto doc = tmplBasicPage; 31 doc.title(format("NoMut Details %(%s %) %s", humanReadableKinds, Clock.currTime)); 32 doc.mainBody.addChild("p", 33 "This is all the mutation suppressions that are used and affects the analysis."); 34 35 db.getMutantationMetaData(kinds, Mutation.Status.alive).toHtml(db, doc.mainBody); 36 37 return doc.toPrettyString; 38 } 39 40 private: 41 42 // TODO: this is very inefficient implementation. There are so many lookups in 43 // the database. It "works" as long as there are only a limited amount of 44 // nomut. 45 void toHtml(MutantMetaData[] data, ref Database db, Element root) { 46 import std.algorithm : sort; 47 import std.array : array, empty; 48 import std.path : buildPath; 49 import std.typecons : Tuple; 50 import std.uni : toLower; 51 import sumtype; 52 import dextool.plugin.mutate.backend.database : MutationId, NoMetadata, NoMut; 53 import dextool.plugin.mutate.backend.report.html.page_files : pathToHtmlLink; 54 55 alias IdComment = Tuple!(MutationId, "id", string, "comment"); 56 IdComment[][string] tags; 57 58 foreach (x; data) { 59 x.attr.match!((NoMetadata a) {}, (NoMut a) { 60 tags[a.tag.toLower] ~= IdComment(x.id, a.comment); 61 }); 62 } 63 64 foreach (tag; tags.byKey.array.sort) { 65 if (!tag.empty) 66 root.addChild("h2", tag); 67 68 auto tbl = tmplDefaultTable(root, ["Mutant"]); 69 foreach (m; tags[tag].array.sort!((a, b) => a.comment < b.comment)) { 70 auto r = tbl.appendRow(); 71 72 auto file = db.getPath(m.id); 73 if (file.isNull) 74 continue; 75 76 auto td = r.addChild("td"); 77 td.addChild("a", file.get).href = format("%s#%s", 78 buildPath(htmlFileDir, pathToHtmlLink(file.get)), m.id); 79 td.addChild("br"); 80 td.appendText(m.comment); 81 } 82 } 83 }