Search in sources :

Example 16 with ExitCode

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

the class CompileEnvironmentTest method testSmokeWithCompilerOutput.

public void testSmokeWithCompilerOutput() throws IOException {
    File tempDir = FileUtil.createTempDirectory("compilerTest", "compilerTest");
    try {
        File out = new File(tempDir, "out");
        File stdlib = ForTestCompileRuntime.runtimeJarForTests();
        ExitCode exitCode = new K2JVMCompiler().exec(System.out, KotlinTestUtils.getTestDataPathBase() + "/compiler/smoke/Smoke.kt", "-d", out.getAbsolutePath(), "-no-stdlib", "-classpath", stdlib.getAbsolutePath());
        Assert.assertEquals(ExitCode.OK, exitCode);
        File[] files = out.listFiles();
        Arrays.sort(files);
        assertEquals(2, files.length);
        //META-INF
        assertEquals(1, files[0].listFiles().length);
        // SmokeKt
        assertEquals(1, files[1].listFiles().length);
    } finally {
        FileUtil.delete(tempDir);
    }
}
Also used : ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) K2JVMCompiler(org.jetbrains.kotlin.cli.jvm.K2JVMCompiler) File(java.io.File)

Example 17 with ExitCode

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

the class CompileKotlinAgainstCustomBinariesTest method doTestKotlinLibraryWithWrongMetadataVersion.

private void doTestKotlinLibraryWithWrongMetadataVersion(@NotNull String libraryName, @Nullable final Function2<String, Object, Object> additionalTransformation, @NotNull String... additionalOptions) throws Exception {
    final int[] version = new JvmMetadataVersion(42, 0, 0).toArray();
    File library = transformJar(compileLibrary(libraryName), new Function2<String, byte[], byte[]>() {

        @Override
        public byte[] invoke(String name, byte[] bytes) {
            return WrongBytecodeVersionTest.Companion.transformMetadataInClassFile(bytes, new Function2<String, Object, Object>() {

                @Override
                public Object invoke(String name, Object value) {
                    if (additionalTransformation != null) {
                        Object result = additionalTransformation.invoke(name, value);
                        if (result != null)
                            return result;
                    }
                    return JvmAnnotationNames.METADATA_VERSION_FIELD_NAME.equals(name) ? version : null;
                }
            });
        }
    });
    Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, Arrays.asList(additionalOptions), library);
    KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output));
}
Also used : JvmMetadataVersion(org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion) ExitCode(org.jetbrains.kotlin.cli.common.ExitCode) DescriptorUtils.isObject(org.jetbrains.kotlin.resolve.DescriptorUtils.isObject) Function2(kotlin.jvm.functions.Function2) JarFile(java.util.jar.JarFile) RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile) File(java.io.File)

Example 18 with ExitCode

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

the class CompileKotlinAgainstCustomBinariesTest method testTypeAliasesAreInvisibleInCompatibilityMode.

public void testTypeAliasesAreInvisibleInCompatibilityMode() {
    compileKotlin("typeAliases.kt", tmpdir);
    Pair<String, ExitCode> outputMain = compileKotlin("main.kt", tmpdir, Arrays.asList("-language-version", "1.0"), tmpdir);
    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 19 with ExitCode

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

the class CompileKotlinAgainstCustomBinariesTest method testInnerClassPackageConflict.

public void testInnerClassPackageConflict() throws Exception {
    compileJava("library");
    FileUtil.copy(new File(getTestDataDirectory(), "library/test/Foo/x.txt"), new File(tmpdir, "library/test/Foo/x.txt"));
    MockLibraryUtil.createJarFile(tmpdir, new File(tmpdir, "library"), null, "library", false);
    File jarPath = new File(tmpdir, "library.jar");
    Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, jarPath);
    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)

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