Ensured exit status is set on failure
This commit is contained in:
parent
6faea5a8f4
commit
8a5b9c9431
2 changed files with 47 additions and 28 deletions
|
@ -18,10 +18,14 @@ package rife.bld.extension;
|
|||
|
||||
import rife.bld.BaseProject;
|
||||
import rife.bld.operations.AbstractProcessOperation;
|
||||
import rife.bld.operations.exceptions.ExitStatusException;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Mutation testing and coverage with <a href="https://pitest.org">PIT</a>.
|
||||
|
@ -34,17 +38,12 @@ public class PitestOperation extends AbstractProcessOperation<PitestOperation> {
|
|||
* False constant.
|
||||
*/
|
||||
protected static final String FALSE = "false";
|
||||
/**
|
||||
* Source directories command line option.
|
||||
*/
|
||||
protected static final String SOURCE_DIRS = "--sourceDirs";
|
||||
/**
|
||||
* True constant.
|
||||
*/
|
||||
protected static final String TRUE = "true";
|
||||
/**
|
||||
* The PIT options.
|
||||
*/
|
||||
private static final Logger LOGGER = Logger.getLogger(PitestOperation.class.getName());
|
||||
private static final String SOURCE_DIRS = "--sourceDirs";
|
||||
private final Map<String, String> options_ = new ConcurrentHashMap<>();
|
||||
private BaseProject project_;
|
||||
|
||||
|
@ -330,33 +329,45 @@ public class PitestOperation extends AbstractProcessOperation<PitestOperation> {
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws IOException, InterruptedException, ExitStatusException {
|
||||
if (project_ == null) {
|
||||
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
|
||||
LOGGER.severe("A project must be specified.");
|
||||
}
|
||||
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||
} else {
|
||||
super.execute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the {@link #execute} operation, constructs the command list
|
||||
* to use for building the process.
|
||||
*/
|
||||
@Override
|
||||
protected List<String> executeConstructProcessCommandList() {
|
||||
if (project_ == null) {
|
||||
throw new IllegalArgumentException("A project must be specified.");
|
||||
} else if (!options_.containsKey(SOURCE_DIRS)) {
|
||||
options_.put(SOURCE_DIRS, project_.srcDirectory().getPath());
|
||||
}
|
||||
|
||||
final List<String> args = new ArrayList<>();
|
||||
args.add(javaTool());
|
||||
|
||||
if (project_ != null) {
|
||||
args.add(javaTool());
|
||||
args.add("-cp");
|
||||
args.add(String.format("%s:%s:%s:%s", Path.of(project_.libTestDirectory().getPath(), "*"),
|
||||
Path.of(project_.libCompileDirectory().getPath(), "*"), project_.buildMainDirectory(),
|
||||
args.add(String.format("%s:%s:%s:%s", new File(project_.libTestDirectory(), "*"),
|
||||
new File(project_.libCompileDirectory(), "*"), project_.buildMainDirectory(),
|
||||
project_.buildTestDirectory()));
|
||||
args.add("org.pitest.mutationtest.commandline.MutationCoverageReport");
|
||||
|
||||
if (!options_.containsKey(SOURCE_DIRS)) {
|
||||
options_.put(SOURCE_DIRS, project_.srcDirectory().getPath());
|
||||
}
|
||||
|
||||
options_.forEach((k, v) -> {
|
||||
args.add(k);
|
||||
if (!v.isEmpty()) {
|
||||
args.add(v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.junit.jupiter.api.Test;
|
|||
import rife.bld.BaseProject;
|
||||
import rife.bld.Project;
|
||||
import rife.bld.WebProject;
|
||||
import rife.bld.operations.exceptions.ExitStatusException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
@ -29,7 +30,8 @@ import java.util.Set;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static rife.bld.extension.PitestOperation.*;
|
||||
import static rife.bld.extension.PitestOperation.FALSE;
|
||||
import static rife.bld.extension.PitestOperation.TRUE;
|
||||
|
||||
class PitestOperationTest {
|
||||
private static final String AS_LIST = "as list";
|
||||
|
@ -287,6 +289,12 @@ class PitestOperationTest {
|
|||
"--sourceDirs c:\\myProject\\src");
|
||||
}
|
||||
|
||||
@Test
|
||||
void executeNoProject() {
|
||||
var op = new PitestOperation();
|
||||
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void exportLineCoverage() {
|
||||
var op = new PitestOperation()
|
||||
|
@ -547,12 +555,12 @@ class PitestOperationTest {
|
|||
var op = new PitestOperation()
|
||||
.fromProject(new BaseProject())
|
||||
.sourceDirs(FOO, BAR);
|
||||
assertThat(op.options().get(SOURCE_DIRS)).isEqualTo(FOOBAR);
|
||||
assertThat(op.options().get("--sourceDirs")).isEqualTo(FOOBAR);
|
||||
|
||||
op = new PitestOperation()
|
||||
.fromProject(new Project())
|
||||
.sourceDirs(List.of(FOO, BAR));
|
||||
assertThat(op.options().get(SOURCE_DIRS)).as(AS_LIST).isEqualTo(FOOBAR);
|
||||
assertThat(op.options().get("--sourceDirs")).as(AS_LIST).isEqualTo(FOOBAR);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue