check class names in slowTests.txt for correctness
authorAlexey Kudravtsev <cdr@intellij.com>
Wed, 7 Jul 2010 08:57:30 +0000 (12:57 +0400)
committerAlexey Kudravtsev <cdr@intellij.com>
Wed, 7 Jul 2010 09:06:30 +0000 (13:06 +0400)
platform/testFramework/src/com/intellij/TestAll.java
platform/testFramework/src/com/intellij/TestCaseLoader.java

index 5cff8eaff5467cc043d7269d50e10d26f745ffd4..af5f8ba76192286bcf26b5efa954977b5b45677a 100644 (file)
@@ -48,8 +48,6 @@ public class TestAll implements Test {
     Logger.setFactory(TestLoggerFactory.getInstance());
   }
 
-  private static final Logger LOG = Logger.getInstance("#com.intellij.TestAll");
-
   private TestCaseLoader myTestCaseLoader;
   private long myStartTime = 0;
   private final boolean myInterruptedByOutOfMemory = false;
@@ -70,7 +68,7 @@ public class TestAll implements Test {
   public static final int MAX_FAILURE_TEST_COUNT = 150;
 
   public int countTestCases() {
-    List classes = myTestCaseLoader.getClasses();
+    List<Class> classes = myTestCaseLoader.getClasses();
 
     int count = 0;
 
@@ -135,12 +133,7 @@ public class TestAll implements Test {
     if (PlatformTestCase.ourTestThread != null) {
       return PlatformTestCase.ourTestThread;
     }
-    else if (LightPlatformTestCase.ourTestThread != null) {
-      return LightPlatformTestCase.ourTestThread;
-    }
-    else {
-      return null;
-    }
+    else return LightPlatformTestCase.ourTestThread;
   }
 
   private void addErrorMessage(TestResult testResult, String message) {
@@ -156,10 +149,10 @@ public class TestAll implements Test {
   }
 
   public void run(final TestResult testResult) {
-    List classes = myTestCaseLoader.getClasses();
+    List<Class> classes = myTestCaseLoader.getClasses();
     int totalTests = classes.size();
-    for (final Object aClass : classes) {
-      runNextTest(testResult, totalTests, (Class)aClass);
+    for (final Class aClass : classes) {
+      runNextTest(testResult, totalTests, aClass);
       if (testResult.shouldStop()) break;
     }
     tryGc(10);
@@ -369,6 +362,7 @@ public class TestAll implements Test {
     }
 
     log("Number of test classes found: " + myTestCaseLoader.getClasses().size());
+    myTestCaseLoader.checkClassesExist();
   }
 
   private static void log(String message) {
index df90ffa7714e818313dc0217e4e191596549d2d9..afb2677749d5748254eaf637c6d20ebd59ddc468 100644 (file)
@@ -26,6 +26,7 @@ package com.intellij;
 
 import com.intellij.idea.Bombed;
 import com.intellij.openapi.util.Comparing;
+import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.testFramework.PlatformTestUtil;
 import com.intellij.testFramework.TestRunnerUtil;
@@ -54,6 +55,7 @@ public class TestCaseLoader {
   private final TestClassesFilter myTestClassesFilter;
   private final String myTestGroupName;
   private final Set<String> blockedTests = new HashSet<String>();
+  private final String[] slowTestNames;
 
   public TestCaseLoader(String classFilterName) {
     InputStream excludedStream = getClass().getClassLoader().getResourceAsStream(classFilterName);
@@ -86,27 +88,39 @@ public class TestCaseLoader {
       }
     }
 
+    String[] names;
+    try {
+      InputStream stream = getClass().getClassLoader().getResourceAsStream("tests/slowTests.txt");
+      names = FileUtil.loadTextAndClose(new InputStreamReader(stream)).split("\\s");
+    }
+    catch (Exception e) {
+      // no luck
+      names = new String[0];
+    }
+    slowTestNames = names;
     if (Comparing.equal(System.getProperty(FAST_TESTS_ONLY_FLAG), "true")) {
-      BufferedReader reader =
-              new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("tests/slowTests.txt")));
+      blockedTests.addAll(Arrays.asList(slowTestNames));
+    }
+    else {
+      checkClassesExist();
+    }
+    System.out.println("Using test group: [" + myTestGroupName +"]");
+  }
+
+  void checkClassesExist() {
+    String s = "";
+    for (String slowTestName : slowTestNames) {
+      if (slowTestName.trim().length() == 0) continue;
       try {
-        String testName;
-        while ((testName = reader.readLine()) != null) {
-          blockedTests.add(testName);
-        }
+        Class.forName(slowTestName);
       }
-      catch (IOException e) {
-        // No luck
-      } finally {
-        try {
-          reader.close();
-        }
-        catch (IOException e) {
-          // ignore
-        }
+      catch (ClassNotFoundException e) {
+        s += "\n" + slowTestName;
       }
     }
-    System.out.println("Using test group: [" + myTestGroupName + "]");
+    if (s.length() != 0) {
+      throw new RuntimeException("Tests in slowTests.txt which cannot be instantiated: "+s);
+    }
   }
 
   /*