Skip to content

Commit 4e022e2

Browse files
authored
Merge pull request #15627 from github/criemen/java-test
Move the JS java tests to be a proper `java_test` target.
2 parents 037e64a + 798a1e2 commit 4e022e2

File tree

3 files changed

+54
-56
lines changed

3 files changed

+54
-56
lines changed

javascript/extractor/test/com/semmle/js/extractor/test/AllTests.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
package com.semmle.js.extractor.test;
22

3+
import com.google.devtools.build.runfiles.Runfiles;
4+
import com.semmle.util.process.Env;
5+
import java.io.FileInputStream;
6+
import java.nio.file.Files;
7+
import java.nio.file.Path;
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
import java.util.zip.ZipEntry;
11+
import java.util.zip.ZipInputStream;
12+
import org.junit.BeforeClass;
313
import org.junit.runner.RunWith;
414
import org.junit.runners.Suite;
515
import org.junit.runners.Suite.SuiteClasses;
@@ -18,4 +28,35 @@
1828
RobustnessTests.class,
1929
NumericSeparatorTests.class
2030
})
21-
public class AllTests {}
31+
public class AllTests {
32+
33+
@BeforeClass
34+
public static void setUp() throws Exception {
35+
Runfiles.Preloaded runfiles = Runfiles.preload();
36+
String nodePath = runfiles.unmapped().rlocation(System.getenv("NODE_BIN"));
37+
String tsWrapperZip = runfiles.unmapped().rlocation(System.getenv("TS_WRAPPER_ZIP"));
38+
Path tempDir = Files.createTempDirectory("ts-wrapper");
39+
// extract the ts-wrapper.zip to tempDir:
40+
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(tsWrapperZip))) {
41+
ZipEntry entry = zis.getNextEntry();
42+
while (entry != null) {
43+
Path entryPath = tempDir.resolve(entry.getName());
44+
if (entry.isDirectory()) {
45+
Files.createDirectories(entryPath);
46+
} else {
47+
Files.copy(zis, entryPath);
48+
}
49+
entry = zis.getNextEntry();
50+
}
51+
}
52+
Path tsWrapper = tempDir.resolve("javascript/tools/typescript-parser-wrapper/main.js");
53+
if (!Files.exists(tsWrapper)) {
54+
throw new RuntimeException("Could not find ts-wrapper at " + tsWrapper);
55+
}
56+
Map<String, String> envUpdate = new HashMap<>();
57+
envUpdate.put("SEMMLE_TYPESCRIPT_NODE_RUNTIME", nodePath);
58+
envUpdate.put("SEMMLE_TYPESCRIPT_PARSER_WRAPPER", tsWrapper.toString());
59+
60+
Env.systemEnv().pushEnvironmentContext(envUpdate);
61+
}
62+
}
Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,21 @@
11
java_test(
2-
name = "test_jar",
3-
srcs = glob(["**/*.java"]),
4-
test_class = "com.semmle.js.extractor.test.AllTests",
5-
deps = [
6-
"//javascript/extractor",
7-
"//javascript/extractor:deps",
8-
"@//resources/lib/java/DO_NOT_DISTRIBUTE:junit",
9-
],
10-
)
11-
12-
# We need to unzip the typescript wrapper, and provide node on the path.
13-
# Therefore, we're wrapping the java_test inside a sh_test.
14-
sh_test(
152
name = "test",
16-
size = "small",
17-
srcs = ["run_tests.sh"],
18-
args = [
19-
"$(execpath @nodejs//:node_bin)",
20-
"$(JAVABASE)/bin/java",
21-
"$(rootpath //javascript/extractor/lib/typescript)",
22-
"$(rootpath test_jar_deploy.jar)",
23-
],
3+
srcs = glob(["**/*.java"]),
244
data = [
25-
":test_jar_deploy.jar",
265
"//javascript/extractor/lib/typescript",
276
"//javascript/extractor/parser-tests",
287
"//javascript/extractor/tests",
29-
"@bazel_tools//tools/jdk:current_java_runtime",
308
"@nodejs//:node_bin",
319
],
32-
toolchains = ["@bazel_tools//tools/jdk:current_java_runtime"],
10+
test_class = "com.semmle.js.extractor.test.AllTests",
11+
deps = [
12+
"//javascript/extractor",
13+
"//javascript/extractor:deps",
14+
"@//resources/lib/java/DO_NOT_DISTRIBUTE:junit",
15+
"@bazel_tools//tools/java/runfiles",
16+
],
17+
env = {
18+
"NODE_BIN": "$(rlocationpath @nodejs//:node_bin)",
19+
"TS_WRAPPER_ZIP": "$(rlocationpath //javascript/extractor/lib/typescript)",
20+
},
3321
)

javascript/extractor/test/com/semmle/js/extractor/test/run_tests.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)