1 /**
2 Copyright: Copyright (c) 2017, Joakim Brännström. All rights reserved.
3 License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
4 Author: Joakim Brännström (joakim.brannstrom@gmx.com)
5 
6 #TST-plugin_mutate_mutation_dcc
7 */
8 module dextool_test.mutate_dcc;
9 
10 import dextool_test.utility;
11 
12 // dfmt off
13 
14 @("shall produce 2 predicate mutations")
15 unittest {
16     mixin(EnvSetup(globalTestdir));
17     makeDextoolAnalyze(testEnv)
18         .addInputArg(testData ~ "dcc_dc_ifstmt1.cpp")
19         .run;
20     auto r = makeDextool(testEnv)
21         .addArg(["test"])
22         .addArg(["--mutant", "dcc"])
23         .run;
24     testAnyOrder!SubStr([
25         "from 'x' to 'true'",
26         "from 'x' to 'false'",
27     ]).shouldBeIn(r.stdout);
28 }
29 
30 @("shall produce 4 predicate mutations")
31 unittest {
32     mixin(EnvSetup(globalTestdir));
33     makeDextoolAnalyze(testEnv)
34         .addInputArg(testData ~ "dcc_dc_ifstmt2.cpp")
35         .run;
36     auto r = makeDextool(testEnv)
37         .addArg(["test"])
38         .addArg(["--mutant", "dcc"])
39         .run;
40     testAnyOrder!SubStr([
41         "from 'x' to 'true'",
42         "from 'x' to 'false'",
43         "from 'y' to 'true'",
44         "from 'y' to 'false'",
45     ]).shouldBeIn(r.stdout);
46 }
47 
48 @("shall produce 2 predicate mutations for an expression of multiple clauses")
49 @Values("dcc_dc_ifstmt3.cpp", "dcc_dc_stmt3.cpp")
50 unittest {
51     mixin(envSetup(globalTestdir, No.setupEnv));
52     testEnv.outputSuffix(getValue!string);
53     testEnv.setupEnv;
54 
55     makeDextoolAnalyze(testEnv)
56         .addInputArg(testData ~ getValue!string)
57         .run;
58     auto r = makeDextool(testEnv)
59         .addArg(["test"])
60         .addArg(["--mutant", "dcc"])
61         .run;
62     testAnyOrder!SubStr([
63         "from 'x == 0 || y == 0' to 'true'",
64         "from 'x == 0 || y == 0' to 'false'",
65     ]).shouldBeIn(r.stdout);
66 }
67 
68 @("shall produce 6 clause mutations")
69 @Values("dcc_cc_ifstmt1.cpp", "dcc_cc_stmt1.cpp")
70 unittest {
71     mixin(envSetup(globalTestdir, No.setupEnv));
72     testEnv.outputSuffix(getValue!string);
73     testEnv.setupEnv;
74 
75     makeDextoolAnalyze(testEnv)
76         .addInputArg(testData ~ getValue!string)
77         .run;
78     auto r = makeDextool(testEnv)
79         .addArg(["test"])
80         .addArg(["--mutant", "dcc"])
81         .run;
82     testAnyOrder!SubStr([
83         "from 'x == 0' to 'true'",
84         "from 'x == 0' to 'false'",
85         "from 'x == 1' to 'true'",
86         "from 'x == 1' to 'false'",
87         "from 'x == 2' to 'true'",
88         "from 'x == 2' to 'false'",
89         "from 'y > 0' to 'true'",
90         "from 'y > 0' to 'false'",
91         "from 'x > 2' to 'true'",
92         "from 'x > 2' to 'false'",
93     ]).shouldBeIn(r.stdout);
94 
95     r.stdout.joiner.count("'x == 0'").shouldEqual(2);
96     r.stdout.joiner.count("'x == 1'").shouldEqual(2);
97     r.stdout.joiner.count("'x == 2'").shouldEqual(2);
98     r.stdout.joiner.count("'y > 0'").shouldEqual(2);
99     r.stdout.joiner.count("'x > 2'").shouldEqual(2);
100 }
101 
102 @("shall produce 4 switch bomb mutations")
103 unittest {
104     mixin(EnvSetup(globalTestdir));
105     makeDextoolAnalyze(testEnv)
106         .addInputArg(testData ~ "dcc_dc_switch1.cpp")
107         .run;
108     auto r = makeDextool(testEnv)
109         .addArg(["test"])
110         .addArg(["--mutant", "dcc"])
111         .run;
112     testAnyOrder!SubStr([
113         "from 'return -1 ;' to '*((char*)0)='x';break;'",
114         "from 'return 1;' to '*((char*)0)='x';break;'",
115         "from 'break;' to '*((char*)0)='x';break;'",
116         "from '' to '*((char*)0)='x';break;'",
117     ]).shouldBeIn(r.stdout);
118 }
119 
120 @("shall produce 4 switch deletion mutations")
121 unittest {
122     mixin(EnvSetup(globalTestdir));
123     makeDextoolAnalyze(testEnv)
124         .addInputArg(testData ~ "dcc_dc_switch1.cpp")
125         .run;
126     auto r = makeDextool(testEnv)
127         .addArg(["test"])
128         .addArg(["--mutant", "dcr"])
129         .run;
130     testConsecutiveSparseOrder!SubStr([
131         "from 'case 0:",
132         "return -1 ;' to '/*case 0:",
133         "return -1 ;*/'",
134 
135         "from 'case 1:",
136         "return 1;' to '/*case 1:",
137         "return 1;*/'",
138 
139         "from 'case 3:",
140         "break;' to '/*case 3:",
141         "break;*/'",
142 
143         "from 'case 4:' to '/*case 4:*/'",
144     ]).shouldBeIn(r.stdout);
145 }