@@ -31,6 +31,7 @@ public class Console {
3131 static String [] methodsToMutate = null ;
3232 static boolean mutationScore = false ;
3333 static String [] testClasses = new String []{"mutationScore.BooleanOpsAndTests" , "mutationScore.BooleanOpsXorTests" , "mutationScore.BooleanOpsXnorTests" , "mutationScore.BooleanOpsOrTests" };
34+ static int generations = 1 ;
3435
3536 public static void main (String [] args ) {
3637
@@ -67,6 +68,8 @@ public static void main(String[] args) {
6768 flags .setNoValueFlag ('p' ); //disable mutations of the form a = b where a is of type Object and b is a primitive type expression
6869 flags .setNoValueFlag ('w' ); //wrap mutations of the form a = b to a = new T(b), where a is of type Object and b is a primitive type expression
6970 flags .setNoValueFlag ('r' ); //apply refined versions of PRVO to mutate arguments in statements containing only a method call
71+ flags .setOptionalFlag ('g' ); //define how many mutants generations to generate
72+ flags .setNoValueFlag ('W' ); //show surviving mutants
7073 flags .setDependence ('T' , 'S' );
7174 flags .setDependence ('S' , 'T' );
7275 flags .setDependence ('t' , 'T' );
@@ -82,12 +85,14 @@ public static void main(String[] args) {
8285 flags .setDependence ('p' , 'm' );
8386 flags .setDependence ('w' , 'm' );
8487 flags .setDependence ('r' , 'm' );
88+ flags .setDependence ('W' , 'S' );
8589
8690
8791 System .out .println ("Validating parameters..." );
8892 //================================validate input================================================//
8993 if (!flags .validateInput (args )) {
90- System .out .println ("To get help on how to run mujava++ please run with only flag -H" );
94+ System .err .println ("Invalid Params" );
95+ System .err .println ("To get help on how to run mujava++ please run with only flag -H" );
9196 return ;
9297 }
9398
@@ -99,14 +104,14 @@ public static void main(String[] args) {
99104 if (flags .flagExist ('x' )) {
100105 for (String op : flags .getFlagValues ('x' )) {
101106 if (!mi .isSupported (Mutant .valueOf (op ))) {
102- System .out .println ("Mutation operator (" +op +") is unsupported" );
103- System .out .println ("To see a list with all mutation operators currently supported run mujava++ with only flag -h" );
107+ System .err .println ("Mutation operator (" +op +") is unsupported" );
108+ System .err .println ("To see a list with all mutation operators currently supported run mujava++ with only flag -h" );
104109 return ;
105110 }
106111 ops .add (Mutant .valueOf (op ));
107112 }
108113 } else {
109- ops .addAll (mi .listBasicOperators ());
114+ ops .addAll (mi .allOps ());
110115 }
111116 System .out .println ("Operators: " + ops .toString ());
112117
@@ -126,7 +131,7 @@ public static void main(String[] args) {
126131 //mutant source dir
127132 List <String > mutDir = flags .getFlagValues ('M' );
128133 if (mutDir .size () != 1 ) {
129- System .out .println ("-M flag must have only one value" );
134+ System .err .println ("-M flag must have only one value" );
130135 return ;
131136 }
132137 if (verifyDirectory (mutDir .get (0 ))) {
@@ -140,11 +145,11 @@ public static void main(String[] args) {
140145 //original source dir
141146 List <String > sourceDir = flags .getFlagValues ('O' );
142147 if (sourceDir .size () != 1 ) {
143- System .out .println ("-O flag must have only one value" );
148+ System .err .println ("-O flag must have only one value" );
144149 return ;
145150 }
146151 if (!verifyDirectory (sourceDir .get (0 ))) {
147- System .out .println ("Original source directory (" +sourceDir .get (0 )+") doesn't exist" );
152+ System .err .println ("Original source directory (" +sourceDir .get (0 )+") doesn't exist" );
148153 return ;
149154 }
150155 originalSourceDir = sourceDir .get (0 );
@@ -154,11 +159,11 @@ public static void main(String[] args) {
154159 //original bin dir
155160 List <String > binDir = flags .getFlagValues ('B' );
156161 if (binDir .size () != 1 ) {
157- System .out .println ("-B flag must have only one value" );
162+ System .err .println ("-B flag must have only one value" );
158163 return ;
159164 }
160165 if (!verifyDirectory (binDir .get (0 ))) {
161- System .out .println ("Original bin directory (" +binDir .get (0 )+") doesn't exist" );
166+ System .err .println ("Original bin directory (" +binDir .get (0 )+") doesn't exist" );
162167 return ;
163168 }
164169 originalBinDir = binDir .get (0 );
@@ -169,11 +174,11 @@ public static void main(String[] args) {
169174 if (mutationScore ) {
170175 List <String > testDir = flags .getFlagValues ('T' );
171176 if (testDir .size () != 1 ) {
172- System .out .println ("-T flag must have only one value" );
177+ System .err .println ("-T flag must have only one value" );
173178 return ;
174179 }
175180 if (!verifyDirectory (testDir .get (0 ))) {
176- System .out .println ("Tests directory (" +testDir .get (0 )+") doesn't exist" );
181+ System .err .println ("Tests directory (" +testDir .get (0 )+") doesn't exist" );
177182 return ;
178183 }
179184 testBinDir = testDir .get (0 );
@@ -183,7 +188,7 @@ public static void main(String[] args) {
183188 //=============================verify class to mutate============================================//
184189 List <String > ctm = flags .getFlagValues ('m' );
185190 if (ctm .size () != 1 ) {
186- System .out .println ("-m flag must have only one value" );
191+ System .err .println ("-m flag must have only one value" );
187192 return ;
188193 }
189194 System .out .println ("\n \n Verifying class to mutate..." );
@@ -193,7 +198,7 @@ public static void main(String[] args) {
193198 System .out .println ("Class to mutate as path: " +ctm .get (0 ).replaceAll ("\\ ." , Core .SEPARATOR ));
194199 System .out .println ("Class to mutate full path: " +originalSourceDir +ctm .get (0 ).replaceAll ("\\ ." , Core .SEPARATOR )+".java\n " );
195200 if (!verifyFile (originalSourceDir +ctm .get (0 ).replaceAll ("\\ ." , Core .SEPARATOR )+".java" )) {
196- System .out .println ("Class to mutate (" +(originalSourceDir +ctm .get (0 ).replaceAll ("\\ ." , Core .SEPARATOR )+".java" )+") doesn't exist" );
201+ System .err .println ("Class to mutate (" +(originalSourceDir +ctm .get (0 ).replaceAll ("\\ ." , Core .SEPARATOR )+".java" )+") doesn't exist" );
197202 return ;
198203 }
199204 classToMutate = ctm .get (0 );
@@ -205,7 +210,7 @@ public static void main(String[] args) {
205210 List <String > tclasses = flags .getFlagValues ('t' );
206211 for (String tc : tclasses ) {
207212 if (!verifyFile (testBinDir +tc .replaceAll ("\\ ." , Core .SEPARATOR )+".class" )) {
208- System .out .println ("Test class (" +(testBinDir +tc .replaceAll ("\\ ." , Core .SEPARATOR )+".class" )+") doesn't exist" );
213+ System .err .println ("Test class (" +(testBinDir +tc .replaceAll ("\\ ." , Core .SEPARATOR )+".class" )+") doesn't exist" );
209214 return ;
210215 }
211216 }
@@ -224,7 +229,7 @@ public static void main(String[] args) {
224229 mtm .addAll (flags .getFlagValues ('s' ));
225230 for (String m : mtm ) {
226231 if (!verifyMethod (m )) {
227- System .out .println ("No such method (" +m +") on class to mutate (" +classToMutate +")" );
232+ System .err .println ("No such method (" +m +") on class to mutate (" +classToMutate +")" );
228233 return ;
229234 }
230235 }
@@ -350,24 +355,46 @@ public static void main(String[] args) {
350355 Configuration .add (Configuration .ENABLE_REFINEMENT_IN_METHOD_CALL_STATEMENTS , Boolean .FALSE );
351356 }
352357
358+ if (flags .flagExist ('g' )) {
359+ List <String > valuesForGeneration = flags .getFlagValues ('g' );
360+ if (valuesForGeneration .size () != 1 ) {
361+ System .err .println ("Only one value is accepted for flag -g (values given : " + valuesForGeneration .size () + ")" );
362+ return ;
363+ }
364+ generations = Integer .valueOf (valuesForGeneration .get (0 ));
365+ if (generations <= 0 ) {
366+ System .err .println ("Can't use a value <= 0 for generations (value used : " + generations + ")" );
367+ return ;
368+ }
369+ } else {
370+ generations = 1 ;
371+ }
372+ System .out .println ("Generations to generate: " + generations );
373+
374+ if (flags .flagExist ('W' )) {
375+ System .out .println ("Showing surviving mutants at the end of mutation score" );
376+ Core .showSurvivingMutants = true ;
377+ } else {
378+ Core .showSurvivingMutants = false ;
379+ }
353380
354381
355382 System .out .println ("Parameters validated\n \n " );
356383
357384 //================================Mutants generation==============================================//
358385 System .out .println ("Generating mutants...\n " );
359386 //List<Mutant> basicMutants = mi.listBasicOperators();
360- boolean result = core .generateMutants (classToMutate , methodsToMutate , ops .toArray (new Mutant [ops .size ()]));
387+ boolean result = core .generateMutants (classToMutate , methodsToMutate , ops .toArray (new Mutant [ops .size ()]), generations );
361388 if (!result ) {
362- core .lastError ().printStackTrace ();
389+ core .lastError ().printStackTrace (System . err );
363390 } else {
364391 System .out .println (core .lastMutantsFolder ().toString ());
365392 }
366393 System .out .println ("\n Mutants generated\n \n " );
367394
368395 //==============================Mutation score====================================================//;
369- if (mutationScore && !core .lastMutantsFolder ().isEmpty ()) {
370- System .out .println ("Calculating mutation score\n " );
396+ if (mutationScore && core . lastMutantsFolder () != null && !core .lastMutantsFolder ().isEmpty ()) {
397+ System .out .println ("Calculating mutation score for generation (" + generations + ") \n " );
371398 MutationScore ms = MutationScore .newInstance (mutantsSourceDir , originalBinDir , testBinDir );
372399 core .setMutationScore (ms );
373400 float mutationScoreResult = core .calculateMutationScore (testClasses , classToMutate );
@@ -405,6 +432,8 @@ private static void fullHelp() {
405432 System .out .println ("-p | optional parameter | effect : disable mutations of the form a = b where a is of type Object and b is a primitive type expression" );
406433 System .out .println ("-w | optional parameter | effect : wrap mutations of the form a = b to a = new T(b), where a is of type Object and b is a primitive type expression" );
407434 System .out .println ("-r | optional parameter | effect : apply refined versions of PRVO to mutate arguments in statements containing only a method call" );
435+ System .out .println ("-g <generations> | optional parameter | effect : generate <generations> of mutants | e.g.: -g 2 will generate the first and second generations of mutants" );
436+ System .out .println ("-W | optional parameter | required : -S | effect : shows which mutants that compile and were not killed by any test" );
408437 }
409438
410439 private static void mutopsHelp () {
0 commit comments