update test framework to ensure compiled before search for tests
authorAnna.Kozlova <anna.kozlova@jetbrains.com>
Tue, 8 Aug 2017 14:22:26 +0000 (16:22 +0200)
committerAnna.Kozlova <anna.kozlova@jetbrains.com>
Tue, 8 Aug 2017 15:42:39 +0000 (17:42 +0200)
15 files changed:
java/execution/impl/src/com/intellij/execution/TestClassCollector.java
java/java-tests/testData/junit/configurations/mock JUnit/org/junit/Test.class [new file with mode: 0644]
java/java-tests/testData/junit/configurations/mock JUnit/org/junit/Test.java [new file with mode: 0644]
java/java-tests/testData/junit/configurations/mock JUnit/org/junit/runner/RunWith.class [new file with mode: 0644]
java/java-tests/testData/junit/configurations/mock JUnit/org/junit/runner/RunWith.java [new file with mode: 0644]
java/java-tests/testData/junit/configurations/outputs/general 1/keep.dir [deleted file]
java/java-tests/testData/junit/configurations/outputs/general 2/keep.dir [deleted file]
java/java-tests/testData/junit/configurations/outputs/general 3/keep.dir [deleted file]
java/java-tests/testData/junit/configurations/outputs/general 4/keep.dir [deleted file]
java/java-tests/testData/junit/configurations/outputs/tests1/keep.dir [deleted file]
java/java-tests/testData/junit/configurations/outputs/tests2/keep.dir [deleted file]
java/java-tests/testData/junit/configurations/outputs/tests3/keep.dir [deleted file]
java/java-tests/testData/junit/configurations/outputs/tests4/keep.dir [deleted file]
java/java-tests/testSrc/com/intellij/java/execution/ConfigurationsTest.java
plugins/junit/test/com/intellij/execution/junit/JUnitClasspathTest.java

index 9183274a70d8257812c3b8b5f0aa0911e61ce09c..b00de4d4ea116dcb74e8e223259776a5fa831087 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.execution;
 
+import com.intellij.execution.testframework.TestSearchScope;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.roots.CompilerModuleExtension;
@@ -50,7 +51,7 @@ public class TestClassCollector {
     Module module = configuration.getConfigurationModule().getModule();
     List<URL> urls = new ArrayList<>();
 
-    PathsList pathsList = (module == null ? OrderEnumerator.orderEntries(configuration.getProject()) : OrderEnumerator.orderEntries(module))
+    PathsList pathsList = (module == null || configuration.getTestSearchScope() == TestSearchScope.WHOLE_PROJECT ? OrderEnumerator.orderEntries(configuration.getProject()) : OrderEnumerator.orderEntries(module))
       .runtimeOnly().recursively().getPathsList(); //include jdk to avoid NoClassDefFoundError for classes inside tools.jar
     for (VirtualFile file : pathsList.getVirtualFiles()) {
       try {
diff --git a/java/java-tests/testData/junit/configurations/mock JUnit/org/junit/Test.class b/java/java-tests/testData/junit/configurations/mock JUnit/org/junit/Test.class
new file mode 100644 (file)
index 0000000..7123197
Binary files /dev/null and b/java/java-tests/testData/junit/configurations/mock JUnit/org/junit/Test.class differ
diff --git a/java/java-tests/testData/junit/configurations/mock JUnit/org/junit/Test.java b/java/java-tests/testData/junit/configurations/mock JUnit/org/junit/Test.java
new file mode 100644 (file)
index 0000000..66c78b4
--- /dev/null
@@ -0,0 +1,2 @@
+package org.junit;
+public @interface Test {}
\ No newline at end of file
diff --git a/java/java-tests/testData/junit/configurations/mock JUnit/org/junit/runner/RunWith.class b/java/java-tests/testData/junit/configurations/mock JUnit/org/junit/runner/RunWith.class
new file mode 100644 (file)
index 0000000..e059434
Binary files /dev/null and b/java/java-tests/testData/junit/configurations/mock JUnit/org/junit/runner/RunWith.class differ
diff --git a/java/java-tests/testData/junit/configurations/mock JUnit/org/junit/runner/RunWith.java b/java/java-tests/testData/junit/configurations/mock JUnit/org/junit/runner/RunWith.java
new file mode 100644 (file)
index 0000000..b4b9e99
--- /dev/null
@@ -0,0 +1,4 @@
+package org.junit.runner;
+@interface RunWith {
+    Class<? extends Runner> value();
+}
diff --git a/java/java-tests/testData/junit/configurations/outputs/general 1/keep.dir b/java/java-tests/testData/junit/configurations/outputs/general 1/keep.dir
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/java/java-tests/testData/junit/configurations/outputs/general 2/keep.dir b/java/java-tests/testData/junit/configurations/outputs/general 2/keep.dir
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/java/java-tests/testData/junit/configurations/outputs/general 3/keep.dir b/java/java-tests/testData/junit/configurations/outputs/general 3/keep.dir
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/java/java-tests/testData/junit/configurations/outputs/general 4/keep.dir b/java/java-tests/testData/junit/configurations/outputs/general 4/keep.dir
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/java/java-tests/testData/junit/configurations/outputs/tests1/keep.dir b/java/java-tests/testData/junit/configurations/outputs/tests1/keep.dir
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/java/java-tests/testData/junit/configurations/outputs/tests2/keep.dir b/java/java-tests/testData/junit/configurations/outputs/tests2/keep.dir
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/java/java-tests/testData/junit/configurations/outputs/tests3/keep.dir b/java/java-tests/testData/junit/configurations/outputs/tests3/keep.dir
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/java/java-tests/testData/junit/configurations/outputs/tests4/keep.dir b/java/java-tests/testData/junit/configurations/outputs/tests4/keep.dir
deleted file mode 100644 (file)
index e69de29..0000000
index 36b6f5f857813a42be5f56831184c7be1832f84c..801f15f94e3ba5fdc843e69ba1e6a268abfe8b13 100644 (file)
@@ -33,14 +33,17 @@ import com.intellij.execution.runners.ExecutionEnvironmentBuilder;
 import com.intellij.execution.testframework.SearchForTestsTask;
 import com.intellij.execution.testframework.TestSearchScope;
 import com.intellij.execution.ui.CommonJavaParametersPanel;
+import com.intellij.openapi.Disposable;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleManager;
 import com.intellij.openapi.options.Configurable;
 import com.intellij.openapi.options.ConfigurationException;
+import com.intellij.openapi.project.Project;
 import com.intellij.openapi.projectRoots.Sdk;
 import com.intellij.openapi.roots.*;
 import com.intellij.openapi.ui.LabeledComponent;
 import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.JarFileSystem;
 import com.intellij.openapi.vfs.LocalFileSystem;
@@ -49,6 +52,7 @@ import com.intellij.psi.*;
 import com.intellij.psi.search.GlobalSearchScope;
 import com.intellij.rt.ant.execution.SegmentedOutputStream;
 import com.intellij.rt.execution.junit.JUnitStarter;
+import com.intellij.testFramework.CompilerTester;
 import com.intellij.testFramework.MapDataContext;
 import com.intellij.testFramework.PlatformTestUtil;
 import com.intellij.testFramework.PsiTestUtil;
@@ -61,10 +65,7 @@ import junit.framework.TestCase;
 import org.jdom.Element;
 
 import java.io.*;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.StringTokenizer;
+import java.util.*;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -182,7 +183,7 @@ public class ConfigurationsTest extends BaseConfigurationTestCase {
     List<String> lines = extractAllInPackageTests(parameters, psiPackage);
     Assertion.compareUnordered(
       //category, filters, classNames...
-      new Object[]{"", "", psiClass.getQualifiedName(), psiClass2.getQualifiedName(), derivedTest.getQualifiedName(), RT_INNER_TEST_NAME,
+      new Object[]{"", "", psiClass.getQualifiedName(), derivedTest.getQualifiedName(), RT_INNER_TEST_NAME,
         testB.getQualifiedName()},
       lines);
   }
@@ -446,7 +447,7 @@ public class ConfigurationsTest extends BaseConfigurationTestCase {
     return PathUtil.getLocalPath(output);
   }
 
-  private static String[] addOutputs(Module module, int index) {
+  private String[] addOutputs(Module module, int index) {
     String[] outputs = new String[2];
     String prefix = "outputs" + File.separatorChar;
     VirtualFile generalOutput = findFile(prefix + "general " + index);
@@ -455,6 +456,13 @@ public class ConfigurationsTest extends BaseConfigurationTestCase {
     outputs[1] = testOutput.getPresentableUrl();
     PsiTestUtil.setCompilerOutputPath(module, generalOutput.getUrl(), false);
     PsiTestUtil.setCompilerOutputPath(module, testOutput.getUrl(), true);
+    Disposer.register(getTestRootDisposable(), new Disposable() {
+      @Override
+      public void dispose() {
+        FileUtil.delete(new File(outputs[0]));
+        FileUtil.delete(new File(outputs[1]));
+      }
+    });
     return outputs;
   }
 
@@ -468,7 +476,20 @@ public class ConfigurationsTest extends BaseConfigurationTestCase {
       final JavaParameters parameters = ((TestPackage)state).getJavaParameters();
       final SearchForTestsTask task = ((TestPackage)state).createSearchingForTestsTask();
       assertNotNull(task);
-      task.startSearch();
+      Project project = configuration.getProject();
+      try {
+        CompilerTester tester = new CompilerTester(project, Arrays.asList(ModuleManager.getInstance(project).getModules()));
+        try {
+          tester.rebuild();
+          task.startSearch();
+        }
+        finally {
+          tester.tearDown();
+        }
+      }
+      catch (Exception e) {
+        fail(e.getMessage());
+      }
     }
     try {
       configuration.checkConfiguration();
index b5b753d7049204dadbac685c9ba9931a530b7348..1f827ed49d859ee6a1feb2df02afee32a24bf9f9 100644 (file)
@@ -21,10 +21,12 @@ import com.intellij.execution.runners.ExecutionEnvironmentBuilder;
 import com.intellij.execution.testframework.TestSearchScope;
 import com.intellij.openapi.module.JavaModuleType;
 import com.intellij.openapi.module.Module;
+import com.intellij.openapi.module.ModuleManager;
 import com.intellij.openapi.roots.ModuleRootManager;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.testFramework.CompilerTester;
 import com.intellij.testFramework.IdeaTestUtil;
 import com.intellij.testFramework.PsiTestUtil;
 import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
@@ -33,76 +35,90 @@ import junit.framework.TestCase;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Arrays;
 
 public class JUnitClasspathTest extends JavaCodeInsightFixtureTestCase {
 
   public void testWorkingDirsFileWhenConfigurationSpansToMultipleModules() throws Exception {
     final Module mod1 = setupModule("mod1", "T1");
     final Module mod2 = setupModule("mod2", "T2");
+    CompilerTester compiler = new CompilerTester(myFixture.getProject(), Arrays.asList(ModuleManager.getInstance(myFixture.getProject()).getModules()));
+    compiler.rebuild();
+    try {
+      final JUnitConfiguration configuration =
+        new JUnitConfiguration("p", getProject(), JUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
+      configuration.setWorkingDirectory("$MODULE_DIR$");
+      final JUnitConfiguration.Data persistentData = configuration.getPersistentData();
+      persistentData.setScope(TestSearchScope.SINGLE_MODULE);
+      configuration.setModule(mod1);
+      persistentData.PACKAGE_NAME = "p";
+      persistentData.TEST_OBJECT = JUnitConfiguration.TEST_PACKAGE;
 
-    final JUnitConfiguration configuration =
-      new JUnitConfiguration("p", getProject(), JUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
-    configuration.setWorkingDirectory("$MODULE_DIR$");
-    final JUnitConfiguration.Data persistentData = configuration.getPersistentData();
-    persistentData.setScope(TestSearchScope.SINGLE_MODULE);
-    configuration.setModule(mod1);
-    persistentData.PACKAGE_NAME = "p";
-    persistentData.TEST_OBJECT = JUnitConfiguration.TEST_PACKAGE;
+      final ExecutionEnvironment environment =
+        ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), configuration).build();
+      final TestPackage aPackage = new TestPackage(configuration, environment) {
+        @Override
+        protected boolean createTempFiles() {
+          return true;
+        }
+      };
 
-    final ExecutionEnvironment environment =
-      ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), configuration).build();
-    final TestPackage aPackage = new TestPackage(configuration, environment) {
-      @Override
-      protected boolean createTempFiles() {
-        return true;
-      }
-    };
+      //ensure no fork if single module is selected
+      aPackage.createSearchingForTestsTask().startSearch();
+      File workingDirsFile = aPackage.getWorkingDirsFile();
+      assertNotNull(workingDirsFile);
+      assertEmpty(FileUtil.loadFile(workingDirsFile));
 
-    //ensure no fork if single module is selected
-    aPackage.createSearchingForTestsTask().startSearch();
-    File workingDirsFile = aPackage.getWorkingDirsFile();
-    assertNotNull(workingDirsFile);
-    assertEmpty(FileUtil.loadFile(workingDirsFile));
-
-    //ensure fork when whole project is used
-    persistentData.setScope(TestSearchScope.WHOLE_PROJECT);
-    aPackage.createSearchingForTestsTask().startSearch();
-    workingDirsFile = aPackage.getWorkingDirsFile();
-    assertNotNull(workingDirsFile);
-    String file;
-    aPackage.createSearchingForTestsTask().startSearch();
-    workingDirsFile = aPackage.getWorkingDirsFile();
-    assertNotNull(workingDirsFile);
-    file = preparePathsForComparison(FileUtil.loadFile(workingDirsFile), mod1, mod2);
-    assertEquals("p\n" +
-                 "MODULE_1\n" +
-                 "mod1\n" +
-                 "CLASSPATH\n" +
-                 "1\n" +
-                 "p.T1\n" +
-                 "MODULE_2\n" +
-                 "mod2\n" +
-                 "CLASSPATH\n" +
-                 "1\n" +
-                 "p.T2", file);
+      //ensure fork when whole project is used
+      persistentData.setScope(TestSearchScope.WHOLE_PROJECT);
+      aPackage.createSearchingForTestsTask().startSearch();
+      workingDirsFile = aPackage.getWorkingDirsFile();
+      assertNotNull(workingDirsFile);
+      String file;
+      aPackage.createSearchingForTestsTask().startSearch();
+      workingDirsFile = aPackage.getWorkingDirsFile();
+      assertNotNull(workingDirsFile);
+      file = preparePathsForComparison(FileUtil.loadFile(workingDirsFile), mod1, mod2);
+      assertEquals("p\n" +
+                   "MODULE_1\n" +
+                   "mod1\n" +
+                   "CLASSPATH\n" +
+                   "1\n" +
+                   "p.T1\n" +
+                   "MODULE_2\n" +
+                   "mod2\n" +
+                   "CLASSPATH\n" +
+                   "1\n" +
+                   "p.T2", file);
+    }
+    finally {
+      compiler.tearDown();
+    }
   }
 
   public void testNoWorkingDirsFileWhenOnlyOneModuleExist() throws Exception {
     setupModule("mod1", "T1");
-    final JUnitConfiguration configuration =
-      new JUnitConfiguration("p", getProject(), JUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
-    configuration.setWorkingDirectory("$MODULE_DIR$");
-    final JUnitConfiguration.Data persistentData = configuration.getPersistentData();
-    persistentData.setScope(TestSearchScope.WHOLE_PROJECT);
-    persistentData.PACKAGE_NAME = "p";
-    persistentData.TEST_OBJECT = JUnitConfiguration.TEST_PACKAGE;
-    final ExecutionEnvironment environment =
-      ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), configuration).build();
-    final TestPackage aPackage = new TestPackage(configuration, environment);
-    aPackage.createSearchingForTestsTask().startSearch();
-    final File workingDirsFile = aPackage.getWorkingDirsFile();
-    assertNotNull(workingDirsFile);
-    assertEmpty(FileUtil.loadFile(workingDirsFile));
+    CompilerTester compiler = new CompilerTester(getProject(), Arrays.asList(ModuleManager.getInstance(getProject()).getModules()));
+    compiler.rebuild();
+    try {
+      final JUnitConfiguration configuration =
+        new JUnitConfiguration("p", getProject(), JUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
+      configuration.setWorkingDirectory("$MODULE_DIR$");
+      final JUnitConfiguration.Data persistentData = configuration.getPersistentData();
+      persistentData.setScope(TestSearchScope.WHOLE_PROJECT);
+      persistentData.PACKAGE_NAME = "p";
+      persistentData.TEST_OBJECT = JUnitConfiguration.TEST_PACKAGE;
+      final ExecutionEnvironment environment =
+        ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), configuration).build();
+      final TestPackage aPackage = new TestPackage(configuration, environment);
+      aPackage.createSearchingForTestsTask().startSearch();
+      final File workingDirsFile = aPackage.getWorkingDirsFile();
+      assertNotNull(workingDirsFile);
+      assertEmpty(FileUtil.loadFile(workingDirsFile));
+    }
+    finally {
+      compiler.tearDown();
+    }
   }
 
   private Module setupModule(String moduleName, final String className) throws IOException {