Java Code Examples for fr.inria.lille.repair.common.config.NopolContext

The following examples show how to use fr.inria.lille.repair.common.config.NopolContext. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void AM1() {
    String projectName = "am1";
    RepairType repairType = RepairType.DOUBLE_LITERAL;
    NopolContext config = new NopolContext();
    config.setSolver(NopolContext.NopolSolver.Z3);
    config.setSolverPath("lib/z3/z3_for_linux");

    List<Patch> patches = setupAndRun(
            projectName,
repairType,
            new String[]{"org.apache.commons.math3.complex.QuaternionTest"}, config);

    assertEquals(patches.toString(), 1, patches.size());
    Patch patch = patches.get(0);
    assertEquals(patch.getType(), repairType);
    System.out.println(String.format("Patch for real bug %s: %s",
            projectName, patch.asString()));

    TestUtility.assertAgainstKnownPatches(patch, "start == seqEnd");

    String rootFolder = realBugPath + projectName + "/";
    String srcFolder = rootFolder + "src";
    clean(srcFolder); // TODO
}
 
Example 2
private void test(String projectName, boolean isMaven, String sourceFolder, Map<String, Object[]> oracle, SourceLocation location, String[] dependencies, NopolContext nopolContext, String... patch) {
    String realBugPath = "../../nopol-dataset/";
    String rootFolder = realBugPath + projectName + "/";
    String srcFolder = rootFolder + "src/";
    String binFolder = rootFolder + "bin/";
    if (isMaven) {
        binFolder = rootFolder + "target/classes:" + rootFolder + "target/test-classes";
    }
    String libFolder = rootFolder + "lib/";

    String classpath = binFolder + ":/home/thomas/.m2/repository/junit/junit/4.11/junit-4.11.jar:/home/thomas/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:";
    for (int i = 0; i < dependencies.length; i++) {
        classpath += libFolder + dependencies[i];
        if (i < dependencies.length - 1) {
            classpath += ":";
        }
    }
    File[] sourceFiles = { new File(srcFolder + sourceFolder) };
    URL[] classpathURL = JavaLibrary.classpathFrom(classpath);
    String[] tests = oracle.keySet().toArray(new String[0]);
    DynamothCodeGenesis synthesizer = new DynamothCodeGenesisImpl(sourceFiles,location, classpathURL, oracle, tests, nopolContext);
    Candidates expression = synthesizer.run(TimeUnit.MINUTES.toMillis(15));
    check(expression, patch);
}
 
Example 3
@Test
public void CM1() throws InterruptedException {
    Map<String, Object[]> oracle = new HashMap<>();
    oracle.put("org.apache.commons.math.stat.univariate.rank.PercentileTest#testHighPercentile", new Object[]{true});
    oracle.put("org.apache.commons.math.stat.univariate.rank.PercentileTest#testEvaluation", new Object[]{false});

    SourceLocation location = new SourceLocation("org.apache.commons.math.stat.univariate.rank.Percentile", 151);
    boolean isMaven = false;
    test("cm1",
            isMaven,
            "",
            oracle,
            location,
            new String[] {},
            new NopolContext(),
            "n <= pos",
            "n == pos");
}
 
Example 4
@Ignore
@Test
public void AM2() {
    String projectName = "am2";
    RepairType repairType = RepairType.DOUBLE_LITERAL;
    NopolContext config = new NopolContext();
    List<Patch> patches = setupAndRun(
            projectName,
repairType,
            new String[]{"org.apache.commons.math.optimization.direct.BOBYQAOptimizerTest"}, config);

    assertEquals(patches.toString(), 1, patches.size());
    Patch patch = patches.get(0);
    assertEquals(patch.getType(), repairType);
    System.out.println(String.format("Patch for real bug %s: %s",
            projectName, patch.asString()));

    TestUtility.assertAgainstKnownPatches(patch, "stopFitness;");

    String rootFolder = realBugPath + projectName + "/";
    String srcFolder = rootFolder + "src";
    clean(srcFolder); // TODO
}
 
Example 5
@Test
public void CM9() throws InterruptedException {
    Map<String, Object[]> oracle = new HashMap<>();
    oracle.put("org.apache.commons.math3.util.FastMathTest#testMath904_1", new Object[]{false, false});
    oracle.put("org.apache.commons.math3.util.FastMathTest#testMath904_2", new Object[]{false, false});

    SourceLocation location = new SourceLocation("org.apache.commons.math3.util.FastMath", 1543);
    boolean isMaven = true;
    test("cm9",
            isMaven,
            "main/java/",
            oracle,
            location,
            new String[] {},
            new NopolContext(),
            "y >= TWO_POWER_53 || y <= -TWO_POWER_53");
}
 
Example 6
@Test
public void CM10() {
    String projectName = "cm10";
    RepairType repairType = RepairType.PRECONDITION;
    NopolContext config = new NopolContext();
    List<Patch> patches = setupAndRun(
            projectName,
repairType,
            new String[]{"org.apache.commons.math3.stat.correlation.CovarianceTest"},
            config,
            "junit-4.10.jar");

    assertEquals(patches.toString(), 1, patches.size());
    Patch patch = patches.get(0);
    assertEquals(patch.getType(), repairType);
    System.out.println(String.format("Patch for real bug %s: %s",
            projectName, patch.asString()));

    TestUtility.assertAgainstKnownPatches(patch, "(nRows < 2)", "nRows < 2", "((org.apache.commons.math3.linear.AbstractRealMatrix)matrix).isSquare()", "(1) != (nCols)");

    String rootFolder = realBugPath + projectName + "/";
    String srcFolder = rootFolder + "src";
    clean(srcFolder); // TODO
}
 
Example 7
@Test
public void test8() throws InterruptedException {
    Map<String, Object[]> oracle = new HashMap<>();
    oracle.put("test_1", new Object[]{true});
    oracle.put("test_2", new Object[]{true});
    oracle.put("test_3", new Object[]{true});
    oracle.put("test_4", new Object[]{true});
    oracle.put("test_5", new Object[]{true});
    oracle.put("test_6", new Object[]{true});
    oracle.put("test_7", new Object[]{false});
    oracle.put("test_8", new Object[]{false});
    oracle.put("test_9", new Object[]{false});
    oracle.put("test_10", new Object[]{false});
    oracle.put("test_11", new Object[]{false});

    NopolContext nopolContext = TestUtility.configForExample("nopol",8);

    test(8, oracle, 12, new String[] {"(b * a) <= 100", "(a * b) <= 100", "a <= (100 / b)", "b <= (100 / a)"}, nopolContext);
}
 
Example 8
@Test
public void CM2() throws InterruptedException {
    Map<String, Object[]> oracle = new HashMap<>();
    oracle.put("org.apache.commons.math.util.MathUtilsTest#test0Choose0_3", new Object[]{false});
    oracle.put("org.apache.commons.math.util.MathUtilsTest#testBinomialCoefficient1", new Object[]{false});
    oracle.put("org.apache.commons.math.util.MathUtilsTest#testBinomialCoefficient2", new Object[]{false});
    oracle.put("org.apache.commons.math.util.MathUtilsTest#testBinomialCoefficient3", new Object[]{false});
    oracle.put("org.apache.commons.math.util.MathUtilsTest#testBinomialCoefficient6", new Object[]{false});
    oracle.put("org.apache.commons.math.util.MathUtilsTest#testBinomialCoefficient14_1", new Object[]{false});
    oracle.put("org.apache.commons.math.util.MathUtilsTest#testBinomialCoefficient69", new Object[]{true});

    SourceLocation location = new SourceLocation("org.apache.commons.math.util.MathUtils", 254);
    boolean isMaven = false;
    test("cm2",
            isMaven,
            "",
            oracle,
            location,
            new String[] {},
            new NopolContext(),
            "n < 0", "n < 0.0");
}
 
Example 9
Source Project: nopol   Source File: IfMetric.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        if (2 != args.length) {
            printUsage();
            return;
        }
        File sourceFolder = new File(args[0]);
        checkArgument(sourceFolder.exists(), "%s: does not exist.",
                sourceFolder);
        checkArgument(sourceFolder.isDirectory(), "%s: is not a directory.",
                sourceFolder);

        System.setProperty("java.class.path",
                System.getProperty("java.class.path") + File.pathSeparatorChar
                        + args[1]);
        String[] paths = args[1].split(Character
                .toString(File.pathSeparatorChar));

        URL[] classpath = IfMetric.createUrls(paths);

        new IfMetric(new NopolContext(new File[]{ sourceFolder }, classpath, null)).run();
    }
 
Example 10
@Test
public void PM2() {
    String projectName = "pm2";
    RepairType repairType = RepairType.PRECONDITION;
    NopolContext config = new NopolContext();
    List<Patch> patches = setupAndRun(
            projectName,
repairType,
            new String[]{"org.apache.commons.math.exception.util.MessageFactoryTest"},
            config,
            "junit-4.10.jar");

    assertEquals(patches.toString(), 1, patches.size());
    Patch patch = patches.get(0);
    assertEquals(patch.getType(), repairType);
    System.out.println(String.format("Patch for real bug %s: %s",
            projectName, patch.asString()));


    TestUtility.assertAgainstKnownPatches(patch, "specific!=null", "null != specific", "0 != ((java.lang.StringBuilder)sb).length()");

    String rootFolder = realBugPath + projectName + "/";
    String srcFolder = rootFolder + "src";
    clean(srcFolder); // TODO
}
 
Example 11
@Test
public void CM3() throws InterruptedException {
    Map<String, Object[]> oracle = new HashMap<>();
    oracle.put("org.apache.commons.math.util.MathUtilsTest#testFactorial", new Object[]{false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false});
    oracle.put("org.apache.commons.math.util.MathUtilsTest#testFactorialFail_1", new Object[]{true});
    oracle.put("org.apache.commons.math.util.MathUtilsTest#testFactorialFail_2", new Object[]{true});
    oracle.put("org.apache.commons.math.util.MathUtilsTest#testFactorialFail_3", new Object[]{true});
    oracle.put("org.apache.commons.math.util.MathUtilsTest#testFactorialFail_4", new Object[]{false});
    oracle.put("org.apache.commons.math.util.MathUtilsTest#testFactorialFail_5", new Object[]{false});

    SourceLocation location = new SourceLocation("org.apache.commons.math.util.MathUtils", 419);
    boolean isMaven = false;
    test("cm3",
            isMaven,
            "",
            oracle,
            location,
            new String[] {"commons-discovery-SNAPSHOT.jar",
                    "commons-logging-1.0.3.jar"},
            new NopolContext(),
            "n < 0", "n < 0.0");
}
 
Example 12
private DynamothCodeGenesis createSynthesizer(int nopolExampleNumber, Map<String, Object[]> o, int line, NopolContext nopolContext) {
    String executionType = "nopol";
    String pack = executionType + "_examples." + executionType + "_example_" + nopolExampleNumber;
    String className = pack + ".NopolExample";
    String testName = pack + ".NopolExampleTest";
    List<String> tests = new ArrayList<>();

    Map<String, Object[]> oracle = new HashMap<>();

    for (String next : o.keySet()) {
        oracle.put(testName + "#" + next, o.get(next));
        tests.add(testName + "#" + next);
    }

    nopolContext.setDataCollectionTimeoutInSecondForSynthesis(5);

    String classpath = "../test-projects/target/test-classes"+File.pathSeparatorChar+"../test-projects/target/classes/"+File.pathSeparatorChar+"lib/junit-4.11.jar";
    SourceLocation location = new SourceLocation(className, line);
    File[] files = new File []{new File("../test-projects/src/main/java/"), new File("../test-projects/src/test/java/")};

    DynamothCodeGenesis dynamothCodeGenesis = new DynamothCodeGenesisImpl(files, location, JavaLibrary.classpathFrom(classpath), oracle, tests.toArray(new String[0]),nopolContext);

    dynamothCodeGenesis.run(TimeUnit.MINUTES.toMillis(15));
    return dynamothCodeGenesis;
}
 
Example 13
@Test
public void PL3() throws InterruptedException {
    Map<String, Object[]> oracle = new HashMap<>();
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate3", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate4", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate5", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate6", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate7", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate8", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate9", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate10", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate11", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate12", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate13", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate14", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate15", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate16", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate17", new Object[]{true});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate18", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate19", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate20", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate21", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate22", new Object[]{false});
    oracle.put("org.apache.commons.lang.WordUtilsTest#testAbbreviate23", new Object[]{false});

    SourceLocation location = new SourceLocation("org.apache.commons.lang.WordUtils", 617);
    boolean isMaven = true;
    test("pl3",
            isMaven,
            "java/",
            oracle,
            location,
            new String[] {},
            new NopolContext(),
            "str.length() < lower",
            "((java.lang.String)str).length() < lower",
            "str.length() <= lower");
}
 
Example 14
Source Project: repairnator   Source File: NopolMojo.java    License: MIT License 5 votes vote down vote up
private NopolContext.NopolSolver resolveSolver() {
    try {
        return NopolContext.NopolSolver.valueOf(solver.toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new RuntimeException("Solver value \""+solver+"\" is wrong. Only following values are accepted: "+StringUtils.join(NopolContext.NopolSolver.values(),", "));
    }
}
 
Example 15
public DynamothSynthesisContext(Map<String, List<Candidates>> values, NopolContext nopolContext,
		Map<String, Object[]> oracle) {
	super();
	this.values = values;
	this.nopolContext = nopolContext;
	this.oracle = oracle;
}
 
Example 16
Source Project: nopol   Source File: TestSuiteExecutionTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void doNotUseSameTestNameTwice() {

	/* According to the name, we do not run twice the same test, i.e. test with same name */

	TestCasesListener listener = new TestCasesListener();
	TestSuiteExecution.runCasesIn(new String[]{ sampleTestClass(), sampleTestClass() }, classLoaderWithTestClass(), listener, new NopolContext());
	assertEquals(3, listener.allTests().size());
	assertEquals(2, listener.successfulTests().size());
	assertEquals(1, listener.failedTests().size());
}
 
Example 17
@Test
public void CL6() throws InterruptedException {
    Map<String, Object[]> oracle = new HashMap<>();
    oracle.put("org.apache.commons.lang3.StringUtilsIsTest#testIsAlpha0", new Object[]{true});
    oracle.put("org.apache.commons.lang3.StringUtilsIsTest#testIsAlpha1", new Object[]{true});
    oracle.put("org.apache.commons.lang3.StringUtilsIsTest#testIsAlpha2", new Object[]{false});
    oracle.put("org.apache.commons.lang3.StringUtilsIsTest#testIsAlpha3", new Object[]{false});
    oracle.put("org.apache.commons.lang3.StringUtilsIsTest#testIsAlpha4", new Object[]{false});
    oracle.put("org.apache.commons.lang3.StringUtilsIsTest#testIsAlpha5", new Object[]{false});
    oracle.put("org.apache.commons.lang3.StringUtilsIsTest#testIsAlpha6", new Object[]{false});
    oracle.put("org.apache.commons.lang3.StringUtilsIsTest#testIsAlpha7", new Object[]{false});
    oracle.put("org.apache.commons.lang3.StringUtilsIsTest#testIsAlpha8", new Object[]{false});
    oracle.put("org.apache.commons.lang3.StringUtilsIsTest#testIsAlpha9", new Object[]{false});
    oracle.put("org.apache.commons.lang3.StringUtilsIsTest#testIsAlpha10", new Object[]{false});

    SourceLocation location = new SourceLocation("org.apache.commons.lang3.StringUtils", 5217);
    boolean isMaven = true;
    test("cl6",
            isMaven,
            "main/java/",
            oracle,
            location,
            new String[] {},
            new NopolContext(),
            "(cs == null) || (cs.length() == 0)",
            "(cs == null) || (0 == cs.length())");
}
 
Example 18
@Test(timeout = FIFTEEN_MINUTES_TIMEOUT)
public void test_Math32() throws Exception {
	// On Travis 454sec
	// Sep 30: 2018 timeout on Travis with ten minutes (600 seconds), moving to 15 minutes
	if (!testShouldBeRun()) { return; }
	NopolContext nopolContext = nopolConfigFor("Math32");
	NopolResult result = new NoPol(nopolContext).build();
	assertEquals(1, result.getPatches().size());
}
 
Example 19
Source Project: nopol   Source File: NopolTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSkippingRegressionStepLeadToAPatch() {
	NopolContext nopolContext = TestUtility.configForExample(executionType, 1);
	nopolContext.setType(RepairType.CONDITIONAL);
	nopolContext.setSkipRegressionStep(true);
	SolverFactory.setSolver("z3", TestUtility.solverPath);
	URLClassLoader classLoader = new URLClassLoader(nopolContext.getProjectClasspath());
	TestSuiteExecution.runCasesIn(nopolContext.getProjectTests(), classLoader, new TestCasesListener(), nopolContext);
	List<Patch> patches = TestUtility.patchFor(executionType, nopolContext);
	assertTrue(patches.size() > 0);
}
 
Example 20
Source Project: nopol   Source File: ConfigPanel.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add to the Panel a Group of RadioButton for setting up Synthesis
 */
private void buildGroupSynthesis() {

	JRadioButton dynamothSynthesis = new JRadioButton();
	dynamothSynthesis.setSelected(nopolContext.getSynthesis() == NopolContext.NopolSynthesis.DYNAMOTH);
	dynamothSynthesis.setActionCommand(String.valueOf(NopolContext.NopolSynthesis.DYNAMOTH));
	dynamothSynthesis.addActionListener(event -> nopolContext.setSynthesis(NopolContext.NopolSynthesis.DYNAMOTH));

	JRadioButton smtSynthesis = new JRadioButton();
	smtSynthesis.setSelected(nopolContext.getSynthesis() == NopolContext.NopolSynthesis.SMT);
	smtSynthesis.setActionCommand(String.valueOf(NopolContext.NopolSynthesis.SMT));
	smtSynthesis.addActionListener(event -> nopolContext.setSynthesis(NopolContext.NopolSynthesis.SMT));

	ButtonGroup groupSynthesis = new ButtonGroup();
	groupSynthesis.add(smtSynthesis);
	groupSynthesis.add(dynamothSynthesis);

	JPanel panel = new JPanel();
	panel.setLayout(new GridLayout(3, 3));

	panel.add(new JLabel("Synthesis: "));
	panel.add(new JLabel(""));
	panel.add(new JLabel(""));

	panel.add(new JLabel("Dynamoth"));
	panel.add(new JLabel(""));
	panel.add(dynamothSynthesis);

	panel.add(new JLabel("SMT"));
	panel.add(new JLabel(""));
	panel.add(smtSynthesis);

	this.add(panel);
}
 
Example 21
Source Project: astor   Source File: StaSynthBuilder.java    License: GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public List synthesizer(List<CtExpression> singleExpressions, List<CtVariableRead> cteVarReadList) {
	NopolContext fakeContext = fakeContext();

	List<CtInvocation> invocations = this.createtinvocations(cteVarReadList, singleExpressions);

	List<CtExpression> notnull = createNotNullExpr(cteVarReadList);

	for (CtExpression notNullExpression : notnull) {
		// System.out.println("not null: " + notNullExpression);
	}

	singleExpressions.addAll(invocations);

	long maxCombinerTime = TimeUnit.SECONDS.toMillis(10);
	// Passing expression from Collection to Candidates...

	for (CtExpression expr : singleExpressions) {
		// System.out.println(expr + " type " + expr.getType());
	}
	System.out.println("Starting calculating expressions");
	List<CtExpression> allCombinedExpression = new ArrayList<>();
	DataCombinerSpoon combiner = new DataCombinerSpoon();

	combiner.addCombineListener(new DataCombinatorListenerSpoon(allCombinedExpression));

	combiner.combine(singleExpressions, maxCombinerTime, fakeContext);

	List<CtExpression> result = new ArrayList<>();

	System.out.println("Space: expressions: " + singleExpressions.size() + " not null " + notnull.size()
			+ " all combined " + allCombinedExpression.size());
	result.addAll(singleExpressions);
	result.addAll(notnull);
	result.addAll(allCombinedExpression);

	System.out.println("End calculating space " + result.size());
	return result;

}
 
Example 22
Source Project: nopol   Source File: GZoltarFaultLocalizer.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static GZoltarFaultLocalizer createInstance(NopolContext nopolContext) {
	try {
		return new GZoltarFaultLocalizer(nopolContext);
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
Example 23
Source Project: nopol   Source File: PatchGeneratorTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void conditionChangeElseIfTest() {
	NopolContext nopolContext = new NopolContext(projectSourcePath, null, null);

	Launcher spoon = new Launcher();
	spoon.addInputResource(projectSourcePath);
	spoon.buildModel();

	Factory factory = spoon.getFactory();
	SourceLocation pathLocation = new SourceLocation("fr.inria.lille.diff.testclasses.Bar", 12);
	pathLocation.setSourceStart(125);
	pathLocation.setSourceEnd(140);

	ExpressionPatch patch = new ExpressionPatch(
			new LiteralImpl(ValueFactory.create(false), nopolContext),
			pathLocation,
			RepairType.CONDITIONAL);
	PatchGenerator test = new PatchGenerator(
			patch,
			factory, nopolContext);

	Assert.assertEquals("--- a/"+projectSourcePath+"/Bar.java\n"
			+ "+++ b/"+projectSourcePath+"/Bar.java\n"
			+ "@@ -11,4 +11,4 @@\n"
			+ " \n"
			+ "-\t\t} else if (true) {\n"
			+ "-\n"
			+ "+\t\t} else if (false) {\n"
			+ "+\t\t\t\n"
			+ " \t\t}\n", test.getPatch());
}
 
Example 24
@Test(timeout = FIVE_MINUTES_TIMEOUT)
public void test_Lang44() throws Exception {
	if (!testShouldBeRun()) { return; }
	NopolContext nopolContext = nopolConfigFor("Lang44");
	nopolContext.setComplianceLevel(4);
	NopolResult result = new NoPol(nopolContext).build();
	assertEquals(1, result.getPatches().size());
}
 
Example 25
Source Project: nopol   Source File: PatchGeneratorTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void preconditionInvocationInElseTest() {
	NopolContext nopolContext = new NopolContext(projectSourcePath, null, null);

	Launcher spoon = new Launcher();
	spoon.addInputResource(projectSourcePath);
	spoon.buildModel();

	Factory factory = spoon.getFactory();
	SourceLocation pathLocation = new SourceLocation("fr.inria.lille.diff.testclasses.Bar", 34);
	pathLocation.setSourceStart(408);
	pathLocation.setSourceEnd(435);

	ExpressionPatch patch = new ExpressionPatch(
			new LiteralImpl(ValueFactory.create(false), nopolContext),
			pathLocation,
			RepairType.PRECONDITION);
	PatchGenerator test = new PatchGenerator(
			patch,
			factory, nopolContext);

	Assert.assertEquals("--- a/"+projectSourcePath+"/Bar.java\n"
			+ "+++ b/"+projectSourcePath+"/Bar.java\n"
			+ "@@ -33,3 +33,5 @@\n"
			+ " \t\t\tSystem.out.println(\"test1\");\n"
			+ "-\t\t\tSystem.out.println(\"test2\");\n"
			+ "+\t\t\tif (false) {\n"
			+ "+\t\t\t\tSystem.out.println(\"test2\");\n"
			+ "+\t\t\t}\n"
			+ " \t\t}\n", test.getPatch());
}
 
Example 26
@Test(timeout = FIVE_MINUTES_TIMEOUT)
public void test_Chart3() throws Exception {
	if (!testShouldBeRun()) { return; }
	NopolContext nopolContext = nopolConfigFor("Chart3", "");
	nopolContext.setLocalizer(NopolContext.NopolLocalizer.COCOSPOON);

	// we take only the failing test case
	nopolContext.setProjectTests(new String[]{"org.jfree.data.time.junit.TimeSeriesTests#testCreateCopy3"});

	NopolResult result = new NoPol(nopolContext).build();
	assertEquals(1, result.getPatches().size());
}
 
Example 27
@Test
public void PL4() {
    String projectName = "pl4";
    RepairType repairType = RepairType.PRECONDITION;
    NopolContext config = new NopolContext();
    List<Patch> patches = setupAndRun(
            projectName,
repairType,
            new String[]{"org.apache.commons.lang3.text.translate.NumericEntityUnescaperTest"},
            config,
            "junit-4.10.jar",
            "easymock-2.5.2.jar");

    assertEquals(patches.toString(), 1, patches.size());
    Patch patch = patches.get(0);
    assertEquals(patch.getType(), repairType);
    System.out.println(String.format("Patch for real bug %s: %s",
            projectName, patch.asString()));

    TestUtility.assertAgainstKnownPatches(patch, "(start)==(seqEnd)",
            "1 == (seqEnd / index)",
            "seqEnd == start",
            "start == seqEnd",
            "input.length() == start");

    String rootFolder = realBugPath + projectName + "/";
    String srcFolder = rootFolder + "src";
    clean(srcFolder); // TODO
}
 
Example 28
Source Project: nopol   Source File: DataCombiner.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Candidates combine(Candidates candidates, Object angelicValue, long maxTime, NopolContext nopolContext) {
    this.nopolContext = nopolContext;
    maxDepth = nopolContext.getSynthesisDepth();
    this.maxTime = maxTime;
    this.startTime = System.currentTimeMillis();
    executionTime = System.currentTimeMillis() - startTime;
    logger.debug("[combine] start on " + candidates.size() + " elements");
    Candidates result = new Candidates();
    result.addAll(candidates);
    List<Expression> lastTurn = new ArrayList<>();
    lastTurn.addAll(candidates);
    int previousSize = 0;
    executionTime = System.currentTimeMillis() - startTime;
    List<Operator> operators = new ArrayList<>();
    operators.addAll(Arrays.asList(UnaryOperator.values()));
    operators.addAll(Arrays.asList(BinaryOperator.values()));
    for (int i = 0; i < maxDepth - 1 && !stop && executionTime <= maxTime; i++) {
        lastTurn.addAll(newCombiner(lastTurn, operators, i == maxDepth - 2 ? angelicValue : null));

        /*lastTurn.addAll(combinePrimitives(lastTurn, previousSize, i == maxDepth - 2 ? angelicValue : null));
        if (stop) {
            return result;
        }
        lastTurn.addAll(combineComplex(lastTurn, previousSize, i == maxDepth - 2 ? angelicValue : null));
        previousSize = candidates.size();
        executionTime = System.currentTimeMillis() - startTime;*/
    }
    //result.addAll(lastTurn);
    logger.debug("[combine] end " + lastTurn.size() + " evaluated elements");
    return result;
}
 
Example 29
Source Project: nopol   Source File: Main.java    License: GNU General Public License v2.0 5 votes vote down vote up
private boolean parseArguments(String[] args) {
	JSAPResult jsapConfig = jsap.parse(args);
	if (!jsapConfig.success()) {
		System.err.println();
		for (Iterator<?> errs = jsapConfig.getErrorMessageIterator(); errs.hasNext(); ) {
			System.err.println("Error: " + errs.next());
		}
		showUsage();
		return false;
	}
	String[] sources = jsapConfig.getStringArray("source");
	final File[] sourceFiles = new File[sources.length];
	for (int i = 0; i < sources.length; i++) {
		String path = sources[i];
		File sourceFile = FileLibrary.openFrom(path);
		sourceFiles[i] = sourceFile;
	}

	final URL[] classpath = JavaLibrary.classpathFrom(jsapConfig.getString("classpath"));

	this.nopolContext = new NopolContext(sourceFiles, classpath, jsapConfig.getStringArray("test"));

	nopolContext.setType(strToStatementType(jsapConfig.getString("type")));
	nopolContext.setMode(strToMode(jsapConfig.getString("mode")));
	nopolContext.setSynthesis(strToSynthesis(jsapConfig.getString("synthesis")));
	nopolContext.setOracle(strToOracle(jsapConfig.getString("oracle")));
	nopolContext.setSolver(strToSolver(jsapConfig.getString("solver")));
	if (jsapConfig.getString("solverPath") != null) {
		nopolContext.setSolverPath(jsapConfig.getString("solverPath"));
		SolverFactory.setSolver(nopolContext.getSolver(), nopolContext.getSolverPath());
	}
	nopolContext.setComplianceLevel(jsapConfig.getInt("complianceLevel", nopolContext.getComplianceLevel())); 
	nopolContext.setMaxTimeInMinutes(jsapConfig.getInt("maxTime", nopolContext.getMaxTimeInMinutes()));
	nopolContext.setMaxTimeEachTypeOfFixInMinutes(jsapConfig.getLong("maxTimeType",nopolContext.getMaxTimeEachTypeOfFixInMinutes()));

	nopolContext.setLocalizer(strToLocalizer(jsapConfig.getString("faultLocalization")));
	nopolContext.setOutputFolder(jsapConfig.getString("outputFolder"));
	nopolContext.setJson(jsapConfig.getBoolean("outputJson", false));
	return true;
}
 
Example 30
Source Project: nopol   Source File: Main.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static NopolContext.NopolSynthesis strToSynthesis(String str) {
	if (str.equals("smt")) {
		return NopolContext.NopolSynthesis.SMT;
	} else if (str.equals("dynamoth")) {
		return NopolContext.NopolSynthesis.DYNAMOTH;
	}
	throw new RuntimeException("Unknow Nopol oracle " + str);
}