TmpdirRule

junit4 @Rule to create tmp dir from idea SDK
This commit is contained in:
Stepan Koltsov
2012-06-14 15:29:16 +04:00
parent 9db8a63099
commit 4e99edccaa
6 changed files with 82 additions and 29 deletions
@@ -8,6 +8,7 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="idea-full" level="project" />
<orderEntry type="module" module-name="compiler-tests" />
</component>
</module>
@@ -25,7 +25,7 @@ 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";
final String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runAnt("build.log", "build.xml"));
runJava("hello.run", "-cp", jar, "Hello.namespace");
@@ -41,7 +41,7 @@ public class AntTaskTest extends KotlinIntegrationTestBase {
return runJava(logName, "-jar", getAntHome() + File.separator + "lib" + File.separator + "ant-launcher.jar",
"-Dkotlin.lib=" + getCompilerLib(),
"-Dtest.data=" + testDataDir,
"-Dtemp=" + tempDir,
"-Dtemp=" + tmpdir.getTmpDir(),
"-f", scriptName);
}
@@ -30,7 +30,7 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
@Test
public void compileAndRunHelloApp() throws Exception {
final String jar = tempDir.getAbsolutePath() + File.separator + "hello.jar";
final String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-src", "hello.kt", "-jar", jar));
runJava("hello.run", "-cp", jar, "Hello.namespace");
@@ -38,7 +38,7 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
@Test
public void compileAndRunModule() throws Exception {
final String jar = tempDir.getAbsolutePath() + File.separator + "smoke.jar";
final String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "smoke.jar";
assertEquals("compilation failed", 0, runCompiler("Smoke.compile", "-module", "Smoke.kts", "-jar", jar));
runJava("Smoke.run", "-cp", jar + File.pathSeparator + getKotlinRuntimePath(), "Smoke.namespace", "1", "2", "3");
@@ -46,14 +46,14 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
@Test
public void compilationFailed() throws Exception {
final String jar = tempDir.getAbsolutePath() + File.separator + "smoke.jar";
final String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "smoke.jar";
runCompiler("hello.compile", "-src", "hello.kt", "-jar", jar);
}
@Test
public void syntaxErrors() throws Exception {
final String jar = tempDir.getAbsolutePath() + File.separator + "smoke.jar";
final String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "smoke.jar";
runCompiler("test.compile", "-src", "test.kt", "-jar", jar);
}
@@ -29,6 +29,7 @@ import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ArrayUtil;
import org.jetbrains.jet.test.Tmpdir;
import org.junit.ComparisonFailure;
import org.junit.Rule;
import org.junit.rules.TestRule;
@@ -45,39 +46,20 @@ import static com.google.common.base.Charsets.UTF_8;
import static org.junit.Assert.*;
public abstract class KotlinIntegrationTestBase {
protected File tempDir;
protected File testDataDir;
@Rule
public final Tmpdir tmpdir = new Tmpdir();
@Rule
public TestRule watchman = new TestWatcher() {
@Override
protected void starting(Description description) {
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");
testDataDir = new File(baseTestDataDir, description.getMethodName());
}
@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 {
@@ -124,7 +106,7 @@ public abstract class KotlinIntegrationTestBase {
protected String normalizeOutput(String content) {
content = replacePath(content, testDataDir, "[TestData]");
content = replacePath(content, tempDir, "[Temp]");
content = replacePath(content, tmpdir.getTmpDir(), "[Temp]");
content = replacePath(content, getCompilerLib(), "[CompilerLib]");
return content;
}