Skip to content

Commit

Permalink
ensure pitest and jdk cannot be instrumented
Browse files Browse the repository at this point in the history
These checks would only come into play if the user set an over wide
target glob, but were previously broken.
  • Loading branch information
Henry Coles committed Jun 16, 2022
1 parent 0bdeb66 commit 90859f0
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 142 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.systemtest;

import java.util.ArrayList;
import java.util.List;

public class EatsMemoryWhenMutated {
public static int loop() throws InterruptedException {
int i = 1;
final List<String[]> vals = new ArrayList<>();
Thread.sleep(1500);
do {
i++;
vals.add(new String[9999999]);
vals.add(new String[9999999]);
vals.add(new String[9999999]);
vals.add(new String[9999999]);
} while (i < 1);
i++;
return i;
}
}
12 changes: 12 additions & 0 deletions pitest-entry/src/test/java/com/example/systemtest/FailingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.systemtest;

import org.pitest.simpletest.TestAnnotationForTesting;

import static org.junit.Assert.assertEquals;

public class FailingTest {
@TestAnnotationForTesting
public void fail() {
assertEquals(1, 2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.systemtest;

public class InfiniteLoop {
public static int loop() {
int i = 1;
do {
i++;
try {
Thread.sleep(1);
} catch (final InterruptedException e) {
e.printStackTrace();
}
} while (i < 1);
i++;
return i;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.systemtest;

public class NoMutations {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.systemtest;

import org.pitest.simpletest.TestAnnotationForTesting;

public class NoMutationsTest {
@TestAnnotationForTesting
public void pass() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.systemtest;

public class NoTests {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.systemtest;

import org.pitest.simpletest.TestAnnotationForTesting;

import static org.junit.Assert.assertEquals;

public class OneMutationFullTest {
@TestAnnotationForTesting
public void testReturnOne() {
assertEquals(1, OneMutationOnly.returnOne());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.systemtest;

import org.pitest.simpletest.TestAnnotationForTesting;

import static org.junit.Assert.assertEquals;

public class OneMutationFullTestWithSystemPropertyDependency {
@TestAnnotationForTesting
public void testReturnOne() {
if (System.getProperty("foo").equals("foo")) {
assertEquals(1, OneMutationOnly.returnOne());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.systemtest;

public class OneMutationOnly {
public static int returnOne() {
return 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.systemtest;

public class OneMutationTest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.systemtest;

public class ThreeMutations {
public static int returnOne() {
return 1;
}

public static int returnTwo() {
return 2;
}

public static int returnThree() {
return 3;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.systemtest;

import org.pitest.simpletest.TestAnnotationForTesting;

import static org.junit.Assert.assertEquals;

public class ThreeMutationsTwoMeaningfullTests {
@TestAnnotationForTesting
public void testReturnOne() {
assertEquals(1, ThreeMutations.returnOne());
}

@TestAnnotationForTesting
public void testReturnTwo() {
assertEquals(2, ThreeMutations.returnTwo());
}

@TestAnnotationForTesting
public void coverButDoNotTestReturnThree() {
ThreeMutations.returnThree();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void shouldRecordSomeCoverage() throws Exception {
// check all the specialised implementations broadly work
@Test
public void shouldCalculateCoverageForSingleBlockMethods()
throws IOException, InterruptedException, ExecutionException {
throws IOException, InterruptedException {
final List<CoverageResult> coveredClasses = runCoverageForTest(TestsForMultiBlockCoverage.class);
assertCoverage(coveredClasses, "test1", 1);
}
Expand All @@ -74,8 +74,7 @@ public void shouldCalculateCoverageFor3BlockMethods() throws Exception {
}

@Test
public void shouldCalculateCoverageForConstructors() throws IOException,
InterruptedException, ExecutionException {
public void shouldCalculateCoverageForConstructors() throws Exception {
final List<CoverageResult> coveredClasses = runCoverageForTest(TesteeWithComplexConstructorsTest.class);
assertTrue(coversBlock(coveredClasses, "testHigh", 0));
assertTrue(coversBlock(coveredClasses, "testHigh", 1));
Expand All @@ -88,22 +87,19 @@ public void shouldCalculateCoverageForConstructors() throws IOException,
}

@Test
public void shouldCalculateCoverageFor4BlockMethods() throws IOException,
InterruptedException, ExecutionException {
public void shouldCalculateCoverageFor4BlockMethods() throws Exception {
final List<CoverageResult> coveredClasses = runCoverageForTest(TestsForMultiBlockCoverage.class);
assertCoverage(coveredClasses, "test4", 2);
}

@Test
public void shouldCalculateCoverageFor5BlockMethods() throws IOException,
InterruptedException, ExecutionException {
public void shouldCalculateCoverageFor5BlockMethods() throws Exception {
final List<CoverageResult> coveredClasses = runCoverageForTest(TestsForMultiBlockCoverage.class);
assertCoverage(coveredClasses, "test5", 2);
}

@Test
public void shouldCalculateCoverageForBlockMethods() throws IOException,
InterruptedException, ExecutionException {
public void shouldCalculateCoverageForBlockMethods() throws Exception {
final List<CoverageResult> coveredClasses = runCoverageForTest(TestsForMultiBlockCoverage.class);
assertCoverage(coveredClasses, "test6", 2);
}
Expand Down Expand Up @@ -171,7 +167,7 @@ public void shouldCalculateCoverageForLargeBlockMethods() throws Exception {

@Test
public void shouldCalculateCoverageForAllRelevantClasses()
throws Exception{
throws Exception {

final List<CoverageResult> coveredClasses = runCoverageForTest(Tests.class);

Expand Down Expand Up @@ -215,7 +211,7 @@ public void shouldCalculateCoverageForMethodThatThrowsExceptionWithFinallyBlock(

@Test
public void shouldCalculateCoverageForLargeMethodThatThrowsException()
throws IOException, InterruptedException {
throws Exception {
final List<CoverageResult> coveredClasses = runCoverageForTest(TestThrowsExceptionFromLargeMethodTestee.class);

final ClassName clazz = ClassName
Expand Down
Loading

0 comments on commit 90859f0

Please sign in to comment.