Skip to content

Commit

Permalink
use toolchain to get javap executable path for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Jun 21, 2024
1 parent 27980cf commit 232dff6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ val filtered = tasks.register<FilterTestClasspath>("filteredTestClasspath") {
new.from(testDataNewTargets.output)
}

val javapPath = javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
}.map { it.metadata.installationPath.asFile.toPath().resolve("bin/javap") }

tasks.withType<Test> {
environment("JAVAP_PATH", javapPath.get())
}

dependencies {
testImplementation(files(filtered.flatMap { it.outputDir }))
testImplementation(testDataNewTargets.output)
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/io/papermc/asm/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand All @@ -33,6 +34,7 @@
public final class TestUtil {
private TestUtil() {
}
private static final String JAVAP_PATH = Objects.requireNonNullElse(System.getenv("JAVAP_PATH"), "javap");// fallback to hoping its on actual PATH

public static RewriteRuleVisitorFactory testingVisitorFactory(final RewriteRule rewriteRule) {
return RewriteRuleVisitorFactory.create(Opcodes.ASM9, rewriteRule, ClassInfoProvider.basic());
Expand Down Expand Up @@ -132,9 +134,9 @@ private static <T extends Throwable> void assertProcessedMatchesExpected_(
return;
} else {
// Try to get a javap diff
// final boolean proceed = checkJavapDiff(name, expected.get(name), processed.get(name), Arrays.asList("javap", "-c", "-p"));
// final boolean proceed = checkJavapDiff(name, expected.get(name), processed.get(name), Arrays.asList(JAVAP_PATH, "-c", "-p"));
// verbose is too useful for invokedynamic debugging to omit
checkJavapDiff(name, expected.get(name), processed.get(name), Arrays.asList("javap", "-c", "-p", "-v"));
checkJavapDiff(name, expected.get(name), processed.get(name), Arrays.asList(JAVAP_PATH, "-c", "-p", "-v"));

// If javap failed, just assert the bytes equal
assertArrayEquals(
Expand Down

0 comments on commit 232dff6

Please sign in to comment.