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 module dextool.plugin.mutate.type;
11 
12 import dextool.type : Path, AbsolutePath;
13 
14 /// The kind of mutation to perform
15 enum MutationKind {
16     /// all mutation operators are used
17     all,
18     /// Relational operator replacement
19     ror,
20     /// Relational operator replacement for pointers
21     rorp,
22     /// Logical connector replacement
23     lcr,
24     /// Arithmetic operator replacement
25     aor,
26     /// Unary operator insert
27     uoi,
28     /// Statement deletion
29     sdl,
30     /// Decision/Condition Requirement
31     dcr,
32     /// Logical Connector Replacement Bit-wise
33     lcrb,
34     /// rithmetic operator replacement simple
35     aors,
36     /// constant replacement
37     cr,
38 }
39 
40 /// The order the mutations are done when running in test_mutants mode
41 enum MutationOrder {
42     random,
43     consecutive,
44     bySize,
45 }
46 
47 /// The kind of report to generate to the user
48 enum ReportKind {
49     /// As a plain text output
50     plain,
51     /// As compiler warnings and a fix-it hint for the mutation
52     compiler,
53     /// As a JSON model
54     json,
55     /// As a HTML report
56     html,
57 }
58 
59 /// Sections to include in the report
60 enum ReportSection {
61     /// alive mutants
62     alive,
63     /// killed mutants
64     killed,
65     /// all mutants
66     all_mut,
67     /// summary section of the mutation testing
68     summary,
69     /// mutation statistics
70     mut_stat,
71     /// test cases that killed the mutant
72     tc_killed,
73     /// test case statistics
74     tc_stat,
75     /// test case mapping to killed mutants
76     tc_map,
77     /// test case suggestions for killing mutants
78     tc_suggestion,
79     /// Test cases that has killed zero mutants
80     tc_killed_no_mutants,
81     /// Test cases that kill the same mutants
82     tc_full_overlap,
83     /// Test cases that kill the same mutants with a mutation ID column
84     tc_full_overlap_with_mutation_id,
85     /// Test groups defined by the user
86     tc_groups,
87     /// Minimal set of tests
88     tc_min_set,
89     /// Similarity between test cases
90     tc_similarity,
91     /// Similarity between test groups
92     tc_groups_similarity,
93     /// A treemap of the mutation scores
94     treemap,
95     /// mutants that has survived that the plugin recommend the user to kill
96     mut_recommend_kill,
97     /// a section containing a diff and mutants for it
98     diff,
99     /// report of the mutants that only the test case kill
100     tc_unique,
101     /// mutants manually marked by user
102     marked_mutants,
103     /// trend information of how mutation score is predicted to evolve
104     trend,
105 }
106 
107 /// How to sort test cases when reporting them by their kill statistics.
108 enum ReportKillSortOrder {
109     /// From the top down
110     top,
111     /// From the botton up
112     bottom,
113 }
114 
115 /// Administrative operation to perform
116 enum AdminOperation {
117     none,
118     /// Reset mutants to unknown
119     resetMutant,
120     ///
121     removeMutant,
122     ///
123     removeTestCase,
124     ///
125     markMutant,
126     ///
127     removeMarkedMutant,
128     ///
129     resetTestCase,
130     /// compact the database to reduce the disc space it takes up
131     compact,
132     /// force a mutation testing to stop testing timeout mutants
133     stopTimeoutTest,
134     /// Reset all mutants of a kind
135     resetMutantSubKind,
136     /// reset the worklist of mutants to test
137     clearWorklist,
138 }
139 
140 /// Builtin analyzers for testing frameworks that find failing test cases
141 enum TestCaseAnalyzeBuiltin {
142     /// Tracker for the GoogleTest framework
143     gtest,
144     /// Tracker for the CTest binary test runner
145     ctest,
146     /// Tracker for failing makefile targets
147     makefile,
148     /// Only track the test_cmd
149     test_cmd
150 }
151 
152 /// A line in a file.
153 struct Line {
154     uint value;
155 }
156 
157 /// A constraint for what to mutate during the test phase..
158 struct TestConstraint {
159     Line[][Path] value;
160 
161     bool empty() @safe pure nothrow const @nogc {
162         return value.length == 0;
163     }
164 }
165 
166 struct ShellCommand {
167     import std.algorithm : joiner;
168     import std.array : appender;
169     import std.format : formattedWrite;
170     import std.path : relativePath;
171     import std.range : isOutputRange, only;
172     import std.string : join;
173 
174     string[] value;
175 
176     bool empty() @safe pure nothrow const @nogc {
177         return value.length == 0;
178     }
179 
180     string toString() @safe pure const {
181         auto buf = appender!string;
182         toString(buf);
183         return buf.data;
184     }
185 
186     void toString(Writer)(ref Writer w) const if (isOutputRange!(Writer, char)) {
187         formattedWrite(w, "shell command '%-(%s %)'", value);
188     }
189 
190     string toShortString() @safe nothrow const {
191         auto r = () nothrow{
192             try {
193                 return value[0].relativePath;
194             } catch (Exception e) {
195             }
196             return value[0];
197         }();
198         if (value.length == 1)
199             return r;
200         return only([r], value[1 .. $]).joiner.join(" ");
201     }
202 }
203 
204 struct UserRuntime {
205     import dextool.plugin.mutate.backend.type : Language;
206 
207     Path file;
208     Language lang;
209 }
210 
211 enum SchemaRuntime : ubyte {
212     inject,
213     library,
214 }
215 
216 enum CoverageRuntime : ubyte {
217     inject,
218     library,
219 }