CLI tests: convert to JUnit 3
This commit is contained in:
committed by
Alexander Udalov
parent
f74988cbec
commit
762504d5e4
@@ -32,13 +32,11 @@ import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion;
|
|||||||
import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion;
|
import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion;
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
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.ExceptionUtilsKt;
|
||||||
import org.jetbrains.kotlin.utils.PathUtil;
|
import org.jetbrains.kotlin.utils.PathUtil;
|
||||||
import org.jetbrains.kotlin.utils.StringsKt;
|
import org.jetbrains.kotlin.utils.StringsKt;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.rules.TestName;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -47,15 +45,10 @@ import java.io.PrintStream;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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 JS_TEST_DATA = "compiler/testData/cli/js";
|
||||||
static final String JVM_TEST_DATA = "compiler/testData/cli/jvm";
|
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
|
@NotNull
|
||||||
public static Pair<String, ExitCode> executeCompilerGrabOutput(@NotNull CLICompiler<?> compiler, @NotNull List<String> args) {
|
public static Pair<String, ExitCode> executeCompilerGrabOutput(@NotNull CLICompiler<?> compiler, @NotNull List<String> args) {
|
||||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||||
@@ -97,10 +90,10 @@ public class CliBaseTest {
|
|||||||
|
|
||||||
private void executeCompilerCompareOutput(@NotNull CLICompiler<?> compiler, @NotNull String testDataDir) throws Exception {
|
private void executeCompilerCompareOutput(@NotNull CLICompiler<?> compiler, @NotNull String testDataDir) throws Exception {
|
||||||
System.setProperty("java.awt.headless", "true");
|
System.setProperty("java.awt.headless", "true");
|
||||||
String testMethodName = testName.getMethodName();
|
String testMethodName = getTestName(true);
|
||||||
Pair<String, ExitCode> outputAndExitCode =
|
Pair<String, ExitCode> outputAndExitCode =
|
||||||
executeCompilerGrabOutput(compiler, readArgs(testDataDir + "/" + testMethodName + ".args", testDataDir,
|
executeCompilerGrabOutput(compiler, readArgs(testDataDir + "/" + testMethodName + ".args", testDataDir,
|
||||||
tmpdir.getTmpDir().getPath()));
|
tmpdir.getPath()));
|
||||||
String actual = getNormalizedCompilerOutput(outputAndExitCode.getFirst(), outputAndExitCode.getSecond(), testDataDir);
|
String actual = getNormalizedCompilerOutput(outputAndExitCode.getFirst(), outputAndExitCode.getSecond(), testDataDir);
|
||||||
|
|
||||||
KotlinTestUtils.assertEqualsToFile(new File(testDataDir + "/" + testMethodName + ".out"), actual);
|
KotlinTestUtils.assertEqualsToFile(new File(testDataDir + "/" + testMethodName + ".out"), actual);
|
||||||
@@ -117,7 +110,7 @@ public class CliBaseTest {
|
|||||||
|
|
||||||
List<String> existsList = InTextDirectivesUtils.findListWithPrefixes(content, "// EXISTS: ");
|
List<String> existsList = InTextDirectivesUtils.findListWithPrefixes(content, "// EXISTS: ");
|
||||||
for (String fileName : existsList) {
|
for (String fileName : existsList) {
|
||||||
File file = new File(tmpdir.getTmpDir(), fileName);
|
File file = new File(tmpdir, fileName);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
diagnostics.add("File does not exist, but should: " + fileName);
|
diagnostics.add("File does not exist, but should: " + fileName);
|
||||||
}
|
}
|
||||||
@@ -128,7 +121,7 @@ public class CliBaseTest {
|
|||||||
|
|
||||||
List<String> absentList = InTextDirectivesUtils.findListWithPrefixes(content, "// ABSENT: ");
|
List<String> absentList = InTextDirectivesUtils.findListWithPrefixes(content, "// ABSENT: ");
|
||||||
for (String fileName : absentList) {
|
for (String fileName : absentList) {
|
||||||
File file = new File(tmpdir.getTmpDir(), fileName);
|
File file = new File(tmpdir, fileName);
|
||||||
if (file.exists() && file.isFile()) {
|
if (file.exists() && file.isFile()) {
|
||||||
diagnostics.add("File exists, but shouldn't: " + fileName);
|
diagnostics.add("File exists, but shouldn't: " + fileName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,81 +17,65 @@
|
|||||||
package org.jetbrains.kotlin.cli.js;
|
package org.jetbrains.kotlin.cli.js;
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cli.CliBaseTest;
|
import org.jetbrains.kotlin.cli.CliBaseTest;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class K2JsCliTest extends CliBaseTest {
|
public class K2JsCliTest extends CliBaseTest {
|
||||||
@Test
|
public void testSimple2js() throws Exception {
|
||||||
public void simple2js() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testOutputIsDirectory() throws Exception {
|
||||||
public void outputIsDirectory() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testNonExistingSourcePath() throws Exception {
|
||||||
public void nonExistingSourcePath() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testEmptySources() throws Exception {
|
||||||
public void emptySources() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testOutputPrefixFileNotFound() throws Exception {
|
||||||
public void outputPrefixFileNotFound() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testOutputPostfixFileNotFound() throws Exception {
|
||||||
public void outputPostfixFileNotFound() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testWrongAbiVersion() throws Exception {
|
||||||
public void wrongAbiVersion() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testJsHelp() throws Exception {
|
||||||
public void jsHelp() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testWithLib() throws Exception {
|
||||||
public void withLib() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testWithFolderAsLib() throws Exception {
|
||||||
public void withFolderAsLib() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testCreateMetadata() throws Exception {
|
||||||
public void createMetadata() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testCreateKjsm() throws Exception {
|
||||||
public void createKjsm() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testLibraryDirNotFound() throws Exception {
|
||||||
public void libraryDirNotFound() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testNotValidLibraryDir() throws Exception {
|
||||||
public void notValidLibraryDir() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testSuppressAllWarningsJS() throws Exception {
|
||||||
public void suppressAllWarningsJS() throws Exception {
|
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,111 +17,89 @@
|
|||||||
package org.jetbrains.kotlin.cli.jvm;
|
package org.jetbrains.kotlin.cli.jvm;
|
||||||
|
|
||||||
import org.jetbrains.kotlin.cli.CliBaseTest;
|
import org.jetbrains.kotlin.cli.CliBaseTest;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class K2JvmCliTest extends CliBaseTest {
|
public class K2JvmCliTest extends CliBaseTest {
|
||||||
@Test
|
public void testWrongAbiVersion() throws Exception {
|
||||||
public void wrongAbiVersion() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testWrongAbiVersionNoErrors() throws Exception {
|
||||||
public void wrongAbiVersionNoErrors() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testNonExistingClassPathAndAnnotationsPath() throws Exception {
|
||||||
public void nonExistingClassPathAndAnnotationsPath() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testNonExistingSourcePath() throws Exception {
|
||||||
public void nonExistingSourcePath() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testEmptySources() throws Exception {
|
||||||
public void emptySources() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testClasspath() throws Exception {
|
||||||
public void classpath() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testSignatureClash() throws Exception {
|
||||||
public void signatureClash() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testConflictingOverloads() throws Exception {
|
||||||
public void conflictingOverloads() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testWarningsInDummy() throws Exception {
|
||||||
public void warningsInDummy() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testHelp() throws Exception {
|
||||||
public void help() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testWrongArgument() throws Exception {
|
||||||
public void wrongArgument() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testSimple() throws Exception {
|
||||||
public void simple() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testDuplicateSources() throws Exception {
|
||||||
public void duplicateSources() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testDuplicateSourcesInModule() throws Exception {
|
||||||
public void duplicateSourcesInModule() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testNonexistentPathInModule() throws Exception {
|
||||||
public void nonexistentPathInModule() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testNonexistentScript() throws Exception {
|
||||||
public void nonexistentScript() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testDiagnosticsOrder() throws Exception {
|
||||||
public void diagnosticsOrder() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testMultipleTextRangesInDiagnosticsOrder() throws Exception {
|
||||||
public void multipleTextRangesInDiagnosticsOrder() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testSuppressAllWarningsJvm() throws Exception {
|
||||||
public void suppressAllWarningsJvm() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testPluginSimple() throws Exception {
|
||||||
public void pluginSimple() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public void testPluginSimpleUsage() throws Exception {
|
||||||
public void pluginSimpleUsage() throws Exception {
|
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user