Generate relative paths in JS source maps

Also, add CLI options to manipulate prefixes of path

See KT-4078
This commit is contained in:
Alexey Andreev
2017-06-09 14:52:04 +03:00
parent 44d3b8fb1a
commit 13ab63ae09
39 changed files with 399 additions and 18 deletions
@@ -24,7 +24,6 @@ import kotlin.collections.CollectionsKt;
import kotlin.io.FilesKt;
import kotlin.text.Charsets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.cli.common.CLICompiler;
import org.jetbrains.kotlin.cli.common.CLITool;
import org.jetbrains.kotlin.cli.common.ExitCode;
import org.jetbrains.kotlin.cli.js.K2JSCompiler;
@@ -120,6 +119,26 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
}
}
List<String> containsTextList = InTextDirectivesUtils.findLinesWithPrefixesRemoved(content, "// CONTAINS: ");
for (String containsSpec : containsTextList) {
String[] parts = containsSpec.split(",", 2);
String fileName = parts[0].trim();
String contentToSearch = parts[1].trim();
File file = new File(tmpdir, fileName);
if (!file.exists()) {
diagnostics.add("File does not exist: " + fileName);
}
else if (file.isDirectory()) {
diagnostics.add("File is a directory: " + fileName);
}
else {
String text = FilesKt.readText(file, Charsets.UTF_8);
if (!text.contains(contentToSearch)) {
diagnostics.add("File " + fileName + " does not contain string: " + contentToSearch);
}
}
}
if (!diagnostics.isEmpty()) {
diagnostics.add(0, diagnostics.size() + " problem(s) found:");
Assert.fail(StringsKt.join(diagnostics, "\n"));
@@ -127,7 +146,7 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
}
@NotNull
static List<String> readArgs(@NotNull String argsFilePath, @NotNull String tempDir) throws IOException {
private static List<String> readArgs(@NotNull String argsFilePath, @NotNull String tempDir) throws IOException {
List<String> lines = FilesKt.readLines(new File(argsFilePath), Charsets.UTF_8);
return CollectionsKt.mapNotNull(lines, arg -> {
@@ -515,6 +515,42 @@ public class CliTestGenerated extends AbstractCliTest {
doJsTest(fileName);
}
@TestMetadata("sourceMap.args")
public void testSourceMap() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js/sourceMap.args");
doJsTest(fileName);
}
@TestMetadata("sourceMapPrefix.args")
public void testSourceMapPrefix() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js/sourceMapPrefix.args");
doJsTest(fileName);
}
@TestMetadata("sourceMapRootAuto.args")
public void testSourceMapRootAuto() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js/sourceMapRootAuto.args");
doJsTest(fileName);
}
@TestMetadata("sourceMapRootManual.args")
public void testSourceMapRootManual() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js/sourceMapRootManual.args");
doJsTest(fileName);
}
@TestMetadata("sourceMapRootMissing.args")
public void testSourceMapRootMissing() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js/sourceMapRootMissing.args");
doJsTest(fileName);
}
@TestMetadata("sourceMapRootMultiple.args")
public void testSourceMapRootMultiple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js/sourceMapRootMultiple.args");
doJsTest(fileName);
}
@TestMetadata("suppressAllWarningsJS.args")
public void testSuppressAllWarningsJS() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js/suppressAllWarningsJS.args");