Search in sources :

Example 6 with CheapPurityAnalyzer

use of org.evosuite.assertion.CheapPurityAnalyzer in project evosuite by EvoSuite.

the class ToStringInspectorSystemTest method testImpureToString.

@Test
public void testImpureToString() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ImpureToStringInspector.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.HadUnstableTests;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    double best_fitness = best.getFitness();
    Assert.assertTrue("Optimal coverage was not achieved ", best_fitness == 0.0);
    CheapPurityAnalyzer purityAnalyzer = CheapPurityAnalyzer.getInstance();
    String descriptor = Type.getMethodDescriptor(Type.getType(String.class));
    boolean toString = purityAnalyzer.isPure(targetClass, "toString", descriptor);
    assertFalse(toString);
    Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
    Assert.assertNotNull(map);
    OutputVariable unstable = map.get(RuntimeVariable.HadUnstableTests.toString());
    Assert.assertNotNull(unstable);
    Assert.assertEquals(Boolean.FALSE, unstable.getValue());
}
Also used : CheapPurityAnalyzer(org.evosuite.assertion.CheapPurityAnalyzer) EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Example 7 with CheapPurityAnalyzer

use of org.evosuite.assertion.CheapPurityAnalyzer in project evosuite by EvoSuite.

the class ImpureInspectorSystemTest method test.

@Test
public void test() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ImpureInspector.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.HadUnstableTests;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    double best_fitness = best.getFitness();
    Assert.assertTrue("Optimal coverage was not achieved ", best_fitness == 0.0);
    CheapPurityAnalyzer purityAnalyzer = CheapPurityAnalyzer.getInstance();
    String descriptor = Type.getMethodDescriptor(Type.INT_TYPE);
    boolean recursivePureFunction = purityAnalyzer.isPure(targetClass, "recursivePureFunction", Type.getMethodDescriptor(Type.INT_TYPE, Type.INT_TYPE));
    assertTrue(recursivePureFunction);
    boolean getImpureValue = purityAnalyzer.isPure(targetClass, "getImpureValue", descriptor);
    assertFalse(getImpureValue);
    boolean getPureValue = purityAnalyzer.isPure(targetClass, "getPureValue", descriptor);
    assertTrue(getPureValue);
    boolean getImpureValueFromCall = purityAnalyzer.isPure(targetClass, "getImpureValueFromCall", descriptor);
    assertFalse(getImpureValueFromCall);
    boolean getPureValueFromCall = purityAnalyzer.isPure(targetClass, "getPureValueFromCall", descriptor);
    assertTrue(getPureValueFromCall);
    boolean recursivePureInspector = purityAnalyzer.isPure(targetClass, "recursivePureInspector", descriptor);
    assertTrue(recursivePureInspector);
    boolean recursiveImpureInspector = purityAnalyzer.isPure(targetClass, "recursiveImpureInspector", descriptor);
    assertFalse(recursiveImpureInspector);
    Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
    Assert.assertNotNull(map);
    OutputVariable unstable = map.get(RuntimeVariable.HadUnstableTests.toString());
    Assert.assertNotNull(unstable);
    Assert.assertEquals(Boolean.FALSE, unstable.getValue());
}
Also used : CheapPurityAnalyzer(org.evosuite.assertion.CheapPurityAnalyzer) EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Example 8 with CheapPurityAnalyzer

use of org.evosuite.assertion.CheapPurityAnalyzer in project evosuite by EvoSuite.

the class JUnitOnSeparateProcessPropertySystemTest method test.

@Test
public void test() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = Foo.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.HadUnstableTests;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    double best_fitness = best.getFitness();
    Assert.assertTrue("Optimal coverage was not achieved ", best_fitness == 0.0);
    CheapPurityAnalyzer purityAnalyzer = CheapPurityAnalyzer.getInstance();
    String descriptor = Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Object.class));
    boolean equals = purityAnalyzer.isPure(targetClass, "equals", descriptor);
    assertFalse(equals);
    Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
    Assert.assertNotNull(map);
    OutputVariable unstable = map.get(RuntimeVariable.HadUnstableTests.toString());
    Assert.assertNotNull(unstable);
    Assert.assertEquals(Boolean.FALSE, unstable.getValue());
}
Also used : CheapPurityAnalyzer(org.evosuite.assertion.CheapPurityAnalyzer) EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Example 9 with CheapPurityAnalyzer

use of org.evosuite.assertion.CheapPurityAnalyzer in project evosuite by EvoSuite.

the class ToStringInspectorSystemTest method testPureToString.

@Test
public void testPureToString() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ToStringInspector.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.HadUnstableTests;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    double best_fitness = best.getFitness();
    Assert.assertTrue("Optimal coverage was not achieved ", best_fitness == 0.0);
    CheapPurityAnalyzer purityAnalyzer = CheapPurityAnalyzer.getInstance();
    String descriptor = Type.getMethodDescriptor(Type.getType(String.class));
    boolean toString = purityAnalyzer.isPure(targetClass, "toString", descriptor);
    assertFalse(toString);
    boolean abstractToString = purityAnalyzer.isPure(AbstractToStringInspector.class.getCanonicalName(), "toString", descriptor);
    assertFalse(abstractToString);
    Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
    Assert.assertNotNull(map);
    OutputVariable unstable = map.get(RuntimeVariable.HadUnstableTests.toString());
    Assert.assertNotNull(unstable);
    Assert.assertEquals(Boolean.FALSE, unstable.getValue());
}
Also used : CheapPurityAnalyzer(org.evosuite.assertion.CheapPurityAnalyzer) AbstractToStringInspector(com.examples.with.different.packagename.purity.AbstractToStringInspector) EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Example 10 with CheapPurityAnalyzer

use of org.evosuite.assertion.CheapPurityAnalyzer in project evosuite by EvoSuite.

the class JdkInspectorSystemTest method test.

@Test
public void test() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = JdkPureInspector.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.HadUnstableTests;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    double best_fitness = best.getFitness();
    Assert.assertTrue("Optimal coverage was not achieved ", best_fitness == 0.0);
    CheapPurityAnalyzer purityAnalyzer = CheapPurityAnalyzer.getInstance();
    String descriptor = Type.getMethodDescriptor(Type.BOOLEAN_TYPE);
    boolean equalsToZ = purityAnalyzer.isPure(targetClass, "equalsToZ", descriptor);
    assertTrue(equalsToZ);
    boolean isLowerCase = purityAnalyzer.isPure(targetClass, "isLowerCase", descriptor);
    assertTrue(isLowerCase);
    Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
    Assert.assertNotNull(map);
    OutputVariable unstable = map.get(RuntimeVariable.HadUnstableTests.toString());
    Assert.assertNotNull(unstable);
    Assert.assertEquals(Boolean.FALSE, unstable.getValue());
}
Also used : CheapPurityAnalyzer(org.evosuite.assertion.CheapPurityAnalyzer) EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Aggregations

CheapPurityAnalyzer (org.evosuite.assertion.CheapPurityAnalyzer)14 EvoSuite (org.evosuite.EvoSuite)13 OutputVariable (org.evosuite.statistics.OutputVariable)13 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)13 Test (org.junit.Test)13 AbstractInspector (com.examples.with.different.packagename.purity.AbstractInspector)1 AbstractToStringInspector (com.examples.with.different.packagename.purity.AbstractToStringInspector)1 PrintWriter (java.io.PrintWriter)1 CFGClassAdapter (org.evosuite.graphs.cfg.CFGClassAdapter)1 ErrorConditionClassAdapter (org.evosuite.instrumentation.error.ErrorConditionClassAdapter)1 BooleanTestabilityTransformation (org.evosuite.instrumentation.testability.BooleanTestabilityTransformation)1 ComparisonTransformation (org.evosuite.instrumentation.testability.ComparisonTransformation)1 ContainerTransformation (org.evosuite.instrumentation.testability.ContainerTransformation)1 StringTransformation (org.evosuite.instrumentation.testability.StringTransformation)1 ComputeClassWriter (org.evosuite.runtime.util.ComputeClassWriter)1 PrimitiveClassAdapter (org.evosuite.seeding.PrimitiveClassAdapter)1 ClassVisitor (org.objectweb.asm.ClassVisitor)1 ClassWriter (org.objectweb.asm.ClassWriter)1 SerialVersionUIDAdder (org.objectweb.asm.commons.SerialVersionUIDAdder)1 ClassNode (org.objectweb.asm.tree.ClassNode)1