public void testMissingDependencyJavaConflictingLibraries() throws Exception {
   File library1 = deletePaths(compileJava("library1"), "test/A.class", "test/A$Inner.class");
   File library2 = deletePaths(compileJava("library2"), "test/A.class", "test/A$Inner.class");
   Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, library1, library2);
   KotlinTestUtils.assertEqualsToFile(
       new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output));
 }
Esempio n. 2
0
  public static void compileJavaFiles(
      @NotNull Collection<File> files, List<String> options, @Nullable File javaErrorFile)
      throws IOException {
    JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
    DiagnosticCollector<JavaFileObject> diagnosticCollector =
        new DiagnosticCollector<JavaFileObject>();
    StandardJavaFileManager fileManager =
        javaCompiler.getStandardFileManager(
            diagnosticCollector, Locale.ENGLISH, Charset.forName("utf-8"));
    try {
      Iterable<? extends JavaFileObject> javaFileObjectsFromFiles =
          fileManager.getJavaFileObjectsFromFiles(files);

      JavaCompiler.CompilationTask task =
          javaCompiler.getTask(
              new StringWriter(), // do not write to System.err
              fileManager,
              diagnosticCollector,
              options,
              null,
              javaFileObjectsFromFiles);

      Boolean success = task.call(); // do NOT inline this variable, call() should complete before
      // errorsToString()
      if (javaErrorFile == null || !javaErrorFile.exists()) {
        Assert.assertTrue(errorsToString(diagnosticCollector, true), success);
      } else {
        assertEqualsToFile(javaErrorFile, errorsToString(diagnosticCollector, false));
      }
    } finally {
      fileManager.close();
    }
  }
 private void doTestBrokenKotlinLibrary(
     @NotNull String libraryName, @NotNull String... pathsToDelete) throws Exception {
   // Analogous to doTestBrokenJavaLibrary, but with a Kotlin library compiled to a JAR file
   File library = copyJarFileWithoutEntry(compileLibrary(libraryName), pathsToDelete);
   Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, library);
   KotlinTestUtils.assertEqualsToFile(
       new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output));
 }
Esempio n. 4
0
  public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull Editor editor) {
    String actualText = editor.getDocument().getText();
    String afterText =
        new StringBuilder(actualText)
            .insert(editor.getCaretModel().getOffset(), "<caret>")
            .toString();

    assertEqualsToFile(expectedFile, afterText);
  }
Esempio n. 5
0
 public static void assertEqualsToFile(@NotNull File expectedFile, @NotNull String actual) {
   assertEqualsToFile(
       expectedFile,
       actual,
       new Function1<String, String>() {
         @Override
         public String invoke(String s) {
           return s;
         }
       });
 }
  private void doTestBrokenJavaLibrary(
      @NotNull String libraryName, @NotNull String... pathsToDelete) throws Exception {
    // This function compiles a Java library, then deletes one class file and attempts to compile a
    // Kotlin source against
    // this broken library. The expected result is an error message from the compiler
    File library = deletePaths(compileJava(libraryName), pathsToDelete);

    Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, library);
    KotlinTestUtils.assertEqualsToFile(
        new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output));
  }
  public void testRawTypes() throws Exception {
    KotlinTestUtils.compileJavaFiles(
        Collections.singletonList(new File(getTestDataDirectory() + "/library/test/A.java")),
        Arrays.asList("-d", tmpdir.getPath()));

    Pair<String, ExitCode> outputLib = compileKotlin("library/test/lib.kt", tmpdir, tmpdir);

    Pair<String, ExitCode> outputMain = compileKotlin("main.kt", tmpdir, tmpdir);

    KotlinTestUtils.assertEqualsToFile(
        new File(getTestDataDirectory(), "output.txt"),
        normalizeOutput(outputLib) + "\n" + normalizeOutput(outputMain));
  }