|
1 | 1 | package com.semmle.js.extractor.test;
|
2 | 2 |
|
| 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; |
3 | 13 | import org.junit.runner.RunWith;
|
4 | 14 | import org.junit.runners.Suite;
|
5 | 15 | import org.junit.runners.Suite.SuiteClasses;
|
|
18 | 28 | RobustnessTests.class,
|
19 | 29 | NumericSeparatorTests.class
|
20 | 30 | })
|
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 | +} |
0 commit comments