Added tests
This commit is contained in:
parent
26c1f11e84
commit
541ed74d9f
7 changed files with 68 additions and 35 deletions
|
@ -8,6 +8,7 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
|
||||
import static rife.bld.dependencies.Repository.MAVEN_CENTRAL;
|
||||
import static rife.bld.dependencies.Repository.MAVEN_LOCAL;
|
||||
import static rife.bld.dependencies.Scope.test;
|
||||
|
||||
public class ExamplesBuild extends Project {
|
||||
|
@ -16,7 +17,7 @@ public class ExamplesBuild extends Project {
|
|||
name = "Examples";
|
||||
version = version(0, 1, 0);
|
||||
|
||||
repositories = List.of(MAVEN_CENTRAL);
|
||||
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL);
|
||||
|
||||
scope(test)
|
||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 9, 3)))
|
||||
|
@ -26,13 +27,6 @@ public class ExamplesBuild extends Project {
|
|||
public static void main(String[] args) {
|
||||
new ExamplesBuild().start(args);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void test() throws Exception {
|
||||
// super.test();
|
||||
// jacoco();
|
||||
// }
|
||||
|
||||
@BuildCommand(summary = "Generates Jacoco Reports")
|
||||
public void jacoco() throws IOException {
|
||||
new JacocoReportOperation()
|
||||
|
|
|
@ -53,8 +53,6 @@ public class JacocoReportOperationBuild extends Project {
|
|||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 0)))
|
||||
.include(dependency("org.assertj:assertj-joda-time:2.2.0"));
|
||||
|
||||
testOperation().mainClass("rife.bld.extension.JacocoReportOperationTest");
|
||||
|
||||
javadocOperation()
|
||||
.javadocOptions()
|
||||
.docLint(NO_MISSING)
|
||||
|
@ -62,7 +60,7 @@ public class JacocoReportOperationBuild extends Project {
|
|||
|
||||
publishOperation()
|
||||
.repository(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2"))
|
||||
// .repository(MAVEN_LOCAL)
|
||||
// .repository(MAVEN_LOCAL)
|
||||
.info()
|
||||
.groupId("com.uwyn.rife2")
|
||||
.artifactId("bld-jacoco-report")
|
||||
|
@ -84,7 +82,7 @@ public class JacocoReportOperationBuild extends Project {
|
|||
}
|
||||
|
||||
@BuildCommand(summary = "Runs PMD analysis")
|
||||
public void pmd() throws Exception {
|
||||
public void pmd() {
|
||||
new PmdOperation()
|
||||
.fromProject(this)
|
||||
.failOnViolation(true)
|
||||
|
|
|
@ -142,34 +142,38 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
|
|||
@Override
|
||||
public void execute() throws IOException {
|
||||
if ((project == null) && LOGGER.isLoggable(Level.SEVERE)) {
|
||||
LOGGER.severe("A project and version must be specified.");
|
||||
LOGGER.severe("A project must be specified.");
|
||||
} else {
|
||||
var buildJacocoReportsDir = Path.of(project.buildDirectory().getPath(), "reports", "jacoco", "test").toFile();
|
||||
var buildJacocoExecDir = Path.of(project.buildDirectory().getPath(), "jacoco").toFile();
|
||||
var buildJacocoExec = Path.of(buildJacocoExecDir.getPath(), "jacoco.exec").toFile();
|
||||
|
||||
if (execFiles.isEmpty()) {
|
||||
// project.testOperation().fromProject(project).javaOptions().javaAgent(
|
||||
// Path.of(project.libBldDirectory().getPath(), "org.jacoco.agent-"
|
||||
// + JaCoCo.VERSION.substring(0, JaCoCo.VERSION.lastIndexOf('.')) + "-runtime.jar").toFile(),
|
||||
// "destfile=" + Path.of(buildJacocoExecDir.getPath(), "jacoco.exec"));
|
||||
project.testOperation().fromProject(project).javaOptions().add("-javaagent:" +
|
||||
Path.of(project.libBldDirectory().getPath(), "org.jacoco.agent-"
|
||||
+ JaCoCo.VERSION.substring(0, JaCoCo.VERSION.lastIndexOf('.')) + "-runtime.jar")
|
||||
+ "=destfile=" + Path.of(buildJacocoExecDir.getPath(), "jacoco.exec"));
|
||||
try {
|
||||
project.testOperation().execute();
|
||||
} catch (InterruptedException | ExitStatusException e) {
|
||||
throw new IOException(e);
|
||||
project.testOperation().fromProject(project).javaOptions().add("-javaagent:" +
|
||||
Path.of(project.libBldDirectory().getPath(), "org.jacoco.agent-"
|
||||
+ JaCoCo.VERSION.substring(0, JaCoCo.VERSION.lastIndexOf('.')) + "-runtime.jar")
|
||||
+ "=destfile=" + Path.of(buildJacocoExecDir.getPath(), "jacoco.exec"));
|
||||
try {
|
||||
project.testOperation().execute();
|
||||
} catch (InterruptedException | ExitStatusException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
|
||||
if (buildJacocoExec.exists()) {
|
||||
execFiles.add(buildJacocoExec);
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceFiles.isEmpty()) {
|
||||
sourceFiles.add(project.srcDirectory());
|
||||
sourceFiles.add(project.srcTestDirectory());
|
||||
sourceFiles.add(project.srcMainJavaDirectory());
|
||||
}
|
||||
|
||||
if (classFiles.isEmpty()) {
|
||||
classFiles.add(project.buildMainDirectory());
|
||||
classFiles.add(project.buildTestDirectory());
|
||||
}
|
||||
|
||||
if (html == null) {
|
||||
|
@ -184,10 +188,6 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
|
|||
csv = new File(buildJacocoReportsDir, "jacocoTestReport.csv");
|
||||
}
|
||||
|
||||
if (execFiles.isEmpty() && (buildJacocoExec.exists())) {
|
||||
execFiles.add(buildJacocoExec);
|
||||
}
|
||||
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
buildJacocoReportsDir.mkdirs();
|
||||
|
||||
|
@ -267,7 +267,7 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the locations of the source files.
|
||||
* Sets the locations of the source files. (e.g., {@code src/main/java})
|
||||
**/
|
||||
public JacocoReportOperation sourceFiles(File... sourceFiles) {
|
||||
this.sourceFiles.addAll(Arrays.stream(sourceFiles).toList());
|
||||
|
|
|
@ -17,29 +17,64 @@
|
|||
package rife.bld.extension;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.bld.Project;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class JacocoReportOperationTest {
|
||||
final File csv;
|
||||
final File html;
|
||||
final Path tempDir;
|
||||
final File xml;
|
||||
|
||||
JacocoReportOperationTest() throws IOException {
|
||||
tempDir = Files.createTempDirectory("jacoco-test");
|
||||
csv = (new File(tempDir.toFile(), "jacoco.csv"));
|
||||
html = (new File(tempDir.toFile(), "html"));
|
||||
xml = (new File(tempDir.toFile(), "jacoco.xml"));
|
||||
}
|
||||
|
||||
static void deleteOnExit(File folder) {
|
||||
folder.deleteOnExit();
|
||||
for (var f : Objects.requireNonNull(folder.listFiles())) {
|
||||
if (f.isDirectory()) {
|
||||
deleteOnExit(f);
|
||||
} else {
|
||||
f.deleteOnExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void executeTest() throws IOException {
|
||||
newJacocoReportOperation().execute();
|
||||
|
||||
assertThat(csv).exists();
|
||||
assertThat(html).isDirectory();
|
||||
assertThat(xml).exists();
|
||||
try (var lines = Files.lines(xml.toPath())) {
|
||||
assertThat(lines.anyMatch(s ->
|
||||
s.contains("<counter type=\"INSTRUCTION\" missed=\"0\" covered=\"3\"/>"))).isTrue();
|
||||
}
|
||||
|
||||
// deleteOnExit(tempDir.toFile());
|
||||
}
|
||||
|
||||
JacocoReportOperation newJacocoReportOperation() {
|
||||
var o = new JacocoReportOperation();
|
||||
o.csv(new File(tempDir.toFile(), "jacoco.csv"));
|
||||
o.fromProject(new Project());
|
||||
o.csv(csv);
|
||||
o.html(html);
|
||||
o.xml(xml);
|
||||
o.classFiles(new File("src/test/resources/Examples.class"));
|
||||
o.sourceFiles(new File("examples/src/main/java"));
|
||||
o.execFiles(new File("src/test/resources/jacoco.exec"));
|
||||
return o;
|
||||
}
|
||||
|
||||
@Test
|
||||
void executeTest() {
|
||||
assertThat(true).isTrue(); // TODO
|
||||
}
|
||||
}
|
BIN
src/test/resources/Examples.class
Normal file
BIN
src/test/resources/Examples.class
Normal file
Binary file not shown.
BIN
src/test/resources/jacoco.exec
Normal file
BIN
src/test/resources/jacoco.exec
Normal file
Binary file not shown.
6
update-test-resource.sh
Executable file
6
update-test-resource.sh
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
rm -rf src/test/resources/*
|
||||
examples/bld co jacoco
|
||||
cp -f "examples/build/main/com/example/Examples.class" src/test/resources/
|
||||
cp -f "examples/build/jacoco/jacoco.exec" src/test/resources/
|
Loading…
Add table
Add a link
Reference in a new issue