Ejemplo n.º 1
0
  private static void checkForUnexpectedErrors() {
    AnalyzeExhaust exhaust =
        WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile((JetFile) getFile());
    Collection<Diagnostic> diagnostics = exhaust.getBindingContext().getDiagnostics();

    if (diagnostics.size() != 0) {
      String[] expectedErrorStrings =
          InTextDirectivesUtils.findListWithPrefix("// ERROR:", getFile().getText());

      System.out.println(getFile().getText());

      Collection<String> expectedErrors = new HashSet<String>(Arrays.asList(expectedErrorStrings));

      StringBuilder builder = new StringBuilder();
      boolean hasErrors = false;

      for (Diagnostic diagnostic : diagnostics) {
        if (diagnostic.getSeverity() == Severity.ERROR) {
          String errorText = IdeErrorMessages.RENDERER.render(diagnostic);
          if (!expectedErrors.contains(errorText)) {
            hasErrors = true;
            builder.append("// ERROR: ").append(errorText).append("\n");
          }
        }
      }

      Assert.assertFalse(
          "There should be no unexpected errors after applying fix (Use \"// ERROR:\" directive): \n"
              + builder.toString(),
          hasErrors);
    }
  }
Ejemplo n.º 2
0
  protected void doTest() {
    try {
      final String testName = getTestName(false);
      configureByFileNoComplete(testName + ".kt");

      final String fileText = getFile().getText();
      type = getCompletionType(testName, fileText);

      boolean withKotlinRuntime =
          InTextDirectivesUtils.getPrefixedInt(fileText, "// RUNTIME:") != null;

      try {
        if (withKotlinRuntime) {
          ConfigRuntimeUtil.configureKotlinRuntime(getModule(), getFullJavaJDK());
        }

        Integer completionTime = completionUtils.getExecutionTime(fileText);

        complete(completionTime == null ? 1 : completionTime);

        ExpectedCompletionUtils.CompletionProposal[] expected =
            completionUtils.itemsShouldExist(fileText);
        ExpectedCompletionUtils.CompletionProposal[] unexpected =
            completionUtils.itemsShouldAbsent(fileText);
        Integer itemsNumber = completionUtils.getExpectedNumber(fileText);

        assertTrue(
            "Should be some assertions about completion",
            expected.length != 0 || unexpected.length != 0 || itemsNumber != null);

        if (myItems == null) {
          myItems = new LookupElement[0];
        }

        ExpectedCompletionUtils.assertContainsRenderedItems(
            expected, myItems, completionUtils.isWithOrder(fileText));
        ExpectedCompletionUtils.assertNotContainsRenderedItems(unexpected, myItems);

        if (itemsNumber != null) {
          assertEquals(
              String.format(
                  "Invalid number of completion items: %s",
                  ExpectedCompletionUtils.listToString(
                      ExpectedCompletionUtils.getItemsInformation(myItems))),
              itemsNumber.intValue(),
              myItems.length);
        }
      } finally {
        if (withKotlinRuntime) {
          ConfigRuntimeUtil.unConfigureKotlinRuntime(getModule(), getProjectJDK());
        }
      }
    } catch (Exception e) {
      throw new AssertionError(e);
    }
  }