Skip to content

Commit

Permalink
Fix code for Windows builds
Browse files Browse the repository at this point in the history
  • Loading branch information
big-andy-coates committed Nov 22, 2023
1 parent 5956f18 commit b6cb6c0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.creekservice.api.test.util.coverage;

import java.io.File;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.nio.file.Path;
Expand Down Expand Up @@ -69,10 +68,10 @@ static Optional<String> codeCoverageCmdLineArg(
found.map(
arg ->
arg.replaceAll(
"([:=])build[/\\\\]",
"([:=])build([/\\\\])",
"$1"
+ dir.toAbsolutePath()
+ File.separator)))
+ "$2")))
.orElse(found);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@
@ExtendWith(MockitoExtension.class)
class CodeCoverageTest {

private static final Path BUILD_DIR = Paths.get("some/path/build/");
private static final Path BUILD_DIR = Paths.get("some", "path", "build");
private static final Path ROOT;

static {
Path path = Paths.get("");
while (path.getParent() != null) {
path = path.getParent();
}
ROOT = path;
}

@Mock private RuntimeMXBean runtimeMXBean;

@Test
Expand Down Expand Up @@ -88,7 +98,11 @@ void shouldReturnJaCoCoAgentParamWithAbsolutePaths() {
// Given:
when(runtimeMXBean.getInputArguments())
.thenReturn(
List.of("-javaagent:build/jacocoagent.jar:destfile=build/tmp/something"));
List.of(
"-javaagent:"
+ Paths.get("build", "jacocoagent.jar")
+ ":destfile="
+ Paths.get("build", "tmp", "something")));

// When:
final Optional<String> result =
Expand All @@ -101,10 +115,9 @@ void shouldReturnJaCoCoAgentParamWithAbsolutePaths() {
is(
Optional.of(
"-javaagent:"
+ abs
+ "/jacocoagent.jar:destfile="
+ abs
+ "/tmp/something")));
+ abs.resolve("jacocoagent.jar")
+ ":destfile="
+ abs.resolve(Paths.get("tmp", "something")))));
}

@Test
Expand All @@ -129,10 +142,16 @@ void shouldWorkWithGradle7() {
when(runtimeMXBean.getInputArguments())
.thenReturn(
List.of(
"-javaagent:build/tmp/expandedArchives/org.jacoco.agent-0.8.8.jar"
+ "_a33b649e552c51298e5a242c2f0d0e3c/jacocoagent.jar="
+ "destfile=build/jacoco/test.exec,"
+ "append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false"));
"-javaagent:"
+ Paths.get(
"build",
"tmp",
"expandedArchives",
"org.jacoco.agent-0.8.8.jar_a33b649e552c51298e5a242c2f0d0e3c",
"jacocoagent.jar=")
+ "destfile="
+ Paths.get("build", "jacoco", "test.exec")
+ ",append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false"));

// When:
final Optional<String> result =
Expand All @@ -145,24 +164,46 @@ void shouldWorkWithGradle7() {
is(
Optional.of(
"-javaagent:"
+ abs
+ "/tmp/expandedArchives/org.jacoco.agent-0.8.8.jar_a33b649e552c51298e5a242c2f0d0e3c/jacocoagent.jar="
+ "destfile="
+ abs
+ "/jacoco/test.exec,"
+ "append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false")));
+ abs.resolve(
Paths.get(
"tmp",
"expandedArchives",
"org.jacoco.agent-0.8.8.jar_a33b649e552c51298e5a242c2f0d0e3c",
"jacocoagent.jar"))
+ "=destfile="
+ abs.resolve(Paths.get("jacoco", "test.exec"))
+ ",append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false")));
}

@Test
void shouldWorkWithGradle8() {
// Given:
final Path agentAbs =
ROOT.resolve(
Paths.get(
"home",
"runner",
"work",
"creek-system-test",
"executor",
"build",
"tmp",
".cache",
"expanded",
"zip_a33b649e552c51298e5a242c2f0d0e3c",
"jacocoagent.jar"));

when(runtimeMXBean.getInputArguments())
.thenReturn(
List.of(
"-javaagent:/home/runner/work/creek-system-test/executor/build/tmp/"
+ ".cache/expanded/zip_a33b649e552c51298e5a242c2f0d0e3c/jacocoagent.jar="
+ "destfile=build/jacoco/test.exec,"
+ "append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false"));
"-javaagent:"
+ agentAbs
+ "=destfile="
+ Paths.get(
"build",
"jacoco",
"test.exec"
+ ",append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false")));

// When:
final Optional<String> result =
Expand All @@ -174,11 +215,10 @@ void shouldWorkWithGradle8() {
result,
is(
Optional.of(
"-javaagent:/home/runner/work/creek-system-test/executor/build/tmp/"
+ ".cache/expanded/zip_a33b649e552c51298e5a242c2f0d0e3c/jacocoagent.jar="
+ "destfile="
+ abs
+ "/jacoco/test.exec,"
+ "append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false")));
"-javaagent:"
+ agentAbs
+ "=destfile="
+ abs.resolve(Paths.get("jacoco", "test.exec"))
+ ",append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false")));
}
}

0 comments on commit b6cb6c0

Please sign in to comment.