From 102ced153cdebb255f3584a233e11d32139ee236 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 9 Oct 2013 21:56:50 +0400 Subject: [PATCH] Remove binary test data from completion tests Delete CompileBinaryTestData script, since there are no tests with binary test data left in the repository --- .../generators/tests/CompileBinaryTestData.kt | 95 ------------------ .../jet/generators/tests/GenerateTests.java | 2 +- .../custom/TopLevelNonImportedExtFun.jar | Bin 1911 -> 0 bytes .../source.kt} | 3 - .../basic/custom/TopLevelNonImportedFun.jar | Bin 1896 -> 0 bytes .../source.kt} | 3 - .../AbstractJavaWithLibCompletionTest.java | 84 ++-------------- .../JetJavaLibCompletionTestGenerated.java | 4 +- .../jet/plugin/PluginTestCaseBase.java | 6 +- .../resolve/AbstractResolveWithLibTest.java | 12 +-- 10 files changed, 18 insertions(+), 191 deletions(-) delete mode 100644 generators/src/org/jetbrains/jet/generators/tests/CompileBinaryTestData.kt delete mode 100644 idea/testData/completion/basic/custom/TopLevelNonImportedExtFun.jar rename idea/testData/completion/basic/custom/{TopLevelNonImportedFunSource.kt.txt => TopLevelNonImportedExtFunSrc/source.kt} (58%) delete mode 100644 idea/testData/completion/basic/custom/TopLevelNonImportedFun.jar rename idea/testData/completion/basic/custom/{TopLevelNonImportedExtFunSource.kt.txt => TopLevelNonImportedFunSrc/source.kt} (58%) diff --git a/generators/src/org/jetbrains/jet/generators/tests/CompileBinaryTestData.kt b/generators/src/org/jetbrains/jet/generators/tests/CompileBinaryTestData.kt deleted file mode 100644 index ec3dfd40cd0..00000000000 --- a/generators/src/org/jetbrains/jet/generators/tests/CompileBinaryTestData.kt +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2010-2013 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.generators.tests - -import java.io.File -import com.intellij.openapi.util.SystemInfo -import com.intellij.openapi.util.io.FileUtil -import java.lang.annotation.Retention -import java.lang.annotation.RetentionPolicy - -var cwd = File("") -fun mv(from: String, to: String) = File(cwd, from).renameTo(File(cwd, to)) -fun cp(from: String, to: String) = File(cwd, from).copyTo(File(cwd, to)) -fun rm(path: String) = FileUtil.delete(File(cwd, path)) - -fun runProcess(cmd: String) { - val process = Runtime.getRuntime().exec(cmd) - process.waitFor() - process.getInputStream()?.reader()?.forEachLine { println(it) } - process.getErrorStream()?.reader()?.forEachLine { System.err.println(it) } - if (process.exitValue() != 0) { - System.err.println("Exit code ${process.exitValue()} was returned by: $cmd") - } -} - -fun jar(dest: String, src: String) { - runProcess("jar cvf $cwd/$dest -C $cwd $src") -} - -Retention(RetentionPolicy.RUNTIME) -private annotation class GenScript(val dir: String, val source: String, val binary: String) - -private object BinaryTestData { - GenScript("idea/testData/completion/basic/custom/", "TopLevelNonImportedExtFunSource.kt", "TopLevelNonImportedExtFun.jar") - fun genTopLevelNonImportedExtFun() { - jar("TopLevelNonImportedExtFun.jar", "abc") - rm("abc") - } - - GenScript("idea/testData/completion/basic/custom/", "TopLevelNonImportedFunSource.kt", "TopLevelNonImportedFun.jar") - fun genTopLevelNonImportedFun() { - jar("TopLevelNonImportedFun.jar", "abc") - rm("abc") - } -} - -fun changeDirectory(dir: String) { - cwd = File(dir) -} - -fun deleteBinary(file: String) = rm(file) - -fun compileSource(src: String) { - // We assume that ${script.source}.txt file exists and contains the source to compile. Kotlin compiler would not compile the source - // with the ".txt" extension, so we temporarily rename this file to ${script.source} (it should end with ".kt") - assert(src.endsWith(".kt"), "Source should have a '.kt' extension: $src") - mv("$src.txt", src) - try { - runProcess("dist/kotlinc/bin/kotlinc-jvm${if (SystemInfo.isWindows) ".bat" else ""} -src $cwd/$src -output $cwd") - } - finally { - mv(src, "$src.txt") - } -} - -fun main(args: Array) { - System.setProperty("java.awt.headless", "true") - for (method in javaClass().getDeclaredMethods()) { - val script = method.getAnnotation(javaClass()) as? GenScript ?: continue - - println() - println("---------------------------------") - println("Processing: ${script.dir}") - - changeDirectory(script.dir) - deleteBinary(script.binary) - compileSource(script.source) - - method.invoke(BinaryTestData) - } -} diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.java b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.java index abb741a4949..560e8b9e7f8 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.java +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.java @@ -316,7 +316,7 @@ public class GenerateTests { "idea/tests", "JetJavaLibCompletionTestGenerated", AbstractJavaWithLibCompletionTest.class, - testModel("idea/testData/completion/basic/custom", false, "doTestWithJar")); + testModel("idea/testData/completion/basic/custom", false, "doTest")); generateTest( "idea/tests", diff --git a/idea/testData/completion/basic/custom/TopLevelNonImportedExtFun.jar b/idea/testData/completion/basic/custom/TopLevelNonImportedExtFun.jar deleted file mode 100644 index a0a71fc6d5508af663e996f206a7e54cfa5f66ab..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1911 zcmWIWW@Zs#-~hr69Zt>+NPv@pg~8V~#8KDN&rSc|DFy~+h5&DN4v-2asImZ@nni#r z;F^6M{XE@VgG2Ou-9G!CIql=Et9OytTUYDcne&^246YbIcv__A<*VcAd$DvC3+IfN zl1FAsX=PZ5i9A`NRq;&qb>^p{k421N+b@V6%eMiV4ZWo?D@xo-^MdnBi;`1y(-Kot z4O7$1^^$WEi;H^$eDj43MdnP;@eJmg!l2v8Ec9rC+^JQpE7|>Kw|H<1h6KF5ySuV; zPTrdng-SmnV=O-~{|M~ZF7LXsg=N}2`(yKFn*aOx`ZqsAdWDlkc&3i=D#03KRdX(f6gr38$ZljY^T0zx$6~ud5Yidme`lYLarAz7v8k? z%UW>%{d~cuxEO`KL6_F{UgzffdtEi#cqtEhR&c(l!U1)#c@T@wWt2;dH*EGzkyURY+$-Oss z;o50Z6){?GJFHY>A5II=KK3pjlswTzq{?&T9?epLL>+drpNInz%bmw#Sna}f!|4-O2&Zcl^DRbSKY+Jc~ z>uo>twak}Tpfsgy@nYRVohtvu8?M@SJ#r~Aw^!|Nd)S>J@jL0Gf#VK`9YA++I>xRj z5xDm6S@?hEmG6obrycn>i&1>j1SVx(wI#=6u9r?1+|oLYML$QjV~H65VU-u%QJ;Q# zuso~_sn(gq_n!A?vE1i<9xi+QBo$)?4Nf?T6-~;Rcugu;y4Owipw96_;s-Z&Y%WL@ zF)`%3apOjW;|1}k5OePEg&K2%Ii~wtR|u)@RgkHd6ZJ0Ef6-AP;Ih!m{^pWTvGWR! z9Am$2`26?LU8|QFr5@cYyf@>$-p1=+7w(-q@3pvgT(RNrjlZ%!J+y=XDFx~kGQ`LkMYUiCV9h;11U_r?acv?9LJrB5#0OO`3VVQ|vEJGc3bA9LxG z%dW?LU$bp5JJr<{rdA*$?i;HA#$re3=AT@?QQkph^K7 diff --git a/idea/testData/completion/basic/custom/TopLevelNonImportedFunSource.kt.txt b/idea/testData/completion/basic/custom/TopLevelNonImportedExtFunSrc/source.kt similarity index 58% rename from idea/testData/completion/basic/custom/TopLevelNonImportedFunSource.kt.txt rename to idea/testData/completion/basic/custom/TopLevelNonImportedExtFunSrc/source.kt index 9f7a0034d93..5a59cd4d890 100644 --- a/idea/testData/completion/basic/custom/TopLevelNonImportedFunSource.kt.txt +++ b/idea/testData/completion/basic/custom/TopLevelNonImportedExtFunSrc/source.kt @@ -1,8 +1,5 @@ package abc -// To regenerate this test, run CompileBinaryTestData.kt -// Or manually, compile this file into jar - public fun abcdAAA1(): Unit {} public fun abcdBBB2(i: Int) {} diff --git a/idea/testData/completion/basic/custom/TopLevelNonImportedFun.jar b/idea/testData/completion/basic/custom/TopLevelNonImportedFun.jar deleted file mode 100644 index 2363847668e363a992791c8caacd3bfbe61e32a3..0000000000000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rzuo!hi0 zvsj1g^obcwyMODPti0>gR(W{SMs35FQGScHc+zGjJr+N2aNNXyiNyJicI`t26?q$9 zRGr{`Y4%Lw>*SAjx$ny4@A$!z{`obN?c~BQx;mTWYj&N;y0Nf)&!)HRuZ}Lb9&~YD zPU%UbeX`q9w`(fLzgA8zEVq#M-T!{_!{-hi3LMFjmw$hGxwS3%`<3gG=iWWb$8!H& zfq$B9j_OU;|9U3jA5+>P*-2Jg9d4bqy3;h%`GDP>e|(@E(h|%1{sAy|bN~y;0B=Sn z5eC$vA6Bk|ihfi8FUvs{0lHS?LK&335Wp75glk2r20$ioG2kw|5hm;gG9g7ds&kPu yJE$;6fV)5@Y6d5zXh-)Oa*(0=?K&{DQ0;*fBmv&6Y#`UL0%0VuIQq#7;sF5Y+s#A( diff --git a/idea/testData/completion/basic/custom/TopLevelNonImportedExtFunSource.kt.txt b/idea/testData/completion/basic/custom/TopLevelNonImportedFunSrc/source.kt similarity index 58% rename from idea/testData/completion/basic/custom/TopLevelNonImportedExtFunSource.kt.txt rename to idea/testData/completion/basic/custom/TopLevelNonImportedFunSrc/source.kt index 9f7a0034d93..5a59cd4d890 100644 --- a/idea/testData/completion/basic/custom/TopLevelNonImportedExtFunSource.kt.txt +++ b/idea/testData/completion/basic/custom/TopLevelNonImportedFunSrc/source.kt @@ -1,8 +1,5 @@ package abc -// To regenerate this test, run CompileBinaryTestData.kt -// Or manually, compile this file into jar - public fun abcdAAA1(): Unit {} public fun abcdBBB2(i: Int) {} diff --git a/idea/tests/org/jetbrains/jet/completion/AbstractJavaWithLibCompletionTest.java b/idea/tests/org/jetbrains/jet/completion/AbstractJavaWithLibCompletionTest.java index 62f6691c2ea..1635a88bc76 100644 --- a/idea/tests/org/jetbrains/jet/completion/AbstractJavaWithLibCompletionTest.java +++ b/idea/tests/org/jetbrains/jet/completion/AbstractJavaWithLibCompletionTest.java @@ -16,98 +16,26 @@ package org.jetbrains.jet.completion; -import com.intellij.openapi.module.Module; -import com.intellij.openapi.module.ModuleType; -import com.intellij.openapi.module.StdModuleTypes; -import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.roots.ContentEntry; -import com.intellij.openapi.roots.ModifiableRootModel; -import com.intellij.openapi.roots.OrderRootType; -import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.testFramework.LightProjectDescriptor; -import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; -import junit.framework.Assert; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.cli.common.ExitCode; -import org.jetbrains.jet.cli.jvm.K2JVMCompiler; -import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime; -import org.jetbrains.jet.codegen.forTestCompile.ForTestPackJdkAnnotations; +import org.jetbrains.jet.plugin.JdkAndMockLibraryProjectDescriptor; import org.jetbrains.jet.plugin.PluginTestCaseBase; import org.jetbrains.jet.plugin.project.TargetPlatform; -import org.jetbrains.jet.testing.ConfigLibraryUtil; - -import java.io.File; -import java.io.IOException; public abstract class AbstractJavaWithLibCompletionTest extends JetFixtureCompletionBaseTestCase { - public void doTestWithJar(String testPath) throws IOException { - - File jarDependency = getOrCompileJarDependency(testPath); - assert jarDependency.exists() : "Library file should exist: " + jarDependency.getAbsolutePath(); - NewLibraryEditor editor = new NewLibraryEditor(); - editor.setName("doTestWithJarLib"); - editor.addRoot(VfsUtil.getUrlForLibraryRoot(jarDependency), OrderRootType.CLASSES); - - try { - ConfigLibraryUtil.configureLibrary(myModule, getProjectDescriptor().getSdk(), editor); - CodeInsightTestFixtureImpl.ensureIndexesUpToDate(getProject()); - doTest(testPath); - } - finally { - ConfigLibraryUtil.unConfigureLibrary(myModule, getProjectDescriptor().getSdk(), editor.getName()); - } - } + private static final String TEST_PATH = PluginTestCaseBase.getTestDataPathBase() + "/completion/basic/custom"; @NotNull @Override protected LightProjectDescriptor getProjectDescriptor() { - return new LightProjectDescriptor() { - @Override - public ModuleType getModuleType() { - return StdModuleTypes.JAVA; - } - - @Override - public Sdk getSdk() { - return PluginTestCaseBase.jdkFromIdeaHome(); - } - - @Override - public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) { - // Do nothing - } - }; + if (PluginTestCaseBase.isAllFilesPresentTest(getTestName(true))) { + return super.getProjectDescriptor(); + } + return new JdkAndMockLibraryProjectDescriptor(TEST_PATH + "/" + getTestName(true) + "Src", false); } @Override public TargetPlatform getPlatform() { return TargetPlatform.JVM; } - - //NOTE: you can just delete existing jar to recompile data for tests that have kotlin dependency - @NotNull - private File getOrCompileJarDependency(@NotNull String testPath) throws IOException { - File fullDirectoryPath = new File(testPath).getParentFile(); - String jarLibName = getTestName(false) + ".jar"; - File jarFile = new File(fullDirectoryPath, jarLibName); - if (!jarFile.exists()) { - compileDependencySources(jarFile, fullDirectoryPath); - } - return jarFile; - } - - private void compileDependencySources(@NotNull File outputFile, @NotNull File fullDirectoryPath) { - File sourcesDir = new File(fullDirectoryPath, getTestName(true) + "Src"); - File stdlib = ForTestCompileRuntime.runtimeJarForTests(); - File jdkAnnotations = ForTestPackJdkAnnotations.jdkAnnotationsForTests(); - ExitCode rv = new K2JVMCompiler().exec(System.out, - "-src", sourcesDir.getAbsolutePath(), - "-jar", outputFile.getAbsolutePath(), - "-noStdlib", - "-classpath", stdlib.getAbsolutePath(), - "-noJdkAnnotations", - "-annotations", jdkAnnotations.getAbsolutePath()); - Assert.assertEquals("compilation completed with non-zero code: " + rv.getCode(), ExitCode.OK, rv); - } } diff --git a/idea/tests/org/jetbrains/jet/completion/JetJavaLibCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/JetJavaLibCompletionTestGenerated.java index df60683327f..51d4ddf860a 100644 --- a/idea/tests/org/jetbrains/jet/completion/JetJavaLibCompletionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/JetJavaLibCompletionTestGenerated.java @@ -38,12 +38,12 @@ public class JetJavaLibCompletionTestGenerated extends AbstractJavaWithLibComple @TestMetadata("TopLevelNonImportedExtFun.kt") public void testTopLevelNonImportedExtFun() throws Exception { - doTestWithJar("idea/testData/completion/basic/custom/TopLevelNonImportedExtFun.kt"); + doTest("idea/testData/completion/basic/custom/TopLevelNonImportedExtFun.kt"); } @TestMetadata("TopLevelNonImportedFun.kt") public void testTopLevelNonImportedFun() throws Exception { - doTestWithJar("idea/testData/completion/basic/custom/TopLevelNonImportedFun.kt"); + doTest("idea/testData/completion/basic/custom/TopLevelNonImportedFun.kt"); } } diff --git a/idea/tests/org/jetbrains/jet/plugin/PluginTestCaseBase.java b/idea/tests/org/jetbrains/jet/plugin/PluginTestCaseBase.java index 731fcea1da5..f7d5967630f 100644 --- a/idea/tests/org/jetbrains/jet/plugin/PluginTestCaseBase.java +++ b/idea/tests/org/jetbrains/jet/plugin/PluginTestCaseBase.java @@ -20,16 +20,17 @@ import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.projectRoots.SdkModificator; import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; import com.intellij.openapi.roots.AnnotationOrderRootType; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.JetTestCaseBuilder; import org.jetbrains.jet.codegen.forTestCompile.ForTestPackJdkAnnotations; import java.io.File; public class PluginTestCaseBase { - public static final String TEST_DATA_PROJECT_RELATIVE = "/idea/testData"; private PluginTestCaseBase() { @@ -59,4 +60,7 @@ public class PluginTestCaseBase { return getSdk(javaHome); } + public static boolean isAllFilesPresentTest(@NotNull String testName) { + return StringUtil.startsWithIgnoreCase(testName, "allFilesPresentIn"); + } } diff --git a/idea/tests/org/jetbrains/jet/resolve/AbstractResolveWithLibTest.java b/idea/tests/org/jetbrains/jet/resolve/AbstractResolveWithLibTest.java index 96514f6f26e..bf5a9f4526b 100644 --- a/idea/tests/org/jetbrains/jet/resolve/AbstractResolveWithLibTest.java +++ b/idea/tests/org/jetbrains/jet/resolve/AbstractResolveWithLibTest.java @@ -18,20 +18,16 @@ package org.jetbrains.jet.resolve; import com.intellij.testFramework.LightProjectDescriptor; import org.jetbrains.jet.plugin.JdkAndMockLibraryProjectDescriptor; - -import static com.intellij.openapi.util.text.StringUtil.startsWithIgnoreCase; +import org.jetbrains.jet.plugin.PluginTestCaseBase; public abstract class AbstractResolveWithLibTest extends AbstractResolveBaseTest { - - private static final String TEST_DATA_PATH = "idea/testData/resolve/referenceWithLib"; - private static final String ALL_FILES_PRESENT_PREFIX = "allFilesPresentIn"; + private static final String TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/resolve/referenceWithLib"; @Override protected LightProjectDescriptor getProjectDescriptor() { - String testName = getTestName(true); - if (startsWithIgnoreCase(testName, ALL_FILES_PRESENT_PREFIX)) { + if (PluginTestCaseBase.isAllFilesPresentTest(getTestName(true))) { return null; } - return new JdkAndMockLibraryProjectDescriptor(TEST_DATA_PATH + "/" + testName + "Src", false); + return new JdkAndMockLibraryProjectDescriptor(TEST_DATA_PATH + "/" + getTestName(true) + "Src", false); } }