|
17 | 17 | package org.jetbrains.kotlin.cli;
|
18 | 18 |
|
19 | 19 | import com.intellij.util.ArrayUtil;
|
20 |
| -import com.intellij.util.Function; |
21 |
| -import com.intellij.util.containers.ContainerUtil; |
22 | 20 | import kotlin.Pair;
|
| 21 | +import kotlin.collections.CollectionsKt; |
23 | 22 | import kotlin.io.FilesKt;
|
| 23 | +import kotlin.jvm.functions.Function1; |
24 | 24 | import kotlin.text.Charsets;
|
25 | 25 | import org.jetbrains.annotations.NotNull;
|
26 | 26 | import org.jetbrains.kotlin.cli.common.CLICompiler;
|
|
46 | 46 | import java.util.List;
|
47 | 47 |
|
48 | 48 | public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
49 |
| - static final String JS_TEST_DATA = "compiler/testData/cli/js"; |
50 |
| - static final String JVM_TEST_DATA = "compiler/testData/cli/jvm"; |
51 |
| - |
52 | 49 | @NotNull
|
53 | 50 | public static Pair<String, ExitCode> executeCompilerGrabOutput(@NotNull CLICompiler<?> compiler, @NotNull List<String> args) {
|
54 | 51 | ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
@@ -88,17 +85,16 @@ public static String getNormalizedCompilerOutput(
|
88 | 85 | return normalizedOutputWithoutExitCode + exitCode;
|
89 | 86 | }
|
90 | 87 |
|
91 |
| - private void executeCompilerCompareOutput(@NotNull CLICompiler<?> compiler, @NotNull String testDataDir) throws Exception { |
| 88 | + private void doTest(@NotNull String fileName, @NotNull CLICompiler<?> compiler) throws Exception { |
92 | 89 | System.setProperty("java.awt.headless", "true");
|
93 |
| - String testMethodName = getTestName(true); |
94 |
| - Pair<String, ExitCode> outputAndExitCode = |
95 |
| - executeCompilerGrabOutput(compiler, readArgs(testDataDir + "/" + testMethodName + ".args", testDataDir, |
96 |
| - tmpdir.getPath())); |
97 |
| - String actual = getNormalizedCompilerOutput(outputAndExitCode.getFirst(), outputAndExitCode.getSecond(), testDataDir); |
| 90 | + Pair<String, ExitCode> outputAndExitCode = executeCompilerGrabOutput(compiler, readArgs(fileName, tmpdir.getPath())); |
| 91 | + String actual = |
| 92 | + getNormalizedCompilerOutput(outputAndExitCode.getFirst(), outputAndExitCode.getSecond(), new File(fileName).getParent()); |
98 | 93 |
|
99 |
| - KotlinTestUtils.assertEqualsToFile(new File(testDataDir + "/" + testMethodName + ".out"), actual); |
| 94 | + File outFile = new File(fileName.replaceFirst("\\.args$", ".out")); |
| 95 | + KotlinTestUtils.assertEqualsToFile(outFile, actual); |
100 | 96 |
|
101 |
| - File additionalTestConfig = new File(testDataDir + "/" + testMethodName + ".test"); |
| 97 | + File additionalTestConfig = new File(fileName.replaceFirst("\\.args$", ".test")); |
102 | 98 | if (additionalTestConfig.exists()) {
|
103 | 99 | doTestAdditionalChecks(additionalTestConfig);
|
104 | 100 | }
|
@@ -134,37 +130,34 @@ else if (!file.isFile()) {
|
134 | 130 | }
|
135 | 131 |
|
136 | 132 | @NotNull
|
137 |
| - static List<String> readArgs( |
138 |
| - @NotNull String argsFilePath, |
139 |
| - @NotNull final String testDataDir, |
140 |
| - @NotNull final String tempDir |
141 |
| - ) throws IOException { |
| 133 | + static List<String> readArgs(@NotNull final String argsFilePath, @NotNull final String tempDir) throws IOException { |
142 | 134 | List<String> lines = FilesKt.readLines(new File(argsFilePath), Charsets.UTF_8);
|
143 | 135 |
|
144 |
| - return ContainerUtil.mapNotNull(lines, new Function<String, String>() { |
| 136 | + return CollectionsKt.mapNotNull(lines, new Function1<String, String>() { |
145 | 137 | @Override
|
146 |
| - public String fun(String arg) { |
| 138 | + public String invoke(String arg) { |
147 | 139 | if (arg.isEmpty()) {
|
148 | 140 | return null;
|
149 | 141 | }
|
150 |
| - // Do not replace : after \ (used in compiler plugin tests) |
| 142 | + |
| 143 | + // Do not replace ':' after '\' (used in compiler plugin tests) |
151 | 144 | String argsWithColonsReplaced = arg
|
152 | 145 | .replace("\\:", "$COLON$")
|
153 | 146 | .replace(":", File.pathSeparator)
|
154 | 147 | .replace("$COLON$", ":");
|
155 | 148 |
|
156 | 149 | return argsWithColonsReplaced
|
157 | 150 | .replace("$TEMP_DIR$", tempDir)
|
158 |
| - .replace("$TESTDATA_DIR$", testDataDir); |
| 151 | + .replace("$TESTDATA_DIR$", new File(argsFilePath).getParent()); |
159 | 152 | }
|
160 | 153 | });
|
161 | 154 | }
|
162 | 155 |
|
163 |
| - protected void executeCompilerCompareOutputJVM() throws Exception { |
164 |
| - executeCompilerCompareOutput(new K2JVMCompiler(), JVM_TEST_DATA); |
| 156 | + protected void doJvmTest(@NotNull String fileName) throws Exception { |
| 157 | + doTest(fileName, new K2JVMCompiler()); |
165 | 158 | }
|
166 | 159 |
|
167 |
| - protected void executeCompilerCompareOutputJS() throws Exception { |
168 |
| - executeCompilerCompareOutput(new K2JSCompiler(), JS_TEST_DATA); |
| 160 | + protected void doJsTest(@NotNull String fileName) throws Exception { |
| 161 | + doTest(fileName, new K2JSCompiler()); |
169 | 162 | }
|
170 | 163 | }
|
0 commit comments