From 32a55f786c237b518f259a53772d4584f9c077b8 Mon Sep 17 00:00:00 2001 From: Leonid Shalupov Date: Sun, 22 Apr 2012 23:10:49 +0400 Subject: [PATCH] integration tests: temp dir, stable test output --- .../jetbrains/kotlin/CompilerSmokeTest.java | 8 +++- .../kotlin/KotlinIntegrationTestBase.java | 46 ++++++++++++++++--- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java b/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java index 72550b8a5a5..72d912e47a7 100644 --- a/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java +++ b/compiler/integration-tests/src/org/jetbrains/kotlin/CompilerSmokeTest.java @@ -18,6 +18,8 @@ package org.jetbrains.kotlin; import org.junit.Test; +import java.io.File; + import static junit.framework.Assert.*; public class CompilerSmokeTest extends KotlinIntegrationTestBase { @@ -28,7 +30,9 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase { @Test public void compileAndRunHelloApp() throws Exception { - assertEquals("compilation failed", 0, runCompiler("hello.compile", "-src", "hello.kt", "-jar", "hello.jar")); - runJava("hello.run", "-cp", "hello.jar", "Hello.namespace"); + final String jar = tempDir.getAbsolutePath() + File.separator + "hello.jar"; + + assertEquals("compilation failed", 0, runCompiler("hello.compile", "-src", "hello.kt", "-jar", jar)); + runJava("hello.run", "-cp", jar, "Hello.namespace"); } } diff --git a/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java b/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java index 3f6f26c807c..7407af4cb83 100644 --- a/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java +++ b/compiler/integration-tests/src/org/jetbrains/kotlin/KotlinIntegrationTestBase.java @@ -30,7 +30,10 @@ import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.Function; -import org.apache.commons.lang.SystemUtils; +import org.junit.Rule; +import org.junit.rules.TestRule; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; import sun.misc.JarFilter; import java.io.File; @@ -43,6 +46,30 @@ import static com.google.common.base.Charsets.UTF_8; import static org.junit.Assert.*; public abstract class KotlinIntegrationTestBase { + protected File tempDir; + + @Rule + public TestRule watchman = new TestWatcher() { + @Override + protected void starting(Description description) { + tempDir = Files.createTempDir(); + } + + @Override + protected void succeeded(Description description) { + try { + tempDir.delete(); + } catch (Exception e) { + System.out.print("Can't delete temp directory " + tempDir + ": " + e); + } + } + + @Override + protected void failed(Throwable e, Description description) { + System.err.println("Temp directory: " + tempDir); + } + }; + protected int runCompiler(String logName, String... arguments) throws Exception { final File lib = getCompilerLib(); @@ -89,7 +116,8 @@ public abstract class KotlinIntegrationTestBase { if (!goldFile.isFile()) { Files.write(content, tmpFile, Charsets.UTF_8); fail("No gold file " + goldFile); - } else { + } + else { final String goldContent = Files.toString(goldFile, UTF_8); if (!goldContent.equals(content.toString())) { Files.write(content, tmpFile, Charsets.UTF_8); @@ -113,14 +141,18 @@ public abstract class KotlinIntegrationTestBase { System.out.print(event.getText()); } else if (outputType == ProcessOutputTypes.STDOUT) { - outContent.append("OUT "); - outContent.append(event.getText()); + appendToContent(outContent, "OUT ", event.getText()); } else if (outputType == ProcessOutputTypes.STDERR) { - errContent.append("ERR "); - errContent.append(event.getText()); + appendToContent(errContent, "ERR ", event.getText()); } } + + private void appendToContent(StringBuilder content, String prefix, String line) { + content.append(prefix); + content.append(StringUtil.trimTrailing(line)); + content.append("\n"); + } }); handler.startNotify(); @@ -129,7 +161,7 @@ public abstract class KotlinIntegrationTestBase { executionLog.append(outContent); executionLog.append(errContent); - executionLog.append("Return code: ").append(exitCode).append(SystemUtils.LINE_SEPARATOR); + executionLog.append("Return code: ").append(exitCode).append("\n"); return exitCode; }