Hi,
I'm able to get the PIT command line working if I supply the tests and class I want to mutate via a directory in the classpath, but if I put them in a jar and include that in the classpath, it stops finding the tests.
I've created a minimal reproduction:
.
├── lib
│ └── calc.jar
├── src
│ ├── Calculator.class
│ ├── Calculator.java
│ ├── CalculatorTest.class
│ └── CalculatorTest.java
└── third-party
├── hamcrest-core-1.3.jar
├── junit-4.12.jar
├── pitest-1.4.9.jar
├── pitest-command-line-1.4.9.jar
└── pitest-entry-1.4.9.jar
Calculator.java (via junit tutorial):
public class Calculator {
public int evaluate(String expression) {
int sum = 0;
for (String summand: expression.split("\\+"))
sum += Integer.valueOf(summand);
return sum;
}
}
CalculatorTest.java:
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class CalculatorTest {
@Test
public void evaluatesExpression() {
Calculator calculator = new Calculator();
int sum = calculator.evaluate("1+2+3");
assertEquals(6, sum);
}
}
Then running with src included in the class path works:
$ java -cp src:third-party/hamcrest-core-1.3.jar:third-party/junit-4.12.jar:third-party/pitest-1.4.9.jar:third-party/pitest-command-line-1.4.9.jar:third-party/pitest-entry-1.4.9.jar \
org.pitest.mutationtest.commandline.MutationCoverageReport \
--reportDir reports \
--targetClasses 'Calculator' \
--sourceDirs src \
--targetTests '*'
1:11:49 AM PIT >> INFO : Verbose logging is disabled. If you encounter a problem, please enable it before reporting an issue.
1:11:50 AM PIT >> INFO : Sending 2 test classes to minion
1:11:50 AM PIT >> INFO : Sent tests to minion
1:11:50 AM PIT >> INFO : MINION : 1:11:50 AM PIT >> INFO : Checking environment
1:11:50 AM PIT >> INFO : MINION : 1:11:50 AM PIT >> INFO : Found 1 tests
1:11:50 AM PIT >> INFO : MINION : 1:11:50 AM PIT >> INFO : Dependency analysis reduced number of potential tests by 0
1:11:50 AM PIT >> INFO : MINION : 1:11:50 AM PIT >> INFO : 1 tests received
# snip
>> Generated 2 mutations Killed 2 (100%)
>> Ran 2 tests (1 tests per mutation)
But then if I put the Calculator classes in a jar (lib/calc.jar, produced by jar --create --file lib/calc.jar src/Calculator.class src/CalculatorTest.class), PIT stops recognizing the tests:
$ java -cp lib/calc.jar:third-party/hamcrest-core-1.3.jar:third-party/junit-4.12.jar:third-party/pitest-1.4.9.jar:third-party/pitest-command-line-1.4.9.jar:third-party/pitest-entry-1.4.9.jar \
org.pitest.mutationtest.commandline.MutationCoverageReport \
--reportDir reports \
--targetClasses 'Calculator' \
--sourceDirs src \
--targetTests '*'
1:27:03 AM PIT >> INFO : Verbose logging is disabled. If you encounter a problem, please enable it before reporting an issue.
1:27:04 AM PIT >> INFO : Sending 0 test classes to minion
1:27:04 AM PIT >> INFO : Sent tests to minion
1:27:04 AM PIT >> INFO : Calculated coverage in 0 seconds.
1:27:04 AM PIT >> INFO : Created 0 mutation test units
Exception in thread "main" org.pitest.help.PitHelpError: No mutations found. This probably means there is an issue with either the supplied classpath or filters.
at org.pitest.mutationtest.tooling.MutationCoverage.checkMutationsFound(MutationCoverage.java:287)
at org.pitest.mutationtest.tooling.MutationCoverage.runReport(MutationCoverage.java:140)
at org.pitest.mutationtest.tooling.EntryPoint.execute(EntryPoint.java:120)
at org.pitest.mutationtest.tooling.EntryPoint.execute(EntryPoint.java:50)
at org.pitest.mutationtest.commandline.MutationCoverageReport.runReport(MutationCoverageReport.java:87)
at org.pitest.mutationtest.commandline.MutationCoverageReport.main(MutationCoverageReport.java:45)
I've confirmed this behavior on AdoptOpenJDK 8 as well as OpenJDK 11.
Any thoughts on what's going wrong? Thanks!