Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote all classpath entries to handle spaces #1387

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(" ", "\" \""));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder, if it can affect the Gradle plugin, in the way how it already passes the classpath entries 🤔

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has just occurred to me that this change would cause a problem if gradle were already quoting the the spaces. Otherwise, this should have no impact.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?


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