Skip to content

Move the JS java tests to be a proper java_test target. #15627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package com.semmle.js.extractor.test;

import com.google.devtools.build.runfiles.Runfiles;
import com.semmle.util.process.Env;
import java.io.FileInputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
Expand All @@ -18,4 +28,35 @@
RobustnessTests.class,
NumericSeparatorTests.class
})
public class AllTests {}
public class AllTests {

@BeforeClass
public static void setUp() throws Exception {
Runfiles.Preloaded runfiles = Runfiles.preload();
String nodePath = runfiles.unmapped().rlocation(System.getenv("NODE_BIN"));
String tsWrapperZip = runfiles.unmapped().rlocation(System.getenv("TS_WRAPPER_ZIP"));
Path tempDir = Files.createTempDirectory("ts-wrapper");
// extract the ts-wrapper.zip to tempDir:
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(tsWrapperZip))) {
ZipEntry entry = zis.getNextEntry();
while (entry != null) {
Path entryPath = tempDir.resolve(entry.getName());
if (entry.isDirectory()) {
Files.createDirectories(entryPath);
} else {
Files.copy(zis, entryPath);
}
entry = zis.getNextEntry();
}
}
Path tsWrapper = tempDir.resolve("javascript/tools/typescript-parser-wrapper/main.js");
if (!Files.exists(tsWrapper)) {
throw new RuntimeException("Could not find ts-wrapper at " + tsWrapper);
}
Map<String, String> envUpdate = new HashMap<>();
envUpdate.put("SEMMLE_TYPESCRIPT_NODE_RUNTIME", nodePath);
envUpdate.put("SEMMLE_TYPESCRIPT_PARSER_WRAPPER", tsWrapper.toString());

Env.systemEnv().pushEnvironmentContext(envUpdate);
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
java_test(
name = "test_jar",
srcs = glob(["**/*.java"]),
test_class = "com.semmle.js.extractor.test.AllTests",
deps = [
"//javascript/extractor",
"//javascript/extractor:deps",
"@//resources/lib/java/DO_NOT_DISTRIBUTE:junit",
],
)

# We need to unzip the typescript wrapper, and provide node on the path.
# Therefore, we're wrapping the java_test inside a sh_test.
sh_test(
name = "test",
size = "small",
srcs = ["run_tests.sh"],
args = [
"$(execpath @nodejs//:node_bin)",
"$(JAVABASE)/bin/java",
"$(rootpath //javascript/extractor/lib/typescript)",
"$(rootpath test_jar_deploy.jar)",
],
srcs = glob(["**/*.java"]),
data = [
":test_jar_deploy.jar",
"//javascript/extractor/lib/typescript",
"//javascript/extractor/parser-tests",
"//javascript/extractor/tests",
"@bazel_tools//tools/jdk:current_java_runtime",
"@nodejs//:node_bin",
],
toolchains = ["@bazel_tools//tools/jdk:current_java_runtime"],
test_class = "com.semmle.js.extractor.test.AllTests",
deps = [
"//javascript/extractor",
"//javascript/extractor:deps",
"@//resources/lib/java/DO_NOT_DISTRIBUTE:junit",
"@bazel_tools//tools/java/runfiles",
],
env = {
"NODE_BIN": "$(rlocationpath @nodejs//:node_bin)",
"TS_WRAPPER_ZIP": "$(rlocationpath //javascript/extractor/lib/typescript)",
},
)

This file was deleted.