integration tests draft
This commit is contained in:
Generated
+1
@@ -6,6 +6,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/backend/backend.iml" filepath="$PROJECT_DIR$/compiler/backend/backend.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/build-tools/build-tools.iml" filepath="$PROJECT_DIR$/build-tools/build-tools.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/cli/cli.iml" filepath="$PROJECT_DIR$/compiler/cli/cli.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/integration-tests/compiler-integration-tests.iml" filepath="$PROJECT_DIR$/compiler/integration-tests/compiler-integration-tests.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/tests/compiler-tests.iml" filepath="$PROJECT_DIR$/compiler/tests/compiler-tests.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/frontend/frontend.iml" filepath="$PROJECT_DIR$/compiler/frontend/frontend.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/compiler/frontend.java/frontend.java.iml" filepath="$PROJECT_DIR$/compiler/frontend.java/frontend.java.iml" />
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="true" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/../../ideaSDK/lib/junit-4.10.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$MODULE_DIR$/../../ideaSDK/lib/junit-4.10-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" name="idea-full" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
OUT Usage: org.jetbrains.jet.cli.CompilerArguments
|
||||
OUT -output [String] output directory
|
||||
OUT -jar [String] jar file name
|
||||
OUT -src [String] source file or directory
|
||||
OUT -module [String] module to compile
|
||||
OUT -classpath [String] classpath to use when compiling
|
||||
OUT -includeRuntime [flag]
|
||||
OUT -stdlib [String] Path to the stdlib.jar
|
||||
OUT -jdkHeaders [String] Path to the kotlin-jdk-headers.jar
|
||||
OUT -help (-h) [flag]
|
||||
OUT -mode [String] Special compiler modes: stubs or jdkHeaders
|
||||
OUT -tags [flag]
|
||||
OUT -verbose [flag]
|
||||
OUT -version [flag]
|
||||
ERR exec() finished with INTERNAL_ERROR return code
|
||||
Return code: 2
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CompilerSmokeTest extends KotlinIntegrationTestBase {
|
||||
@Test
|
||||
public void help() throws Exception {
|
||||
runCompiler("help", "--help");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.execution.process.OSProcessHandler;
|
||||
import com.intellij.execution.process.ProcessAdapter;
|
||||
import com.intellij.execution.process.ProcessEvent;
|
||||
import com.intellij.execution.process.ProcessOutputTypes;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.apache.commons.lang.SystemUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static com.google.common.base.Charsets.UTF_8;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class KotlinIntegrationTestBase {
|
||||
protected void runCompiler(String logName, String... arguments) throws Exception {
|
||||
Collection<String> javaArgs = new ArrayList<String>();
|
||||
javaArgs.add("-jar");
|
||||
javaArgs.add(getCompilerJar().getAbsolutePath());
|
||||
Collections.addAll(javaArgs, arguments);
|
||||
|
||||
runJava(logName, ArrayUtil.toStringArray(javaArgs));
|
||||
}
|
||||
|
||||
protected void runCompiler(StringBuilder executionLog) throws ExecutionException {
|
||||
final File compilerJar = getCompilerJar();
|
||||
assertTrue("no kotlin compiler at " + compilerJar, compilerJar.isFile());
|
||||
|
||||
GeneralCommandLine commandLine = new GeneralCommandLine();
|
||||
commandLine.setExePath(getJavaRuntime().getAbsolutePath());
|
||||
commandLine.addParameters("-jar", compilerJar.getAbsolutePath());
|
||||
commandLine.addParameters("--help");
|
||||
|
||||
runProcess(commandLine, executionLog);
|
||||
}
|
||||
|
||||
protected void runJava(String logName, String... arguments) throws Exception {
|
||||
GeneralCommandLine commandLine = new GeneralCommandLine();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
protected void check(String baseName, StringBuilder content) throws IOException {
|
||||
final File tmpFile = new File(getTestDataDirectory(), baseName + ".tmp");
|
||||
final File goldFile = new File(getTestDataDirectory(), baseName + ".gold");
|
||||
|
||||
if (!goldFile.isFile()) {
|
||||
Files.write(content, tmpFile, Charsets.UTF_8);
|
||||
fail("No gold file " + goldFile);
|
||||
} else {
|
||||
final String goldContent = Files.toString(goldFile, UTF_8);
|
||||
if (!goldContent.equals(content.toString())) {
|
||||
Files.write(content, tmpFile, Charsets.UTF_8);
|
||||
fail("tmp and gold differ, tmp file: " + tmpFile);
|
||||
}
|
||||
tmpFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
protected int runProcess(final GeneralCommandLine commandLine, final StringBuilder executionLog) throws ExecutionException {
|
||||
OSProcessHandler handler =
|
||||
new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString(), commandLine.getCharset());
|
||||
|
||||
final StringBuilder outContent = new StringBuilder();
|
||||
final StringBuilder errContent = new StringBuilder();
|
||||
|
||||
handler.addProcessListener(new ProcessAdapter() {
|
||||
@Override
|
||||
public void onTextAvailable(ProcessEvent event, Key outputType) {
|
||||
if (outputType == ProcessOutputTypes.SYSTEM) {
|
||||
System.out.print(event.getText());
|
||||
}
|
||||
else if (outputType == ProcessOutputTypes.STDOUT) {
|
||||
outContent.append("OUT ");
|
||||
outContent.append(event.getText());
|
||||
}
|
||||
else if (outputType == ProcessOutputTypes.STDERR) {
|
||||
errContent.append("ERR ");
|
||||
errContent.append(event.getText());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
handler.startNotify();
|
||||
handler.waitFor();
|
||||
int exitCode = handler.getProcess().exitValue();
|
||||
|
||||
executionLog.append(outContent);
|
||||
executionLog.append(errContent);
|
||||
executionLog.append("Return code: ").append(exitCode).append(SystemUtils.LINE_SEPARATOR);
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
protected static File getJavaRuntime() {
|
||||
final File javaHome = new File(System.getProperty("java.home"));
|
||||
final String javaExe = SystemInfo.isWindows ? "java.exe" : "java";
|
||||
|
||||
final File runtime = new File(javaHome, "bin" + File.separator + javaExe);
|
||||
assertTrue("no java runtime at " + runtime, runtime.isFile());
|
||||
|
||||
return runtime;
|
||||
}
|
||||
|
||||
protected static File getCompilerJar() {
|
||||
final File file = new File(getKotlinProjectHome(), "dist" + File.separator + "kotlin-compiler.jar");
|
||||
assertTrue("no kotlin compiler at " + file, file.isFile());
|
||||
return file;
|
||||
}
|
||||
|
||||
protected static File getTestDataDirectory() {
|
||||
return new File(getKotlinProjectHome(), "compiler" + File.separator + "integration-tests" + File.separator + "data");
|
||||
}
|
||||
|
||||
protected static File getKotlinProjectHome() {
|
||||
return new File(PathManager.getHomePath()).getParentFile();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user