ant task fixes + first integration test

This commit is contained in:
Leonid Shalupov
2012-05-07 18:12:06 +04:00
parent ffcba10773
commit 58c0ad3c46
8 changed files with 103 additions and 9 deletions
@@ -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
@@ -0,0 +1,7 @@
<project name="Ant Task Test" default="build">
<taskdef resource="org/jetbrains/jet/buildtools/ant/antlib.xml" classpath="${kotlin.lib}/kotlin-ant.jar"/>
<target name="build">
<kotlinc src="${test.data}/hello.kt" output="${temp}/hello.jar"/>
</target>
</project>
@@ -0,0 +1,5 @@
package Hello
fun main(args : Array<String>) {
System.out?.println("Hello!")
}
@@ -0,0 +1,2 @@
OUT Hello!
Return code: 0
@@ -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";
}
}
@@ -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);