diff --git a/nopol/src/main/java/fr/inria/lille/repair/nopol/synth/SMTNopolSynthesizer.java b/nopol/src/main/java/fr/inria/lille/repair/nopol/synth/SMTNopolSynthesizer.java index 0a2b7063..86fc456b 100644 --- a/nopol/src/main/java/fr/inria/lille/repair/nopol/synth/SMTNopolSynthesizer.java +++ b/nopol/src/main/java/fr/inria/lille/repair/nopol/synth/SMTNopolSynthesizer.java @@ -68,19 +68,23 @@ public List findAngelicValuesAndBuildPatch(URL[] classpath, List> data = instrumentedProgram.collectSpecifications(classpath, testClasses, failures); + int dataSize = data.size(); + if (dataSize == 0) { + LoggerFactory.getLogger(this.getClass()).info("No angelic value for {} ({}).", sourceLocation, type.toString()); + return Collections.EMPTY_LIST; + } + + nopolResult.incrementNbAngelicValues(sourceLocation, conditionalProcessor); + nbStatementsWithAngelicValue++; + // XXX FIXME TODO move this // there should be at least two sets of values, otherwise the patch would be "true" or "false" - int dataSize = data.size(); if (dataSize < 2) { LoggerFactory.getLogger(this.getClass()).info("Not enough specifications: {}. A trivial patch is \"true\" or \"false\", please write new tests specifying {}.", dataSize, sourceLocation); // we return so that we can start working on the next statement in the suspicious list return Collections.EMPTY_LIST; } - - nopolResult.incrementNbAngelicValues(sourceLocation, conditionalProcessor); - nbStatementsWithAngelicValue++; - //collects available constants Map constants = new HashMap<>(); DefaultConstantCollector constantCollector = new DefaultConstantCollector(constants); diff --git a/nopol/src/test/java/fr/inria/lille/repair/nopol/NopolTest.java b/nopol/src/test/java/fr/inria/lille/repair/nopol/NopolTest.java index cb34759a..a8fd20b4 100644 --- a/nopol/src/test/java/fr/inria/lille/repair/nopol/NopolTest.java +++ b/nopol/src/test/java/fr/inria/lille/repair/nopol/NopolTest.java @@ -286,4 +286,16 @@ public void testDynamoth() { assertEquals(10, nopol.build().getPatches().size()); } + @Test + public void testNbAngelicValuesWithNotEnoughSpecifications() { + NopolContext nopolContext = TestUtility.configForExample(executionType, 14); + nopolContext.setType(RepairType.CONDITIONAL); + SolverFactory.setSolver("z3", TestUtility.solverPath); + + NoPol nopol = new NoPol(nopolContext); + NopolResult result = nopol.build(); + + assertEquals(1, result.getNbAngelicValues()); + assertEquals(NopolStatus.NO_SYNTHESIS, result.getNopolStatus()); + } } diff --git a/test-projects/src/main/java/nopol_examples/nopol_example_14/NopolExample.java b/test-projects/src/main/java/nopol_examples/nopol_example_14/NopolExample.java new file mode 100644 index 00000000..61796055 --- /dev/null +++ b/test-projects/src/main/java/nopol_examples/nopol_example_14/NopolExample.java @@ -0,0 +1,16 @@ +package nopol_examples.nopol_example_14; + +public class NopolExample { + + /* + * Buggy implementation of the identity function. + */ + public int identity(int a){ + if (a == 1) { // With *only* the test a = 1, there are "Not enough specifications", + // yet this statement admits an angelic value. + return 0; + } + + return a; + } +} diff --git a/test-projects/src/test/java/nopol_examples/nopol_example_14/NopolExampleTest.java b/test-projects/src/test/java/nopol_examples/nopol_example_14/NopolExampleTest.java new file mode 100644 index 00000000..5269ae7d --- /dev/null +++ b/test-projects/src/test/java/nopol_examples/nopol_example_14/NopolExampleTest.java @@ -0,0 +1,15 @@ +package nopol_examples.nopol_example_14; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class NopolExampleTest { + + @Test + public void test1() { + NopolExample ex = new NopolExample(); + assertEquals(1, ex.identity(1)); + } + +}