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     /// any kind of mutation
17     any,
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     /// Absolute value replacement
29     abs,
30     /// Statement deletion
31     sdl,
32     /// Conditional operator replacement
33     cor,
34     /// Decision/Condition Coverage
35     dcc,
36     /// Decision/Condition Requirement
37     dcr,
38     /// Logical Connector Replacement Bit-wise
39     lcrb,
40 }
41 
42 /// The order the mutations are done when running in test_mutants mode
43 enum MutationOrder {
44     random,
45     consecutive,
46 }
47 
48 /// The kind of report to generate to the user
49 enum ReportKind {
50     /// As a plain text output
51     plain,
52     /// As a markdown report that
53     markdown,
54     /// As compiler warnings and a fix-it hint for the mutation
55     compiler,
56     /// As a JSON model
57     json,
58     /// In the CSV format
59     csv,
60     /// As a HTML report
61     html,
62 }
63 
64 /// The level of reporting
65 enum ReportLevel {
66     /// Report a summary of the mutation statistics
67     summary,
68     /// Report alive mutants
69     alive,
70     /// Report all mutants
71     all
72 }
73 
74 /// Sections to include in the report
75 enum ReportSection {
76     /// alive mutants
77     alive,
78     /// killed mutants
79     killed,
80     /// all mutants
81     all_mut,
82     /// summary section of the mutation testing
83     summary,
84     /// mutation statistics
85     mut_stat,
86     /// test cases that killed the mutant
87     tc_killed,
88     /// test case statistics
89     tc_stat,
90     /// test case mapping to killed mutants
91     tc_map,
92     /// test case suggestions for killing mutants
93     tc_suggestion,
94     /// Test cases that has killed zero mutants
95     tc_killed_no_mutants,
96     /// Test cases that kill the same mutants
97     tc_full_overlap,
98     /// Test cases that kill the same mutants with a mutation ID column
99     tc_full_overlap_with_mutation_id,
100     /// Test groups defined by the user
101     tc_groups,
102     /// Minimal set of tests
103     tc_min_set,
104     /// Similarity between test cases
105     tc_similarity,
106     /// Similarity between test groups
107     tc_groups_similarity,
108     /// A treemap of the mutation scores
109     treemap,
110     /// mutants that has survived that the plugin recommend the user to kill
111     mut_recommend_kill,
112     /// a section containing a diff and mutants for it
113     diff,
114     /// report of the mutants that only the test case kill
115     tc_unique,
116     /// mutants manually marked by user
117     marked_mutants
118 }
119 
120 /// How to sort test cases when reporting them by their kill statistics.
121 enum ReportKillSortOrder {
122     /// From the top down
123     top,
124     /// From the botton up
125     bottom,
126 }
127 
128 /// Administrative operation to perform
129 enum AdminOperation {
130     none,
131     /// Reset mutants to unknown
132     resetMutant,
133     ///
134     removeMutant,
135     ///
136     removeTestCase,
137     ///
138     markMutant,
139     ///
140     removeMarkedMutant,
141 }
142 
143 /// Builtin analyzers for testing frameworks that find failing test cases
144 enum TestCaseAnalyzeBuiltin {
145     /// Tracker for the GoogleTest framework
146     gtest,
147     /// Tracker for the CTest binary test runner
148     ctest,
149     /// Tracker for failing makefile targets
150     makefile,
151 }
152 
153 /// A line in a file.
154 struct Line {
155     uint value;
156 }
157 
158 /// A constraint for what to mutate during the test phase..
159 struct TestConstraint {
160     Line[][Path] value;
161 
162     bool empty() @safe pure nothrow const @nogc {
163         return value.length == 0;
164     }
165 }
166 
167 struct ShellCommand {
168     import std.range : isOutputRange;
169 
170     string[] value;
171 
172     /// Split a user string by the whitespace to create an command+argument.
173     static ShellCommand fromString(string cmd) {
174         import std.uni : isWhite;
175         import std.array : split;
176 
177         string[] args = cmd.split!isWhite;
178         return ShellCommand(args);
179     }
180 
181     bool empty() @safe pure nothrow const @nogc {
182         return value.length == 0;
183     }
184 
185     string toString() @safe pure const {
186         import std.array : appender;
187 
188         auto buf = appender!string;
189         toString(buf);
190         return buf.data;
191     }
192 
193     void toString(Writer)(ref Writer w) const if (isOutputRange!(Writer, char)) {
194         import std.format : formattedWrite;
195 
196         formattedWrite(w, "shell command '%-(%s %)'", value);
197     }
198 }