Add tests for jps plugin

Original commit: 74ca357502
This commit is contained in:
Natalia.Ukhorskaya
2012-11-27 11:41:18 +04:00
parent f0c15286c1
commit eef49ca923
31 changed files with 543 additions and 1 deletions
+2
View File
@@ -4,6 +4,7 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="jdk" jdkName="1.6" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
@@ -12,6 +13,7 @@
<orderEntry type="module" module-name="util" />
<orderEntry type="library" name="jps" level="project" />
<orderEntry type="library" scope="TEST" name="jps-test" level="project" />
<orderEntry type="library" scope="TEST" name="idea-full" level="project" />
</component>
</module>
@@ -0,0 +1,16 @@
<?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$/test" isTestSource="true" />
</content>
<orderEntry type="jdk" jdkName="1.6" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="jps-plugin" scope="TEST" />
<orderEntry type="library" scope="TEST" name="jps" level="project" />
<orderEntry type="library" scope="TEST" name="jps-test" level="project" />
<orderEntry type="library" scope="TEST" name="idea-full" level="project" />
</component>
</module>
@@ -0,0 +1,109 @@
/*
* 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.jet.jps.build.kannotator;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.jet.jps.build.AbstractKotlinJpsBuildTestCase;
import org.jetbrains.jps.builders.BuildResult;
import org.jetbrains.jps.model.module.JpsModule;
import org.jetbrains.jps.model.module.JpsModuleSourceRoot;
import java.io.File;
import java.io.IOException;
public class KAnnotatorJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase {
private static final String JDK_NAME = "1.6";
@Override
public void setUp() throws Exception {
super.setUp();
File sourceFilesRoot = new File(TEST_DATA_PATH + File.separator + "kannotator");
workDir = copyTestDataToTmpDir(sourceFilesRoot);
}
public void testMakeKannotator() {
doTest(false);
}
public void testRebuildKannotator() {
doTest(true);
}
private void doTest(boolean rebuildBeforeMake) {
initProject();
rebuildAll();
for (JpsModule module : myProject.getModules()) {
for (JpsModuleSourceRoot sourceRoot : module.getSourceRoots()) {
processFile(sourceRoot.getFile(), rebuildBeforeMake);
}
}
}
private void processFile(File root, boolean rebuildBeforeMake) {
if (root.isDirectory()) {
File[] files = root.listFiles();
if (files == null) return;
for (File file : files) {
processFile(file, rebuildBeforeMake);
}
}
else if (root.getName().endsWith(".kt")) {
System.out.println("Test started. File: " + root.getName());
String path = root.getAbsolutePath();
if (rebuildBeforeMake) {
rebuildAll();
}
System.out.println("Change file: " + path);
change(path);
makeAll().assertSuccessful();
System.out.println("Test successfully finished. File: " + root.getName());
System.out.println("-----");
}
}
@Override
protected void rebuildAll() {
System.out.println("'Rebuild all' started");
super.rebuildAll();
System.out.println("'Rebuild all' finished");
}
@Override
protected BuildResult makeAll() {
System.out.println("'Make all' started");
BuildResult result = super.makeAll();
System.out.println("'Make all' finished");
return result;
}
@Override
protected File doGetProjectDir() throws IOException {
return workDir;
}
private void initProject() {
addJdk(JDK_NAME);
loadProject(workDir.getAbsolutePath());
addKotlinRuntimeDependency();
}
@Override
public void tearDown() throws Exception {
FileUtil.delete(workDir);
super.tearDown();
}
}
@@ -83,7 +83,7 @@ public class KotlinBuilder extends ModuleLevelBuilder {
File outputDir = representativeTarget.getOutputDir();
CompilerEnvironment environment = CompilerEnvironment.getEnvironmentFor(PathUtil.getKotlinPathsForJpsPlugin(), outputDir);
CompilerEnvironment environment = CompilerEnvironment.getEnvironmentFor(PathUtil.getKotlinPathsForJpsPluginOrJpsTests(), outputDir);
if (!environment.success()) {
environment.reportErrorsTo(messageCollector);
return ExitCode.ABORT;
@@ -0,0 +1,90 @@
/*
* 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.jet.jps.build;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.jet.utils.PathUtil;
import org.jetbrains.jps.builders.JpsBuildTestCase;
import org.jetbrains.jps.model.JpsDummyElement;
import org.jetbrains.jps.model.JpsModuleRootModificationUtil;
import org.jetbrains.jps.model.java.JpsAnnotationRootType;
import org.jetbrains.jps.model.java.JpsJavaDependencyScope;
import org.jetbrains.jps.model.java.JpsJavaLibraryType;
import org.jetbrains.jps.model.java.JpsJavaSdkType;
import org.jetbrains.jps.model.library.JpsLibrary;
import org.jetbrains.jps.model.library.JpsOrderRootType;
import org.jetbrains.jps.model.library.JpsTypedLibrary;
import org.jetbrains.jps.model.library.sdk.JpsSdk;
import org.jetbrains.jps.model.module.JpsModule;
import org.jetbrains.jps.util.JpsPathUtil;
import java.io.File;
import java.io.IOException;
public abstract class AbstractKotlinJpsBuildTestCase extends JpsBuildTestCase {
protected static final String TEST_DATA_PATH = "jps-plugin/testData/";
protected File workDir;
@Override
public void setUp() throws Exception {
super.setUp();
System.setProperty("kotlin.jps.tests", "true");
}
@Override
public void tearDown() throws Exception {
System.clearProperty("kotlin.jps.tests");
super.tearDown();
}
protected static File copyTestDataToTmpDir(File testDataDir) throws IOException {
assert testDataDir.exists() : "Cannot find source folder";
File tmpDir = FileUtil.createTempDirectory("jps-build", null);
FileUtil.copyDir(testDataDir, tmpDir);
return tmpDir;
}
@Override
protected File doGetProjectDir() throws IOException {
return workDir;
}
@Override
protected JpsSdk<JpsDummyElement> addJdk(final String name, final String path) {
String homePath = System.getProperty("java.home");
String versionString = System.getProperty("java.version");
JpsTypedLibrary<JpsSdk<JpsDummyElement>> jdk = myModel.getGlobal().addSdk(name, homePath, versionString, JpsJavaSdkType.INSTANCE);
jdk.addRoot(JpsPathUtil.pathToUrl(path), JpsOrderRootType.COMPILED);
jdk.addRoot(JpsPathUtil.pathToUrl(PathUtil.getKotlinPathsForDistDirectory().getJdkAnnotationsPath().getAbsolutePath()), JpsAnnotationRootType.INSTANCE);
return jdk.getProperties();
}
protected JpsLibrary addKotlinRuntimeDependency() {
return addKotlinRuntimeDependency(JpsJavaDependencyScope.COMPILE);
}
protected JpsLibrary addKotlinRuntimeDependency(JpsJavaDependencyScope type) {
JpsLibrary library = myProject.addLibrary("kotlin-runtime", JpsJavaLibraryType.INSTANCE);
File runtime = PathUtil.getKotlinPathsForDistDirectory().getRuntimePath();
library.addRoot(runtime, JpsOrderRootType.COMPILED);
for (JpsModule module : myProject.getModules()) {
JpsModuleRootModificationUtil.addDependency(module, library, type, false);
}
return library;
}
}
@@ -0,0 +1,84 @@
/*
* 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.jet.jps.build;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.jps.model.java.*;
import java.io.File;
import java.io.IOException;
public class KotlinJpsBuildTestCase extends AbstractKotlinJpsBuildTestCase {
private static final String PROJECT_NAME = "kotlinProject";
private static final String JDK_NAME = "IDEA_JDK";
@Override
public void setUp() throws Exception {
super.setUp();
File sourceFilesRoot = new File(TEST_DATA_PATH + File.separator + getTestName(true));
workDir = copyTestDataToTmpDir(sourceFilesRoot);
}
@Override
public void tearDown() throws Exception {
FileUtil.delete(workDir);
super.tearDown();
}
private void initProject() {
addJdk(JDK_NAME);
loadProject(workDir.getAbsolutePath() + File.separator + PROJECT_NAME + ".ipr");
}
public void doTest() {
initProject();
makeAll().assertSuccessful();
}
public void testSimpleKotlinProject() {
doTest();
}
public void testSimpleKotlinJavaProject() {
doTest();
}
public void testJKJProject() {
doTest();
}
public void testKJKProject() {
doTest();
}
public void testKJCircularProject() {
doTest();
}
public void testTwoModules() {
doTest();
}
public void testTestOnlyDependency() throws Throwable {
initProject();
addKotlinRuntimeDependency(JpsJavaDependencyScope.TEST);
makeAll().assertSuccessful();
change(workDir + "/src/src.kt", "fun foo() { println() }");
makeAll().assertFailed();
}
}
@@ -0,0 +1,13 @@
<?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="false" />
</content>
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="kotlinProject" />
<orderEntry type="library" name="KotlinRuntime" level="project" />
</component>
</module>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
</component>
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
@@ -0,0 +1,7 @@
package java;
public class JFirst {
public void foo() {
new kotlin.KFirst().foo();
}
}
@@ -0,0 +1,7 @@
package java;
public class JSecond {
public void foo() {
}
}
@@ -0,0 +1,7 @@
package kotlin
class KFirst() {
fun foo() {
java.JSecond().foo()
}
}
@@ -0,0 +1,12 @@
<?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="false" />
</content>
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="kotlinProject" />
</component>
</module>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
</component>
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
@@ -0,0 +1,11 @@
package java;
public class JFirst {
public void foo() {
new kotlin.KFirst().foo();
}
public void bar() {
new kotlin.KFirst().bar();
}
}
@@ -0,0 +1,9 @@
package kotlin
class KFirst() {
fun foo() {
java.JFirst().bar()
}
fun bar() {}
}
@@ -0,0 +1,13 @@
<?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="false" />
</content>
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="kotlinProject" />
</component>
</module>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
</component>
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
@@ -0,0 +1,7 @@
package java;
public class JFirst {
public void foo() {
new kotlin.KSecond().foo();
}
}
@@ -0,0 +1,7 @@
package kotlin
class KFirst() {
fun foo() {
java.JFirst().foo()
}
}
@@ -0,0 +1,7 @@
package kotlin
class KSecond() {
fun foo() {
}
}
@@ -0,0 +1,12 @@
<?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="false" />
</content>
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="kotlinProject" />
</component>
</module>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
</component>
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
@@ -0,0 +1,6 @@
import test.*;
class A {
public static void main(String[] args) {
new Foo().foo();
}
}
@@ -0,0 +1,7 @@
package test
class Foo() {
fun foo() {
}
}
@@ -0,0 +1,12 @@
<?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="false" />
</content>
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="kotlinProject" />
</component>
</module>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
</component>
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
@@ -0,0 +1,3 @@
fun foo() {
}
@@ -0,0 +1,13 @@
<?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="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="kotlinProject" />
</component>
</module>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
</component>
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
@@ -0,0 +1 @@
fun foo() { }
@@ -0,0 +1,3 @@
fun test() {
println("a")
}