Command-line tool for JS DCE
This commit is contained in:
@@ -25,8 +25,10 @@ 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;
|
||||
import org.jetbrains.kotlin.cli.js.dce.K2JSDce;
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
|
||||
import org.jetbrains.kotlin.config.KotlinCompilerVersion;
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion;
|
||||
@@ -48,12 +50,12 @@ import java.util.List;
|
||||
|
||||
public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
||||
@NotNull
|
||||
public static Pair<String, ExitCode> executeCompilerGrabOutput(@NotNull CLICompiler<?> compiler, @NotNull List<String> args) {
|
||||
public static Pair<String, ExitCode> executeCompilerGrabOutput(@NotNull CLITool<?> compiler, @NotNull List<String> args) {
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
PrintStream origErr = System.err;
|
||||
try {
|
||||
System.setErr(new PrintStream(bytes));
|
||||
ExitCode exitCode = CLICompiler.doMainNoExit(compiler, ArrayUtil.toStringArray(args));
|
||||
ExitCode exitCode = CLITool.doMainNoExit(compiler, ArrayUtil.toStringArray(args));
|
||||
return new Pair<>(bytes.toString("utf-8"), exitCode);
|
||||
}
|
||||
catch (Exception e) {
|
||||
@@ -79,7 +81,7 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
||||
return normalizedOutputWithoutExitCode + exitCode;
|
||||
}
|
||||
|
||||
private void doTest(@NotNull String fileName, @NotNull CLICompiler<?> compiler) throws Exception {
|
||||
private void doTest(@NotNull String fileName, @NotNull CLITool<?> compiler) throws Exception {
|
||||
System.setProperty("java.awt.headless", "true");
|
||||
Pair<String, ExitCode> outputAndExitCode = executeCompilerGrabOutput(compiler, readArgs(fileName, tmpdir.getPath()));
|
||||
String actual = getNormalizedCompilerOutput(
|
||||
@@ -153,6 +155,10 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
||||
doTest(fileName, new K2JSCompiler());
|
||||
}
|
||||
|
||||
protected void doJsDceTest(@NotNull String fileName) throws Exception {
|
||||
doTest(fileName, new K2JSDce());
|
||||
}
|
||||
|
||||
public static String removePerfOutput(String output) {
|
||||
String[] lines = StringUtil.splitByLinesKeepSeparators(output);
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
@@ -539,4 +539,67 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
doJsTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/cli/js-dce")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Js_dce extends AbstractCliTest {
|
||||
public void testAllFilesPresentInJs_dce() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/cli/js-dce"), Pattern.compile("^(.+)\\.args$"), TargetBackend.ANY, false);
|
||||
}
|
||||
|
||||
@TestMetadata("dceHelp.args")
|
||||
public void testDceHelp() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/dceHelp.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("emptySources.args")
|
||||
public void testEmptySources() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/emptySources.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jsExtraHelp.args")
|
||||
public void testJsExtraHelp() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/jsExtraHelp.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nonExistingSourcePath.args")
|
||||
public void testNonExistingSourcePath() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/nonExistingSourcePath.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("notFile.args")
|
||||
public void testNotFile() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/notFile.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("outputIsDirectory.args")
|
||||
public void testOutputIsDirectory() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/outputIsDirectory.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("overrideOutputName.args")
|
||||
public void testOverrideOutputName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/overrideOutputName.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("printReachability.args")
|
||||
public void testPrintReachability() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/printReachability.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.args")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/simple.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user