From 762504d5e4b44eda90a5ea9485cc711ef8581499 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 8 Feb 2016 21:19:37 +0530 Subject: [PATCH] CLI tests: convert to JUnit 3 --- .../org/jetbrains/kotlin/cli/CliBaseTest.java | 19 ++---- .../jetbrains/kotlin/cli/js/K2JsCliTest.java | 46 +++++-------- .../kotlin/cli/jvm/K2JvmCliTest.java | 64 ++++++------------- .../org/jetbrains/kotlin/test/Tmpdir.java | 62 ------------------ 4 files changed, 42 insertions(+), 149 deletions(-) delete mode 100644 compiler/tests/org/jetbrains/kotlin/test/Tmpdir.java diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliBaseTest.java b/compiler/tests/org/jetbrains/kotlin/cli/CliBaseTest.java index 28b2cdc8cc5..5b795153347 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliBaseTest.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliBaseTest.java @@ -32,13 +32,11 @@ import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion; import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion; import org.jetbrains.kotlin.test.InTextDirectivesUtils; import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.Tmpdir; +import org.jetbrains.kotlin.test.TestCaseWithTmpdir; import org.jetbrains.kotlin.utils.ExceptionUtilsKt; import org.jetbrains.kotlin.utils.PathUtil; import org.jetbrains.kotlin.utils.StringsKt; import org.junit.Assert; -import org.junit.Rule; -import org.junit.rules.TestName; import java.io.ByteArrayOutputStream; import java.io.File; @@ -47,15 +45,10 @@ import java.io.PrintStream; import java.util.ArrayList; import java.util.List; -public class CliBaseTest { +public abstract class CliBaseTest extends TestCaseWithTmpdir { static final String JS_TEST_DATA = "compiler/testData/cli/js"; static final String JVM_TEST_DATA = "compiler/testData/cli/jvm"; - @Rule - public final Tmpdir tmpdir = new Tmpdir(); - @Rule - public final TestName testName = new TestName(); - @NotNull public static Pair executeCompilerGrabOutput(@NotNull CLICompiler compiler, @NotNull List args) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); @@ -97,10 +90,10 @@ public class CliBaseTest { private void executeCompilerCompareOutput(@NotNull CLICompiler compiler, @NotNull String testDataDir) throws Exception { System.setProperty("java.awt.headless", "true"); - String testMethodName = testName.getMethodName(); + String testMethodName = getTestName(true); Pair outputAndExitCode = executeCompilerGrabOutput(compiler, readArgs(testDataDir + "/" + testMethodName + ".args", testDataDir, - tmpdir.getTmpDir().getPath())); + tmpdir.getPath())); String actual = getNormalizedCompilerOutput(outputAndExitCode.getFirst(), outputAndExitCode.getSecond(), testDataDir); KotlinTestUtils.assertEqualsToFile(new File(testDataDir + "/" + testMethodName + ".out"), actual); @@ -117,7 +110,7 @@ public class CliBaseTest { List existsList = InTextDirectivesUtils.findListWithPrefixes(content, "// EXISTS: "); for (String fileName : existsList) { - File file = new File(tmpdir.getTmpDir(), fileName); + File file = new File(tmpdir, fileName); if (!file.exists()) { diagnostics.add("File does not exist, but should: " + fileName); } @@ -128,7 +121,7 @@ public class CliBaseTest { List absentList = InTextDirectivesUtils.findListWithPrefixes(content, "// ABSENT: "); for (String fileName : absentList) { - File file = new File(tmpdir.getTmpDir(), fileName); + File file = new File(tmpdir, fileName); if (file.exists() && file.isFile()) { diagnostics.add("File exists, but shouldn't: " + fileName); } diff --git a/compiler/tests/org/jetbrains/kotlin/cli/js/K2JsCliTest.java b/compiler/tests/org/jetbrains/kotlin/cli/js/K2JsCliTest.java index 8cb22c35949..149adc01c63 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/js/K2JsCliTest.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/js/K2JsCliTest.java @@ -17,81 +17,65 @@ package org.jetbrains.kotlin.cli.js; import org.jetbrains.kotlin.cli.CliBaseTest; -import org.junit.Test; public class K2JsCliTest extends CliBaseTest { - @Test - public void simple2js() throws Exception { + public void testSimple2js() throws Exception { executeCompilerCompareOutputJS(); } - @Test - public void outputIsDirectory() throws Exception { + public void testOutputIsDirectory() throws Exception { executeCompilerCompareOutputJS(); } - @Test - public void nonExistingSourcePath() throws Exception { + public void testNonExistingSourcePath() throws Exception { executeCompilerCompareOutputJS(); } - @Test - public void emptySources() throws Exception { + public void testEmptySources() throws Exception { executeCompilerCompareOutputJS(); } - @Test - public void outputPrefixFileNotFound() throws Exception { + public void testOutputPrefixFileNotFound() throws Exception { executeCompilerCompareOutputJS(); } - @Test - public void outputPostfixFileNotFound() throws Exception { + public void testOutputPostfixFileNotFound() throws Exception { executeCompilerCompareOutputJS(); } - @Test - public void wrongAbiVersion() throws Exception { + public void testWrongAbiVersion() throws Exception { executeCompilerCompareOutputJS(); } - @Test - public void jsHelp() throws Exception { + public void testJsHelp() throws Exception { executeCompilerCompareOutputJS(); } - @Test - public void withLib() throws Exception { + public void testWithLib() throws Exception { executeCompilerCompareOutputJS(); } - @Test - public void withFolderAsLib() throws Exception { + public void testWithFolderAsLib() throws Exception { executeCompilerCompareOutputJS(); } - @Test - public void createMetadata() throws Exception { + public void testCreateMetadata() throws Exception { executeCompilerCompareOutputJS(); } - @Test - public void createKjsm() throws Exception { + public void testCreateKjsm() throws Exception { executeCompilerCompareOutputJS(); } - @Test - public void libraryDirNotFound() throws Exception { + public void testLibraryDirNotFound() throws Exception { executeCompilerCompareOutputJS(); } - @Test - public void notValidLibraryDir() throws Exception { + public void testNotValidLibraryDir() throws Exception { executeCompilerCompareOutputJS(); } - @Test - public void suppressAllWarningsJS() throws Exception { + public void testSuppressAllWarningsJS() throws Exception { executeCompilerCompareOutputJS(); } } diff --git a/compiler/tests/org/jetbrains/kotlin/cli/jvm/K2JvmCliTest.java b/compiler/tests/org/jetbrains/kotlin/cli/jvm/K2JvmCliTest.java index da83e636c42..8b001d868e6 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/jvm/K2JvmCliTest.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/jvm/K2JvmCliTest.java @@ -17,111 +17,89 @@ package org.jetbrains.kotlin.cli.jvm; import org.jetbrains.kotlin.cli.CliBaseTest; -import org.junit.Test; public class K2JvmCliTest extends CliBaseTest { - @Test - public void wrongAbiVersion() throws Exception { + public void testWrongAbiVersion() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void wrongAbiVersionNoErrors() throws Exception { + public void testWrongAbiVersionNoErrors() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void nonExistingClassPathAndAnnotationsPath() throws Exception { + public void testNonExistingClassPathAndAnnotationsPath() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void nonExistingSourcePath() throws Exception { + public void testNonExistingSourcePath() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void emptySources() throws Exception { + public void testEmptySources() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void classpath() throws Exception { + public void testClasspath() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void signatureClash() throws Exception { + public void testSignatureClash() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void conflictingOverloads() throws Exception { + public void testConflictingOverloads() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void warningsInDummy() throws Exception { + public void testWarningsInDummy() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void help() throws Exception { + public void testHelp() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void wrongArgument() throws Exception { + public void testWrongArgument() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void simple() throws Exception { + public void testSimple() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void duplicateSources() throws Exception { + public void testDuplicateSources() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void duplicateSourcesInModule() throws Exception { + public void testDuplicateSourcesInModule() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void nonexistentPathInModule() throws Exception { + public void testNonexistentPathInModule() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void nonexistentScript() throws Exception { + public void testNonexistentScript() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void diagnosticsOrder() throws Exception { + public void testDiagnosticsOrder() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void multipleTextRangesInDiagnosticsOrder() throws Exception { + public void testMultipleTextRangesInDiagnosticsOrder() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void suppressAllWarningsJvm() throws Exception { + public void testSuppressAllWarningsJvm() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void pluginSimple() throws Exception { + public void testPluginSimple() throws Exception { executeCompilerCompareOutputJVM(); } - @Test - public void pluginSimpleUsage() throws Exception { + public void testPluginSimpleUsage() throws Exception { executeCompilerCompareOutputJVM(); } } diff --git a/compiler/tests/org/jetbrains/kotlin/test/Tmpdir.java b/compiler/tests/org/jetbrains/kotlin/test/Tmpdir.java deleted file mode 100644 index b4d35186e2e..00000000000 --- a/compiler/tests/org/jetbrains/kotlin/test/Tmpdir.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2010-2015 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.test; - -import com.google.common.io.Files; -import com.intellij.openapi.util.io.FileUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.utils.ExceptionUtilsKt; -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; - -import java.io.File; -import java.io.IOException; - -public class Tmpdir extends TestWatcher { - - private File tmpDir; - - @Override - protected void starting(Description description) { - try { - tmpDir = Files.createTempDir().getCanonicalFile(); - } - catch (IOException e) { - throw ExceptionUtilsKt.rethrow(e); - } - } - - @Override - protected void succeeded(Description description) { - if (tmpDir == null) { - return; - } - if (!FileUtil.delete(tmpDir)) { - throw new RuntimeException("failed to delete " + tmpDir); - } - } - - @Override - protected void failed(Throwable e, Description description) { - System.err.println("Temp directory: " + tmpDir); - } - - @NotNull - public File getTmpDir() { - return tmpDir; - } -}