Search in sources :

Example 1 with ExitCode

use of org.jetbrains.kotlin.cli.common.ExitCode in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method testWrongInlineTarget.

public void testWrongInlineTarget() throws Exception {
    File library = compileLibrary("library", Arrays.asList("-jvm-target", "1.8"));
    Pair<String, ExitCode> outputMain = compileKotlin("source.kt", tmpdir, library);
    KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(outputMain));
}
Also used : ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) JarFile(java.util.jar.JarFile) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File)

Example 2 with ExitCode

use of org.jetbrains.kotlin.cli.common.ExitCode in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method testMissingDependencyConflictingLibraries.

public void testMissingDependencyConflictingLibraries() throws Exception {
    File library1 = copyJarFileWithoutEntry(compileLibrary("library1"), "a/A.class", "a/A$Inner.class", "a/AA.class", "a/AA$Inner.class");
    File library2 = copyJarFileWithoutEntry(compileLibrary("library2"), "a/A.class", "a/A$Inner.class", "a/AA.class", "a/AA$Inner.class");
    Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, library1, library2);
    KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output));
}
Also used : ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) JarFile(java.util.jar.JarFile) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File)

Example 3 with ExitCode

use of org.jetbrains.kotlin.cli.common.ExitCode in project kotlin by JetBrains.

the class AbstractCliTest method executeCompilerGrabOutput.

@NotNull
public static Pair<String, ExitCode> executeCompilerGrabOutput(@NotNull CLICompiler<?> compiler, @NotNull List<String> args) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    PrintStream origErr = System.err;
    try {
        System.setErr(new PrintStream(bytes));
        ExitCode exitCode = CLICompiler.doMainNoExit(compiler, ArrayUtil.toStringArray(args));
        return new Pair<String, ExitCode>(bytes.toString("utf-8"), exitCode);
    } catch (Exception e) {
        throw ExceptionUtilsKt.rethrow(e);
    } finally {
        System.setErr(origErr);
    }
}
Also used : PrintStream(java.io.PrintStream) ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Pair(kotlin.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ExitCode

use of org.jetbrains.kotlin.cli.common.ExitCode in project kotlin by JetBrains.

the class CompileMavenGeneratedJSLibrary method generateJavaScriptFiles.

private void generateJavaScriptFiles(@NotNull Iterable<EcmaVersion> ecmaVersions, @NotNull String sourceDir, @NotNull String... stdLibFiles) throws Exception {
    List<String> files = Lists.newArrayList();
    // now lets add all the files from the definitions and library
    //addAllSourceFiles(files, generatedJsDefinitionsDir);
    addAllSourceFiles(files, generatedJsLibraryDir);
    File stdlibDir = new File(sourceDir);
    assertTrue("Cannot find stdlib test source: " + stdlibDir, stdlibDir.exists());
    for (String file : stdLibFiles) {
        files.add(new File(stdlibDir, file).getPath());
    }
    // now lets try invoke the compiler
    for (EcmaVersion version : ecmaVersions) {
        String outputFile = getOutputFilePath(getTestName(false) + ".compiler.kt", version);
        System.out.println("Compiling with version: " + version + " to: " + outputFile);
        List<String> args = new ArrayList<String>(Arrays.asList("-output", outputFile, "-libraries", generatedJsDefinitionsDir, "-verbose"));
        args.addAll(files);
        ExitCode answer = new K2JSCompiler().exec(System.out, ArrayUtil.toStringArray(args));
        assertEquals("Compile failed", ExitCode.OK, answer);
    }
}
Also used : K2JSCompiler(org.jetbrains.kotlin.cli.js.K2JSCompiler) ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) ArrayList(java.util.ArrayList) EcmaVersion(org.jetbrains.kotlin.js.config.EcmaVersion) File(java.io.File)

Example 5 with ExitCode

use of org.jetbrains.kotlin.cli.common.ExitCode in project kotlin by JetBrains.

the class CompileKotlinAgainstCustomBinariesTest method testProhibitNestedClassesByDollarName.

public void testProhibitNestedClassesByDollarName() throws Exception {
    File library = compileLibrary("library");
    KotlinTestUtils.compileJavaFiles(Collections.singletonList(new File(getTestDataDirectory() + "/library/test/JavaOuter.java")), Arrays.asList("-d", tmpdir.getPath()));
    Pair<String, ExitCode> outputMain = compileKotlin("main.kt", tmpdir, tmpdir, library);
    KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(outputMain));
}
Also used : ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) JarFile(java.util.jar.JarFile) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File)

Aggregations

ExitCode (org.jetbrains.kotlin.cli.common.ExitCode)19 File (java.io.File)15 JarFile (java.util.jar.JarFile)12 RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile (org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile)12 NotNull (org.jetbrains.annotations.NotNull)2 Disposable (com.intellij.openapi.Disposable)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 ArrayList (java.util.ArrayList)1 Pair (kotlin.Pair)1 Function2 (kotlin.jvm.functions.Function2)1 K2JSCompiler (org.jetbrains.kotlin.cli.js.K2JSCompiler)1 K2JVMCompiler (org.jetbrains.kotlin.cli.jvm.K2JVMCompiler)1 EcmaVersion (org.jetbrains.kotlin.js.config.EcmaVersion)1 JvmMetadataVersion (org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion)1 CompilationCanceledException (org.jetbrains.kotlin.progress.CompilationCanceledException)1 CompilationCanceledStatus (org.jetbrains.kotlin.progress.CompilationCanceledStatus)1 ProgressIndicatorAndCompilationCanceledStatus (org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus)1 DescriptorUtils.isObject (org.jetbrains.kotlin.resolve.DescriptorUtils.isObject)1