Skip to content

Commit

Permalink
quote all classpath entries to handle spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoles committed Feb 17, 2025
1 parent 0938a9e commit 0aad768
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
fail-fast: false
matrix:
include:
- title: "JDK 11"
java: 11
- title: "JDK 18"
java: "18"
# - title: "JDK 11"
# java: 11
# - title: "JDK 18"
# java: "18"
- title: "JDK 21"
java: "21"
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ trigger:

strategy:
matrix:
mac:
imageName: 'macos-latest'
# mac:
# imageName: 'macos-latest'
windows:
imageName: 'windows-latest'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ private List<String> createLaunchArgs(JavaAgent agentJarLocator, List<String> ar
List<String> cmd = new ArrayList<>();

cmd.add("-classpath");
cmd.add(classPath);

cmd.add(classPath.replace(" ", "\" \""));
addPITJavaAgent(agentJarLocator, cmd);

cmd.addAll(args);
Expand Down Expand Up @@ -154,4 +154,5 @@ private static Predicate<String> isJavaAgentParam() {
return a -> a.toLowerCase().startsWith("-javaagent");
}


}
13 changes: 13 additions & 0 deletions pitest-maven-verification/src/test/java/org/pitest/PitMojoIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ public void shouldProduceConsistantCoverageData() throws Exception {
assertEquals(firstRun, secondRun);
}

@Test
public void shouldHandleSpacesInProjectPath() throws Exception {
File testDir = prepare("/pit spaces in path");
verifier.executeGoal("test");
verifier.executeGoal("org.pitest:pitest-maven:mutationCoverage");

String firstRun = readCoverage(testDir);
verifier.executeGoal("org.pitest:pitest-maven:mutationCoverage");

String secondRun = readCoverage(testDir);
assertEquals(firstRun, secondRun);
}

@Test
public void shouldExcludeSpecifiedJUnitCategories() throws Exception {
File testDir = prepare("/pit-junit-categories");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>deterministic-coverage</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>deterministic-coverage</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>${pit.version}</version>
<configuration>
<exportLineCoverage>true</exportLineCoverage>
<features>+CLASSLIMIT(limit[1])</features>
<timestampedReports>false</timestampedReports>
<targetClasses><param>com.example*</param></targetClasses>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>


<properties>
<junit.version>4.13.1</junit.version>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example;

public class CoveredByMultipleThreads {

public int lotsOfLinesOfCode(int i) {
if ( i == 0 ) {
return 1;
}

if ( i == 2 ) {
return 42;
}

for ( int j = 0; j != 100; j++ ) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

return i;
}

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

import java.util.Arrays;
import java.util.Collection;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(value = Parameterized.class)
public class MultiThreadedTest {

private final int i;

@Parameters
public static Collection<Object[]> data() {
Object[][] data = new Object[][] { { 1 }, { 2 }, { 3 }, { 4 }, { 5 } ,{ 6 }, { 7 }, { 8 } };
return Arrays.asList(data);
}

public MultiThreadedTest(int i) {
this.i = i;
}

@Test
public void test() throws InterruptedException {
Thread t = new Thread(aTest());
t.start();
t.join();
}



private Runnable aTest() {
return new Runnable() {
public void run() {
CoveredByMultipleThreads testee = new CoveredByMultipleThreads();
testee.lotsOfLinesOfCode(i);
}

};
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;

import org.junit.Before;
import org.junit.Test;
Expand Down

0 comments on commit 0aad768

Please sign in to comment.