NoPol { public NopolResult build() { if (this.testClasses == null) { this.testClasses = new TestClassesFinder().findIn(classpath, false); } this.localizer = this.createLocalizer(); nopolResult.setNbTests(this.testClasses.length); if (nopolContext.getOracle() == NopolContext.NopolOracle.SYMBOLIC) { try { SpoonedProject jpfSpoon = new SpoonedProject(this.sourceFiles, nopolContext); String mainClass = "nopol.repair.NopolTestRunner"; TestExecutorProcessor.createMainTestClass(jpfSpoon, mainClass); jpfSpoon.process(new AssertReplacer()); final File outputSourceFile = new File("src-gen"); final File outputCompiledFile = new File("target-gen"); jpfSpoon.dumpedToClassLoader(); jpfSpoon.generateOutputFile(outputSourceFile); jpfSpoon.generateOutputCompiledFile(outputCompiledFile); } catch (IOException e) { throw new RuntimeException("Unable to write transformed test", e); } } Map<SourceLocation, List<TestResult>> testListPerStatement = this.localizer.getTestListPerStatement(); this.nopolResult.setNbStatements(testListPerStatement.keySet().size()); solveWithMultipleBuild(testListPerStatement); this.logResultInfo(this.nopolResult.getPatches()); this.nopolResult.setDurationInMilliseconds(System.currentTimeMillis()-this.startTime); NopolStatus status; if (nopolResult.getPatches().size() > 0) { status = NopolStatus.PATCH; } else { if (nopolResult.getNbAngelicValues() == 0) { status = NopolStatus.NO_ANGELIC_VALUE; } else { status = NopolStatus.NO_SYNTHESIS; } } nopolResult.setNopolStatus(status); return this.nopolResult; } NoPol(NopolContext nopolContext); NopolResult getNopolResult(); NopolResult build(); SpoonedProject getSpooner(); FaultLocalizer getLocalizer(); static Statement currentStatement; public long startTime; }
@Test public void testAPI() { NopolContext nopolContext = TestUtility.configForExample(executionType, 2); nopolContext.setType(RepairType.CONDITIONAL); SolverFactory.setSolver("z3", TestUtility.solverPath); NoPol nopol = new NoPol(nopolContext); NopolResult result = nopol.build(); assertEquals(1, result.getPatches().size()); assertEquals(1, result.getNbAngelicValues()); assertEquals("SourceLocation nopol_examples.nopol_example_2.NopolExample:11 ConditionalReplacer", result.getAngelicValues().get(0)); TestUtility.assertAgainstKnownPatches(result.getPatches().get(0), "a < b", "-1 < (b - a)", "2 <= (b - a)", "1 < (b - a)"); }
@Test public void testIgnoreTestCouldCreateOtherPatches() { NopolContext nopolContext = TestUtility.configForExample(executionType, 2); nopolContext.setType(RepairType.CONDITIONAL); List<String> testsToIgnore = new ArrayList<String>(); testsToIgnore.add("nopol_examples.nopol_example_2.NopolExampleTest#test2"); testsToIgnore.add("nopol_examples.nopol_example_2.NopolExampleTest#test4"); testsToIgnore.add("nopol_examples.nopol_example_2.NopolExampleTest#test5"); testsToIgnore.add("nopol_examples.nopol_example_2.NopolExampleTest#test7"); testsToIgnore.add("nopol_examples.nopol_example_2.NopolExampleTest#test9"); nopolContext.setTestMethodsToIgnore(testsToIgnore); NoPol nopol = new NoPol(nopolContext); SolverFactory.setSolver("z3", TestUtility.solverPath); nopol = new NoPol(nopolContext); NopolResult result2 = nopol.build(); assertEquals(1, result2.getPatches().size()); TestUtility.assertAgainstKnownPatches(result2.getPatches().get(0), "a == 2", "(b - a) == 2", "2 == (b - a)", "1 < (b - a)"); }
@Test public void testDynamoth() { NopolContext nopolContext = TestUtility.configForExample(executionType, 2); nopolContext.setType(RepairType.CONDITIONAL); nopolContext.setSynthesis(NopolContext.NopolSynthesis.DYNAMOTH); nopolContext.setOnlyOneSynthesisResult(false); NoPol nopol; nopol = new NoPol(nopolContext); assertEquals(10, nopol.build().getPatches().size()); }