From 58c0ad3c465c884a04318b3ea8f876941524fd24 Mon Sep 17 00:00:00 2001 From: Leonid Shalupov Date: Mon, 7 May 2012 18:12:06 +0400 Subject: [PATCH] ant task fixes + first integration test --- build.xml | 22 ++++++--- .../data/antTaskJvm/build.log.expected | 10 +++++ .../data/antTaskJvm/build.xml | 7 +++ .../data/antTaskJvm/hello.kt | 5 +++ .../data/antTaskJvm/hello.run.expected | 2 + .../src/org/jetbrains/kotlin/AntTaskTest.java | 45 +++++++++++++++++++ .../kotlin/KotlinIntegrationTestBase.java | 15 +++++-- update_dependencies.xml | 6 +++ 8 files changed, 103 insertions(+), 9 deletions(-) create mode 100644 compiler/integration-tests/data/antTaskJvm/build.log.expected create mode 100644 compiler/integration-tests/data/antTaskJvm/build.xml create mode 100644 compiler/integration-tests/data/antTaskJvm/hello.kt create mode 100644 compiler/integration-tests/data/antTaskJvm/hello.run.expected create mode 100644 compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java diff --git a/build.xml b/build.xml index 732be52302b..ba2636418c0 100644 --- a/build.xml +++ b/build.xml @@ -1,7 +1,7 @@ - + @@ -155,11 +155,11 @@ - + + tofile="${kotlin-home}/lib/kotlin-compiler.jar"/> @@ -267,10 +267,20 @@ - + + + + + + + + + + + @@ -289,7 +299,7 @@ - + @@ -317,7 +327,7 @@ - + diff --git a/compiler/integration-tests/data/antTaskJvm/build.log.expected b/compiler/integration-tests/data/antTaskJvm/build.log.expected new file mode 100644 index 00000000000..982e7a713f4 --- /dev/null +++ b/compiler/integration-tests/data/antTaskJvm/build.log.expected @@ -0,0 +1,10 @@ +OUT Buildfile: build.xml +OUT +OUT build: +OUT [kotlinc] Compiling [[TestData]\hello.kt] => [[Temp]\hello.jar] +OUT [kotlinc] LOGGING: For source: [TestData]\hello.kt +OUT [kotlinc] LOGGING: Emitting: Hello/namespace.class +OUT +OUT BUILD SUCCESSFUL +OUT Total time: 2 seconds +Return code: 0 diff --git a/compiler/integration-tests/data/antTaskJvm/build.xml b/compiler/integration-tests/data/antTaskJvm/build.xml new file mode 100644 index 00000000000..c5d0a6c090a --- /dev/null +++ b/compiler/integration-tests/data/antTaskJvm/build.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/compiler/integration-tests/data/antTaskJvm/hello.kt b/compiler/integration-tests/data/antTaskJvm/hello.kt new file mode 100644 index 00000000000..4c4a4b67c8c --- /dev/null +++ b/compiler/integration-tests/data/antTaskJvm/hello.kt @@ -0,0 +1,5 @@ +package Hello + +fun main(args : Array) { + System.out?.println("Hello!") +} diff --git a/compiler/integration-tests/data/antTaskJvm/hello.run.expected b/compiler/integration-tests/data/antTaskJvm/hello.run.expected new file mode 100644 index 00000000000..fc47ec99014 --- /dev/null +++ b/compiler/integration-tests/data/antTaskJvm/hello.run.expected @@ -0,0 +1,2 @@ +OUT Hello! +Return code: 0 diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java new file mode 100644 index 00000000000..b9f11c6fe34 --- /dev/null +++ b/compiler/integration-tests/src/org/jetbrains/kotlin/AntTaskTest.java @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin; + +import org.junit.Test; + +import java.io.File; + +import static junit.framework.Assert.assertEquals; + +public class AntTaskTest extends KotlinIntegrationTestBase { + @Test + public void antTaskJvm() throws Exception { + final String jar = tempDir.getAbsolutePath() + File.separator + "hello.jar"; + + assertEquals("compilation failed", 0, runAnt("build.log", "build.xml")); + runJava("hello.run", "-cp", jar, "Hello.namespace"); + } + + private int runAnt(String logName, String scriptName) throws Exception { + return runJava(logName, "-jar", getAntHome() + File.separator + "lib" + File.separator + "ant-launcher.jar", + "-Dkotlin.lib=" + getCompilerLib(), + "-Dtest.data=" + testDataDir, + "-Dtemp=" + tempDir, + "-f", scriptName); + } + + private static String getAntHome() { + return getKotlinProjectHome().getAbsolutePath() + File.separator + "dependencies" + File.separator + "ant"; + } +} diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java b/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java index 465888216fe..87111fcb574 100644 --- a/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java +++ b/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java @@ -52,9 +52,15 @@ public abstract class KotlinIntegrationTestBase { public TestRule watchman = new TestWatcher() { @Override protected void starting(Description description) { - tempDir = Files.createTempDir(); + try { + tempDir = Files.createTempDir().getCanonicalFile(); + } + catch (IOException e) { + throw new RuntimeException(e); + } - final File baseTestDataDir = new File(getKotlinProjectHome(), "compiler" + File.separator + "integration-tests" + File.separator + "data"); + final File baseTestDataDir = + new File(getKotlinProjectHome(), "compiler" + File.separator + "integration-tests" + File.separator + "data"); testDataDir = new File(baseTestDataDir, description.getMethodName()); } @@ -111,7 +117,10 @@ public abstract class KotlinIntegrationTestBase { final File actualFile = new File(testDataDir, baseName + ".actual"); final File expectedFile = new File(testDataDir, baseName + ".expected"); - final String normalizedContent = StringUtil.replace(content, testDataDir.getAbsolutePath(), "[TestData]", true); + final String normalizedContent = + StringUtil.replace( + StringUtil.replace(content, testDataDir.getAbsolutePath(), "[TestData]", true), + tempDir.getAbsolutePath(), "[Temp]", true); if (!expectedFile.isFile()) { Files.write(normalizedContent, actualFile, Charsets.UTF_8); diff --git a/update_dependencies.xml b/update_dependencies.xml index 5a59c691b52..e31c5a57b38 100644 --- a/update_dependencies.xml +++ b/update_dependencies.xml @@ -47,6 +47,7 @@ + @@ -54,6 +55,11 @@ + + + + +