Example #1
0
  public static boolean testRefactoringTestEnvironment(File projectDirectory) {
    IdeMain.setTestMode(TestMode.CORE_TEST);
    TestMain.configureMPS();
    final Project project = loadProject(new File(projectDirectory, REFACTORING_PROJECT));

    final boolean[] b = new boolean[] {true};
    ModelAccess.instance()
        .runReadAction(
            new Runnable() {
              public void run() {
                b[0] =
                    getModel(project, REFACTORING_SANDBOX[0]) != null
                        && getModel(project, REFACTORING_SANDBOX[1]) != null
                        && getLanguage(project, REFACTORING_LANGUAGE[0]) != null
                        && getLanguage(project, REFACTORING_LANGUAGE[1]) != null;
              }
            });

    ThreadUtils.runInUIThreadNoWait(
        new Runnable() {
          public void run() {
            project.dispose();
          }
        });
    return b[0];
  }
Example #2
0
 public static void testProject(File projectFile, ProjectRunnable pr) {
   IdeMain.setTestMode(TestMode.CORE_TEST);
   Logger.setThreshold("INFO");
   org.apache.log4j.BasicConfigurator.configure();
   TestMain.configureMPS();
   final Project project = loadProject(projectFile);
   pr.execute(project);
 }
Example #3
0
  /**
   * Null result means no problems, not null result contains error description.
   *
   * @param projectFile
   * @return
   */
  public static TestResult testProject(
      File projectFile, boolean isRunnable, String[] configurations) {
    com.intellij.openapi.diagnostic.Logger.setFactory(LoggerFactory.getInstance());
    IdeMain.setTestMode(TestMode.CORE_TEST);
    long start = System.currentTimeMillis();
    configureMPS();

    System.out.println("loading project " + projectFile + "...");
    if (!projectFile.exists()) {
      throw new RuntimeException("Can't find a project in file " + projectFile.getAbsolutePath());
    }

    final Project project = loadProject(projectFile);
    TestResult result = new ProjectTester(project, isRunnable).testProject(configurations);

    ThreadUtils.runInUIThreadAndWait(
        new Runnable() {
          public void run() {
            project.dispose();

            IdeEventQueue.getInstance().flushQueue();
            gc();
          }
        });

    result.dump(System.out);

    if (!result.isOk()) {
      if (result.hasGenerationErrors()) {
        System.out.println("there were " + result.myGenerationErrors.size() + " generation error");
        for (String error : result.myGenerationErrors) {
          System.out.println(error);
        }
      }

      if (result.hasGenerationWarnings()) {
        System.out.println(
            "there were " + result.myGenerationWarnings.size() + " generation warnings");
        for (String warning : result.myGenerationWarnings) {
          System.out.println(warning);
        }
      }
      if (result.hasCompilationProblems()) {
        System.out.println(
            "there were " + result.myCompilationProblems.size() + " compilation problems");
        for (String compilationProblem : result.myCompilationProblems) {
          System.out.println(compilationProblem);
        }
      }
    }

    System.out.println("testing took " + (System.currentTimeMillis() - start) + " ms");

    return result;
  }
Example #4
0
  public static boolean testProjectGenerationForLeaks(File projectFile, int leakThreshold) {
    IdeMain.setTestMode(TestMode.CORE_TEST);

    TestMain.configureMPS();

    final Project project = loadProject(projectFile);
    return testActionForLeaks(
        new Runnable() {
          public void run() {
            new ProjectTester(project).testProject();
          }
        },
        leakThreshold);
  }
  private void updateAllWarnings(@Nullable VirtualFile vf) {
    if (IdeMain.getTestMode() == TestMode.CORE_TEST) return;

    for (FileEditor editor : myFileEditorManager.getAllEditors()) {
      if (editor instanceof MPSFileNodeEditor) {
        MPSFileNodeEditor mpsEditor = (MPSFileNodeEditor) editor;
        if (!mpsEditor.isDisposed()) {
          if (vf == null || vf.equals(mpsEditor.getFile())) {
            updateWarnings(mpsEditor);
          }
        }
      }
    }
  }
Example #6
0
  protected void init(Class<?> testClass) throws InitializationError {
    String projectPath = getProjectPath(testClass);
    MpsTestsSupport.initEnv(true);
    IdeMain.setTestMode(IdeMain.TestMode.CORE_TEST);
    initPathMacros();
    if (ourMPSProject != null) {
      throw new InitializationError(
          "One MPS project was already openned in this java process: "
              + ourMPSProject.getName()
              + " (on trying to open: "
              + projectPath
              + ")");
    }
    ourMPSProject = TestMain.PROJECT_CONTAINER.getProject(projectPath);

    // TODO:
    //
    // 2. Libraries?
    // 3. Cache location ?
    // 4. creste separate suite generating (making) all modules in this project by using
    // ProjectTestHelper?
    ModelAccess.instance().flushEventQueue();
  }
Example #7
0
 @BeforeClass
 public static void setUp() throws Exception {
   IdeMain.setTestMode(TestMode.CORE_TEST);
   TestMain.configureMPS();
 }
Example #8
0
  public static boolean testProjectReloadForLeaks(final File projectFile) {
    IdeMain.setTestMode(TestMode.CORE_TEST);

    return testProjectReloadForLeaks(projectFile, 1000);
  }
Example #9
0
  public static boolean testOnProjectCopy(
      final File source,
      final File destinationDir,
      final String projectName,
      ProjectRunnable pr,
      final String... plugins) {
    IdeMain.setTestMode(TestMode.CORE_TEST);
    Logger.setThreshold("WARN");
    org.apache.log4j.BasicConfigurator.configure();
    TestMain.configureMPS(plugins);

    if (destinationDir.exists()) {
      FileUtil.delete(destinationDir);
    }
    if (source.isDirectory()) {
      FileUtil.copyDir(source, destinationDir);
    } else { // it is allowed to have zipped directory here
      try {
        destinationDir.mkdir();
        UnzipUtil.unzip(source, destinationDir);
      } catch (IOException e) {
        e.printStackTrace();
        return false;
      }
    }

    final Project[] project = new MPSProject[] {null};
    try {
      // load a project
      ThreadUtils.runInUIThreadAndWait(
          new Runnable() {
            public void run() {
              try {
                project[0] = loadProject(new File(destinationDir, projectName));
                VirtualFile projectVirtualDir =
                    LocalFileSystem.getInstance().refreshAndFindFileByIoFile(destinationDir);
                assert projectVirtualDir != null;
                projectVirtualDir.refresh(false, true);
              } catch (Throwable t) {
                t.printStackTrace();
              }
            }
          });

      waitUntilAllEventsFlushed();

      // execute test
      return pr.execute(project[0]);
    } catch (Throwable t) {
      t.printStackTrace();
      return false;
    } finally {
      waitUntilAllEventsFlushed();

      // clean up
      ThreadUtils.runInUIThreadAndWait(
          new Runnable() {
            public void run() {
              if (project[0] != null) {
                project[0].dispose();
              }
              FileUtil.delete(destinationDir);
            }
          });
    }
  }