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