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.config; 11 12 import core.time : Duration, dur; 13 import std.typecons : Nullable; 14 15 import dextool.plugin.mutate.type; 16 import dextool.type : AbsolutePath, Path; 17 public import dextool.plugin.mutate.backend : Mutation, TestGroup; 18 19 /// The mode the tool is operating in 20 enum ToolMode { 21 /// No mode set 22 none, 23 /// analyze for mutation points 24 analyzer, 25 /// center that can operate and control subcomponents 26 generate_mutant, 27 /// test mutation points with a test suite 28 test_mutants, 29 /// generate a report of the mutation points 30 report, 31 /// administrator interface for the mutation database 32 admin, 33 /// Dump the TOML configuration to the console 34 dumpConfig, 35 /// Write a TOML config to the filesystem 36 initConfig, 37 } 38 39 /// Config of the report. 40 struct ConfigReport { 41 ReportKind reportKind; 42 ReportLevel reportLevel; 43 ReportSection[] reportSection; 44 45 /// Directory to write logs to when writing to the filesystem. 46 AbsolutePath logDir; 47 48 /// Controls how to sort test cases by their kill statistics. 49 ReportKillSortOrder tcKillSortOrder; 50 int tcKillSortNum = 20; 51 52 /// User regex for reporting groups of tests 53 TestGroup[] testGroups; 54 55 /// If a unified diff should be used in the report 56 bool unifiedDiff; 57 } 58 59 /// Configuration data for the compile_commands.json 60 struct ConfigCompileDb { 61 import dextool.compilation_db : CompileCommandFilter; 62 63 /// Raw user input via either config or cli 64 string[] rawDbs; 65 66 /// path to compilation databases. 67 AbsolutePath[] dbs; 68 69 /// Flags the user wants to be automatically removed from the compile_commands.json. 70 CompileCommandFilter flagFilter; 71 } 72 73 /// Configuration of how the mutation analyzer should act. 74 struct ConfigAnalyze { 75 /// User input of excludes before they are adjusted to relative root 76 string[] rawExclude; 77 78 /// Exclude any files that are in these directory trees from the analysis. 79 AbsolutePath[] exclude; 80 } 81 82 /// Settings for the compiler 83 struct ConfigCompiler { 84 import dextool.compilation_db : SystemCompiler = Compiler; 85 86 /// Additional flags the user wants to add besides those that are in the compile_commands.json. 87 string[] extraFlags; 88 89 /// True requires system includes to be passed on to the compiler via -I 90 bool forceSystemIncludes; 91 92 /// Deduce compiler flags from this compiler and not the one in the 93 /// supplied compilation database. / This is needed when the one specified 94 /// in the DB has e.g. a c++ stdlib that is not compatible with clang. 95 SystemCompiler useCompilerSystemIncludes; 96 } 97 98 /// Settings for mutation testing 99 struct ConfigMutationTest { 100 ShellCommand[] mutationTester; 101 ShellCommand mutationCompile; 102 ShellCommand mutationTestCaseAnalyze; 103 TestCaseAnalyzeBuiltin[] mutationTestCaseBuiltin; 104 Nullable!Duration mutationTesterRuntime; 105 MutationOrder mutationOrder; 106 bool dryRun; 107 108 /// How to behave when new test cases are detected. 109 enum NewTestCases { 110 doNothing, 111 /// Automatically reset alive mutants 112 resetAlive, 113 } 114 115 NewTestCases onNewTestCases; 116 117 /// How to behave when test cases are detected of having been removed 118 enum RemovedTestCases { 119 doNothing, 120 /// Remove it and all results connectedto the test case 121 remove, 122 } 123 124 RemovedTestCases onRemovedTestCases; 125 126 /// How to behave when mutants have aged. 127 enum OldMutant { 128 nothing, 129 test, 130 } 131 132 OldMutant onOldMutants; 133 long oldMutantsNr; 134 135 /// Max time to run mutation testing. 136 // note that Duration.max + Clock.currTime results in a negative time... 137 Duration maxRuntime = 52.dur!"weeks"; 138 139 // Constrain the mutation testing. 140 TestConstraint constraint; 141 142 /// If constraints should be read from a unified diff via stdin. 143 bool unifiedDiffFromStdin; 144 145 /// Stop after this many alive mutants are found. Only effective if constraint.empty is false. 146 Nullable!int maxAlive; 147 } 148 149 /// Settings for the administration mode 150 struct ConfigAdmin { 151 AdminOperation adminOp; 152 Mutation.Status mutantStatus; 153 Mutation.Status mutantToStatus; 154 string testCaseRegex; 155 long mutationId; 156 string mutantRationale; 157 } 158 159 struct ConfigWorkArea { 160 /// User input root. 161 string rawRoot; 162 string[] rawRestrict; 163 164 AbsolutePath outputDirectory; 165 AbsolutePath[] restrictDir; 166 } 167 168 /// Configuration of the generate mode. 169 struct ConfigGenerate { 170 long mutationId; 171 }