Remove module integration-tests, merge into compiler-tests
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
<orderEntry type="module" module-name="serialization.java" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="module" module-name="builtins-serializer" />
|
||||
<orderEntry type="module" module-name="js.frontend" scope="TEST" />
|
||||
<orderEntry type="module" module-name="js.frontend" />
|
||||
<orderEntry type="module" module-name="js.tests" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.integration;
|
||||
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public abstract class AntTaskBaseTest extends KotlinIntegrationTestBase {
|
||||
protected static final File ANT_TASK_TEST_DATA_BASE_DIR = new File(INTEGRATION_TEST_DATA_BASE_DIR, "ant");
|
||||
|
||||
protected static final int SUCCESSFUL = 0;
|
||||
protected static final int FAILED = 1;
|
||||
|
||||
protected void doAntTest(int expectedExitCode, String... extraArgs) throws Exception {
|
||||
assertEquals("Compilation failed", expectedExitCode, runAnt("build.log", "build.xml", extraArgs));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String normalizeOutput(String content) {
|
||||
return super.normalizeOutput(content).replaceAll("Total time: .+\n", "Total time: [time]\n");
|
||||
}
|
||||
|
||||
private int runAnt(String logName, String scriptName, String... extraArgs) throws Exception {
|
||||
String[] basicArgs = {
|
||||
"-jar", getAntHome() + File.separator + "lib" + File.separator + "ant-launcher.jar",
|
||||
"-Dkotlin.lib=" + getCompilerLib(),
|
||||
"-Dtest.data=" + getTestDataDir(),
|
||||
"-Dtemp=" + tmpdir.getTmpDir(),
|
||||
"-f", scriptName
|
||||
};
|
||||
List<String> strings = new ArrayList<String>();
|
||||
strings.addAll(Arrays.asList(basicArgs));
|
||||
strings.addAll(Arrays.asList(extraArgs));
|
||||
return runJava(logName, ArrayUtil.toStringArray(strings));
|
||||
}
|
||||
|
||||
private static String getAntHome() {
|
||||
return getKotlinProjectHome().getAbsolutePath() + File.separator + "dependencies" + File.separator + "ant-1.8";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected File getOutputFileByName(@NotNull String name) {
|
||||
return new File(tmpdir.getTmpDir(), name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.integration;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoFunctionResultChecker;
|
||||
import org.jetbrains.k2js.test.rhino.RhinoUtils;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class AntTaskJsTest extends AntTaskBaseTest {
|
||||
private static final String JS_OUT_FILE = "out.js";
|
||||
|
||||
@Rule
|
||||
public final TestName name = new TestName();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected File getTestDataDir() {
|
||||
return new File(new File(ANT_TASK_TEST_DATA_BASE_DIR, "js"), name.getMethodName());
|
||||
}
|
||||
|
||||
private void doJsAntTest(String... jsFiles) throws Exception {
|
||||
doAntTest(SUCCESSFUL);
|
||||
|
||||
List<String> fileNames = new ArrayList<String>(Arrays.asList(jsFiles));
|
||||
fileNames.add(JS_OUT_FILE);
|
||||
|
||||
List<String> filePaths = ContainerUtil.map(fileNames, new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String s) {
|
||||
return getOutputFileByName(s).getAbsolutePath();
|
||||
}
|
||||
});
|
||||
|
||||
RhinoUtils.runRhinoTest(filePaths, new RhinoFunctionResultChecker("out", "foo", "box", "OK"));
|
||||
}
|
||||
|
||||
private void doJsAntTestForPostfixPrefix(@Nullable String prefix, @Nullable String postfix) throws Exception {
|
||||
doJsAntTest();
|
||||
File outputFile = getOutputFileByName(JS_OUT_FILE);
|
||||
|
||||
File prefixFile = prefix != null ? new File(getTestDataDir(), prefix) : null;
|
||||
File postfixFile = postfix != null ? new File(getTestDataDir(), postfix) : null;
|
||||
|
||||
checkFilePrefixPostfix(outputFile, prefixFile, postfixFile);
|
||||
}
|
||||
|
||||
private static void checkFilePrefixPostfix(@NotNull File file, @Nullable File prefix, @Nullable File postfix) throws IOException {
|
||||
String fileContent = FileUtil.loadFile(file, true);
|
||||
|
||||
if (prefix != null) {
|
||||
String prefixContent = FileUtil.loadFile(prefix, true);
|
||||
assertTrue(fileContent.startsWith(prefixContent));
|
||||
}
|
||||
|
||||
if (postfix != null) {
|
||||
String postfixContent = FileUtil.loadFile(postfix, true);
|
||||
assertTrue(fileContent.endsWith(postfixContent));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simple() throws Exception {
|
||||
doJsAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleWithMain() throws Exception {
|
||||
doJsAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleWithStdlib() throws Exception {
|
||||
doJsAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleWithStdlibAndAnotherLib() throws Exception {
|
||||
doJsAntTest("jslib-example.js");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleWithStdlibAndFolderAsAnotherLib() throws Exception {
|
||||
doJsAntTest("jslib-example.js");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleWithMainFQArgs() throws Exception {
|
||||
doJsAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleWithVarargMain() throws Exception {
|
||||
doJsAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void manySources() throws Exception {
|
||||
doJsAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void additionalArguments() throws Exception {
|
||||
doJsAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suppressWarnings() throws Exception {
|
||||
doJsAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verbose() throws Exception {
|
||||
doJsAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void version() throws Exception {
|
||||
doJsAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outputWithoutDirectory() throws Exception {
|
||||
doJsAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noSrcParam() throws Exception {
|
||||
doAntTest(FAILED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noOutputParam() throws Exception {
|
||||
doAntTest(FAILED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outputPrefix() throws Exception {
|
||||
doJsAntTestForPostfixPrefix("prefix", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outputPostfix() throws Exception {
|
||||
doJsAntTestForPostfixPrefix(null, "postfix");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bothPrefixAndPostfix() throws Exception {
|
||||
doJsAntTestForPostfixPrefix("prefix", "postfix");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sourceMap() throws Exception {
|
||||
doJsAntTest();
|
||||
|
||||
File sourceMap = getOutputFileByName(JS_OUT_FILE + ".map");
|
||||
assertTrue("Source map file \"" + sourceMap.getAbsolutePath() + "\" not found", sourceMap.exists());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.integration;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.utils.UtilsPackage;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class AntTaskJvmTest extends AntTaskBaseTest {
|
||||
private static final String JVM_OUT_FILE = "hello.jar";
|
||||
|
||||
@Rule
|
||||
public final TestName name = new TestName();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected File getTestDataDir() {
|
||||
return new File(new File(ANT_TASK_TEST_DATA_BASE_DIR, "jvm"), name.getMethodName());
|
||||
}
|
||||
|
||||
private void doJvmAntTest(String... extraJavaArgs) throws Exception {
|
||||
doAntTest(SUCCESSFUL, extraJavaArgs);
|
||||
|
||||
String jar = getOutputFileByName(JVM_OUT_FILE).getAbsolutePath();
|
||||
|
||||
runJava("hello.run", "-cp", jar + File.pathSeparator + getKotlinRuntimePath(), "hello.HelloPackage");
|
||||
}
|
||||
|
||||
private static String getClassPathForAnt() {
|
||||
return UtilsPackage.join(Arrays.asList(
|
||||
getCompilerLib() + File.separator + "kotlin-ant.jar",
|
||||
getCompilerLib() + File.separator + "kotlin-compiler.jar",
|
||||
getKotlinRuntimePath()
|
||||
), File.pathSeparator);
|
||||
}
|
||||
|
||||
private static String getIdeaSdkHome() {
|
||||
return getKotlinProjectHome().getAbsolutePath() + File.separator + "ideaSDK";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void helloWorld() throws Exception {
|
||||
doJvmAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void additionalArguments() throws Exception {
|
||||
doJvmAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jvmClasspath() throws Exception {
|
||||
doJvmAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void manySourceRoots() throws Exception {
|
||||
doJvmAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suppressWarnings() throws Exception {
|
||||
doJvmAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verbose() throws Exception {
|
||||
doJvmAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void version() throws Exception {
|
||||
doJvmAntTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void javacCompiler() throws Exception {
|
||||
doJvmAntTest("-cp", getClassPathForAnt(),
|
||||
"-Dkotlin.home", getCompilerLib().getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void externalAnnotations() throws Exception {
|
||||
doJvmAntTest("-cp", getClassPathForAnt(),
|
||||
"-Didea.sdk", getIdeaSdkHome(),
|
||||
"-Dkotlin.home", getCompilerLib().getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kotlinCompiler() throws Exception {
|
||||
doJvmAntTest("-cp", getClassPathForAnt(),
|
||||
"-Didea.sdk", getIdeaSdkHome(),
|
||||
"-Dkotlin.home", getCompilerLib().getAbsolutePath());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.integration;
|
||||
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestName;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class CompilerSmokeTest extends KotlinIntegrationTestBase {
|
||||
@Rule
|
||||
public final TestName name = new TestName();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected File getTestDataDir() {
|
||||
return new File(new File(INTEGRATION_TEST_DATA_BASE_DIR, "smoke"), name.getMethodName());
|
||||
}
|
||||
|
||||
private int runCompiler(String logName, String... arguments) throws Exception {
|
||||
String classpath = getCompilerLib().getAbsolutePath() + File.separator + "kotlin-compiler.jar" + File.pathSeparator +
|
||||
getKotlinRuntimePath();
|
||||
|
||||
Collection<String> javaArgs = new ArrayList<String>();
|
||||
javaArgs.add("-cp");
|
||||
javaArgs.add(classpath);
|
||||
javaArgs.add("org.jetbrains.jet.cli.jvm.K2JVMCompiler");
|
||||
Collections.addAll(javaArgs, arguments);
|
||||
|
||||
return runJava(logName, ArrayUtil.toStringArray(javaArgs));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void helloApp() throws Exception {
|
||||
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar";
|
||||
|
||||
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "hello.kt", "-d", jar));
|
||||
runJava("hello.run", "-cp", jar, "Hello.HelloPackage");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void helloAppFQMain() throws Exception {
|
||||
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar";
|
||||
|
||||
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "hello.kt", "-d", jar));
|
||||
runJava("hello.run", "-cp", jar, "Hello.HelloPackage");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void helloAppVarargMain() throws Exception {
|
||||
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar";
|
||||
|
||||
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "hello.kt", "-d", jar));
|
||||
runJava("hello.run", "-cp", jar, "Hello.HelloPackage");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compileAndRunModule() throws Exception {
|
||||
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "smoke.jar";
|
||||
|
||||
assertEquals("compilation failed", 0, runCompiler("Smoke.compile", "-module", "Smoke.ktm", "-d", jar));
|
||||
runJava("Smoke.run", "-cp", jar + File.pathSeparator + getKotlinRuntimePath(), "Smoke.SmokePackage", "1", "2", "3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compilationFailed() throws Exception {
|
||||
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "smoke.jar";
|
||||
|
||||
runCompiler("hello.compile", "hello.kt", "-d", jar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void syntaxErrors() throws Exception {
|
||||
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "smoke.jar";
|
||||
|
||||
runCompiler("test.compile", "test.kt", "-d", jar);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleScript() throws Exception {
|
||||
runCompiler("script", "-script", "script.kts", "hi", "there");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.integration;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.OutputListener;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.process.OSProcessHandler;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import kotlin.Function1;
|
||||
import kotlin.KotlinPackage;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.cli.common.KotlinVersion;
|
||||
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
||||
import org.jetbrains.jet.test.Tmpdir;
|
||||
import org.jetbrains.jet.utils.PathUtil;
|
||||
import org.junit.ComparisonFailure;
|
||||
import org.junit.Rule;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.regex.MatchResult;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class KotlinIntegrationTestBase {
|
||||
protected static final File INTEGRATION_TEST_DATA_BASE_DIR = new File(JetTestCaseBuilder.getTestDataPathBase(), "integration");
|
||||
|
||||
@Rule
|
||||
public final Tmpdir tmpdir = new Tmpdir();
|
||||
|
||||
static {
|
||||
System.setProperty("java.awt.headless", "true");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract File getTestDataDir();
|
||||
|
||||
protected int runJava(String logName, String... arguments) throws Exception {
|
||||
GeneralCommandLine commandLine = new GeneralCommandLine().withWorkDirectory(getTestDataDir());
|
||||
commandLine.setExePath(getJavaRuntime().getAbsolutePath());
|
||||
commandLine.addParameters(arguments);
|
||||
|
||||
StringBuilder executionLog = new StringBuilder();
|
||||
int exitCode = runProcess(commandLine, executionLog);
|
||||
|
||||
if (logName == null) {
|
||||
assertEquals("Non-zero exit code", 0, exitCode);
|
||||
}
|
||||
else {
|
||||
check(logName, executionLog.toString());
|
||||
}
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
private static String normalizePath(String content, File baseDir, String pathId) {
|
||||
String contentWithRelativePaths = content.replace(baseDir.getAbsolutePath(), pathId);
|
||||
|
||||
@Language("RegExp")
|
||||
String RELATIVE_PATH_WITH_MIXED_SEPARATOR = Pattern.quote(pathId) + "[-.\\w/\\\\]*";
|
||||
|
||||
return KotlinPackage.replaceAll(contentWithRelativePaths, RELATIVE_PATH_WITH_MIXED_SEPARATOR, new Function1<MatchResult, String>() {
|
||||
@Override
|
||||
public String invoke(MatchResult mr) {
|
||||
return FileUtil.toSystemIndependentName(mr.group());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected String normalizeOutput(String content) {
|
||||
content = normalizePath(content, getTestDataDir(), "[TestData]");
|
||||
content = normalizePath(content, tmpdir.getTmpDir(), "[Temp]");
|
||||
content = normalizePath(content, getCompilerLib(), "[CompilerLib]");
|
||||
content = normalizePath(content, getKotlinProjectHome(), "[KotlinProjectHome]");
|
||||
content = content.replaceAll(KotlinVersion.VERSION, "[KotlinVersion]");
|
||||
content = StringUtil.convertLineSeparators(content);
|
||||
return content;
|
||||
}
|
||||
|
||||
private void check(String baseName, String content) throws IOException {
|
||||
File actualFile = new File(getTestDataDir(), baseName + ".actual");
|
||||
File expectedFile = new File(getTestDataDir(), baseName + ".expected");
|
||||
|
||||
String normalizedContent = normalizeOutput(content);
|
||||
|
||||
if (!expectedFile.isFile()) {
|
||||
Files.write(normalizedContent, actualFile, Charsets.UTF_8);
|
||||
fail("No .expected file " + expectedFile);
|
||||
}
|
||||
|
||||
try {
|
||||
JetTestUtils.assertEqualsToFile(expectedFile, normalizedContent);
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
actualFile.delete();
|
||||
}
|
||||
catch (ComparisonFailure e) {
|
||||
Files.write(normalizedContent, actualFile, Charsets.UTF_8);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private static int runProcess(GeneralCommandLine commandLine, StringBuilder executionLog) throws ExecutionException {
|
||||
OSProcessHandler handler =
|
||||
new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString(), commandLine.getCharset());
|
||||
|
||||
StringBuilder outContent = new StringBuilder();
|
||||
StringBuilder errContent = new StringBuilder();
|
||||
|
||||
handler.addProcessListener(new OutputListener(outContent, errContent));
|
||||
|
||||
handler.startNotify();
|
||||
handler.waitFor();
|
||||
int exitCode = handler.getProcess().exitValue();
|
||||
|
||||
appendIfNotEmpty(executionLog, "OUT:\n", outContent);
|
||||
appendIfNotEmpty(executionLog, "\nERR:\n", errContent);
|
||||
|
||||
executionLog.append("\nReturn code: ").append(exitCode).append("\n");
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
private static void appendIfNotEmpty(StringBuilder executionLog, String prefix, StringBuilder content) {
|
||||
if (content.length() > 0) {
|
||||
executionLog.append(prefix);
|
||||
executionLog.append(content);
|
||||
}
|
||||
}
|
||||
|
||||
private static File getJavaRuntime() {
|
||||
File javaHome = new File(System.getProperty("java.home"));
|
||||
String javaExe = SystemInfo.isWindows ? "java.exe" : "java";
|
||||
|
||||
File runtime = new File(javaHome, "bin" + File.separator + javaExe);
|
||||
assertTrue("No java runtime at " + runtime, runtime.isFile());
|
||||
|
||||
return runtime;
|
||||
}
|
||||
|
||||
protected static File getCompilerLib() {
|
||||
File file = PathUtil.getKotlinPathsForDistDirectory().getLibPath().getAbsoluteFile();
|
||||
assertTrue("Lib directory doesn't exist. Run 'ant dist'", file.isDirectory());
|
||||
return file;
|
||||
}
|
||||
|
||||
protected static String getKotlinRuntimePath() {
|
||||
return ForTestCompileRuntime.runtimeJarForTests().getAbsolutePath();
|
||||
}
|
||||
|
||||
protected static File getKotlinProjectHome() {
|
||||
return new File(PathManager.getHomePath()).getParentFile();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user