1 /** 2 Copyright: Copyright (c) 2017, 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 This module contains functionality for reporting the mutations. Both the 11 summary and details for each mutation. 12 */ 13 module dextool.plugin.mutate.backend.report; 14 15 import logger = std.experimental.logger; 16 import std.ascii : newline; 17 import std.exception : collectException; 18 19 import dextool.type; 20 21 import dextool.plugin.mutate.backend.database : Database; 22 import dextool.plugin.mutate.backend.diff_parser : Diff, diffFromStdin; 23 import dextool.plugin.mutate.backend.interface_ : FilesysIO; 24 import dextool.plugin.mutate.backend.utility : getProfileResult, Profile; 25 import dextool.plugin.mutate.config : ConfigReport; 26 import dextool.plugin.mutate.type : MutationKind, ReportKind; 27 28 ExitStatusType runReport(const AbsolutePath dbPath, const MutationKind[] kind, 29 const ConfigReport conf, FilesysIO fio) @trusted nothrow { 30 31 ExitStatusType helper(ref Database db) { 32 Diff diff; 33 if (conf.unifiedDiff) { 34 diff = diffFromStdin; 35 } 36 37 final switch (conf.reportKind) with (ReportKind) { 38 case plain: 39 import dextool.plugin.mutate.backend.report.plain : report; 40 41 report(db, kind, conf, fio); 42 break; 43 case compiler: 44 import dextool.plugin.mutate.backend.report.compiler : report; 45 46 report(db, kind, conf, fio); 47 break; 48 case json: 49 import dextool.plugin.mutate.backend.report.json : report; 50 51 report(db, kind, conf, fio, diff); 52 break; 53 case html: 54 import dextool.plugin.mutate.backend.report.html : report; 55 56 report(db, kind, conf, fio, diff); 57 break; 58 } 59 60 if (conf.profile) 61 try { 62 import std.stdio : writeln; 63 64 writeln(getProfileResult.toString); 65 } catch (Exception e) { 66 logger.warning("Unable to print the profile data: ", e.msg).collectException; 67 } 68 return ExitStatusType.Ok; 69 } 70 71 try { 72 auto db = Database.make(dbPath); 73 return helper(db); 74 } catch (Exception e) { 75 logger.error(e.msg).collectException; 76 } 77 78 return ExitStatusType.Errors; 79 }