Rewrite integration tests to JUnit3, make Ant JVM task tests generated

This commit is contained in:
Alexander Udalov
2015-06-04 22:55:57 +03:00
parent 0f6c23e1c4
commit dda44a61a1
7 changed files with 174 additions and 243 deletions
@@ -22,25 +22,27 @@ import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
import java.io.File;
public abstract class AntTaskBaseTest extends KotlinIntegrationTestBase {
protected static final File ANT_TASK_TEST_DATA_BASE_DIR = new File(INTEGRATION_TEST_DATA_BASE_DIR, "ant");
public abstract class AbstractAntTaskTest extends KotlinIntegrationTestBase {
protected void doTest(String testFile) throws Exception {
String testDataDir = new File(testFile).getAbsolutePath();
protected void doAntTest() throws Exception {
runJava(
testDataDir,
"build.log",
"-jar", getAntHome() + File.separator + "lib" + File.separator + "ant-launcher.jar",
"-Dkotlin.lib=" + getCompilerLib(),
"-Dkotlin.runtime.jar=" + ForTestCompileRuntime.runtimeJarForTests().getAbsolutePath(),
"-Dkotlin.reflect.jar=" + ForTestCompileRuntime.reflectJarForTests().getAbsolutePath(),
"-Dtest.data=" + getTestDataDir(),
"-Dtemp=" + tmpdir.getTmpDir(),
"-Dtest.data=" + testDataDir,
"-Dtemp=" + tmpdir,
"-f", "build.xml"
);
}
@Override
protected String normalizeOutput(String content) {
return CliBaseTest.removePerfOutput(super.normalizeOutput(content))
@NotNull
protected String normalizeOutput(@NotNull File testDataDir, @NotNull String content) {
return CliBaseTest.removePerfOutput(super.normalizeOutput(testDataDir, content))
.replaceAll("Total time: .+\n", "Total time: [time]\n");
}
@@ -23,9 +23,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.js.test.rhino.RhinoFunctionResultChecker;
import org.jetbrains.kotlin.js.test.rhino.RhinoUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.jetbrains.kotlin.test.JetTestUtils;
import java.io.File;
import java.io.IOException;
@@ -33,27 +31,25 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertTrue;
public class AntTaskJsTest extends AntTaskBaseTest {
public class AntTaskJsTest extends AbstractAntTaskTest {
private static final String JS_OUT_FILE = "out.js";
@Rule
public final TestName name = new TestName();
@NotNull
@Override
protected File getTestDataDir() {
return new File(new File(ANT_TASK_TEST_DATA_BASE_DIR, "js"), name.getMethodName());
private String getTestDataDir() {
return JetTestUtils.getTestDataPathBase() + "/integration/ant/js/" + getTestName(true);
}
@NotNull
private File getOutputFileByName(@NotNull String name) {
return new File(tmpdir.getTmpDir(), name);
return new File(tmpdir, name);
}
private void doTest() throws Exception {
doTest(getTestDataDir());
}
private void doJsAntTest(String... jsFiles) throws Exception {
doAntTest();
doTest();
List<String> fileNames = new ArrayList<String>(Arrays.asList(jsFiles));
fileNames.add(JS_OUT_FILE);
@@ -92,123 +88,99 @@ public class AntTaskJsTest extends AntTaskBaseTest {
}
}
@Test
public void simple() throws Exception {
public void testSimple() throws Exception {
doJsAntTest();
}
@Test
public void simpleWithMain() throws Exception {
public void testSimpleWithMain() throws Exception {
doJsAntTest();
}
@Test
public void simpleWithStdlib() throws Exception {
public void testSimpleWithStdlib() throws Exception {
doJsAntTest();
}
@Test
public void simpleWithStdlibAndAnotherLib() throws Exception {
public void testSimpleWithStdlibAndAnotherLib() throws Exception {
doJsAntTest("jslib-example.js");
}
@Test
public void simpleWithStdlibAndFolderAsAnotherLib() throws Exception {
public void testSimpleWithStdlibAndFolderAsAnotherLib() throws Exception {
doJsAntTest("jslib-example.js");
}
@Test
public void simpleWithoutStdlibAndFolderAsAnotherLib() throws Exception {
public void testSimpleWithoutStdlibAndFolderAsAnotherLib() throws Exception {
doJsAntTest("jslib-example.js");
}
@Test
public void simpleWithoutStdlibAndJsFileAsAnotherLib() throws Exception {
public void testSimpleWithoutStdlibAndJsFileAsAnotherLib() throws Exception {
doJsAntTest("jslib-example.js");
}
@Test
public void simpleWithStdlibAndJsFileAsAnotherLib() throws Exception {
public void testSimpleWithStdlibAndJsFileAsAnotherLib() throws Exception {
doJsAntTest("jslib-example.js");
}
@Test
public void simpleWithStdlibAndTwoJsFilesAsLibraries() throws Exception {
public void testSimpleWithStdlibAndTwoJsFilesAsLibraries() throws Exception {
doJsAntTest("jslib-example1.js", "jslib-example2.js");
}
@Test
public void simpleWithStdlibAndJsFilesWithTwoModulesAsLibrary() throws Exception {
public void testSimpleWithStdlibAndJsFilesWithTwoModulesAsLibrary() throws Exception {
doJsAntTest("jslib-example.js");
}
@Test
public void simpleWithMainFQArgs() throws Exception {
public void testSimpleWithMainFQArgs() throws Exception {
doJsAntTest();
}
@Test
public void simpleWithVarargMain() throws Exception {
public void testSimpleWithVarargMain() throws Exception {
doJsAntTest();
}
@Test
public void manySources() throws Exception {
public void testManySources() throws Exception {
doJsAntTest();
}
@Test
public void additionalArguments() throws Exception {
public void testAdditionalArguments() throws Exception {
doJsAntTest();
}
@Test
public void suppressWarnings() throws Exception {
public void testSuppressWarnings() throws Exception {
doJsAntTest();
}
@Test
public void verbose() throws Exception {
public void testVerbose() throws Exception {
doJsAntTest();
}
@Test
public void version() throws Exception {
public void testVersion() throws Exception {
doJsAntTest();
}
@Test
public void outputWithoutDirectory() throws Exception {
public void testOutputWithoutDirectory() throws Exception {
doJsAntTest();
}
@Test
public void noSrcParam() throws Exception {
doAntTest();
public void testNoSrcParam() throws Exception {
doTest();
}
@Test
public void noOutputParam() throws Exception {
doAntTest();
public void testNoOutputParam() throws Exception {
doTest();
}
@Test
public void outputPrefix() throws Exception {
public void testOutputPrefix() throws Exception {
doJsAntTestForPostfixPrefix("prefix", null);
}
@Test
public void outputPostfix() throws Exception {
public void testOutputPostfix() throws Exception {
doJsAntTestForPostfixPrefix(null, "postfix");
}
@Test
public void bothPrefixAndPostfix() throws Exception {
public void testBothPrefixAndPostfix() throws Exception {
doJsAntTestForPostfixPrefix("prefix", "postfix");
}
@Test
public void sourceMap() throws Exception {
public void testSourceMap() throws Exception {
doJsAntTest();
File sourceMap = getOutputFileByName(JS_OUT_FILE + ".map");
@@ -1,94 +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.integration;
import org.jetbrains.annotations.NotNull;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import java.io.File;
public class AntTaskJvmTest extends AntTaskBaseTest {
@Rule
public final TestName name = new TestName();
@NotNull
@Override
protected File getTestDataDir() {
return new File(new File(ANT_TASK_TEST_DATA_BASE_DIR, "jvm"), name.getMethodName());
}
private void doJvmAntTest() throws Exception {
doAntTest();
}
@Test
public void helloWorld() throws Exception {
doJvmAntTest();
}
@Test
public void additionalArguments() throws Exception {
doJvmAntTest();
}
@Test
public void doNotFailOnError() throws Exception {
doJvmAntTest();
}
@Test
public void jvmClasspath() throws Exception {
doJvmAntTest();
}
@Test
public void manySourceRoots() throws Exception {
doJvmAntTest();
}
@Test
public void suppressWarnings() throws Exception {
doJvmAntTest();
}
@Test
public void verbose() throws Exception {
doJvmAntTest();
}
@Test
public void version() throws Exception {
doJvmAntTest();
}
@Test
public void noClasspathGiven() throws Exception {
doJvmAntTest();
}
@Test
public void withKotlinNoJavaSources() throws Exception {
doJvmAntTest();
}
@Test
public void externalAnnotations() throws Exception {
doJvmAntTest();
}
}
@@ -0,0 +1,91 @@
/*
* 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.integration;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.JetTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/testData/integration/ant/jvm")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class AntTaskTestGenerated extends AbstractAntTaskTest {
@TestMetadata("additionalArguments")
public void testAdditionalArguments() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/additionalArguments/");
doTest(fileName);
}
public void testAllFilesPresentInJvm() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/integration/ant/jvm"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("doNotFailOnError")
public void testDoNotFailOnError() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/doNotFailOnError/");
doTest(fileName);
}
@TestMetadata("helloWorld")
public void testHelloWorld() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/helloWorld/");
doTest(fileName);
}
@TestMetadata("jvmClasspath")
public void testJvmClasspath() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/jvmClasspath/");
doTest(fileName);
}
@TestMetadata("noClasspathGiven")
public void testNoClasspathGiven() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/noClasspathGiven/");
doTest(fileName);
}
@TestMetadata("suppressWarnings")
public void testSuppressWarnings() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/suppressWarnings/");
doTest(fileName);
}
@TestMetadata("verbose")
public void testVerbose() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/verbose/");
doTest(fileName);
}
@TestMetadata("version")
public void testVersion() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/version/");
doTest(fileName);
}
@TestMetadata("withKotlinNoJavaSources")
public void testWithKotlinNoJavaSources() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/integration/ant/jvm/withKotlinNoJavaSources/");
doTest(fileName);
}
}
@@ -17,12 +17,8 @@
package org.jetbrains.kotlin.integration;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
import org.jetbrains.kotlin.test.JetTestUtils;
import org.jetbrains.kotlin.utils.UtilsPackage;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import java.io.File;
import java.util.ArrayList;
@@ -30,16 +26,9 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
public class CompilerSmokeTest extends KotlinIntegrationTestBase {
@Rule
public final TestName name = new TestName();
@NotNull
@Override
protected File getTestDataDir() {
return new File(new File(INTEGRATION_TEST_DATA_BASE_DIR, "smoke"), name.getMethodName());
private int run(String logName, String... args) throws Exception {
return runJava(JetTestUtils.getTestDataPathBase() + "/integration/smoke/" + getTestName(true), logName, args);
}
private int runCompiler(String logName, String... arguments) throws Exception {
@@ -55,54 +44,47 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
Collections.addAll(javaArgs, arguments);
return runJava(logName, ArrayUtil.toStringArray(javaArgs));
return run(logName, ArrayUtil.toStringArray(javaArgs));
}
@Test
public void helloApp() throws Exception {
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar";
public void testHelloApp() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "hello.kt", "-d", jar));
runJava("hello.run", "-cp", jar, "Hello.HelloPackage");
run("hello.run", "-cp", jar, "Hello.HelloPackage");
}
@Test
public void helloAppFQMain() throws Exception {
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar";
public void testHelloAppFQMain() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "hello.kt", "-d", jar));
runJava("hello.run", "-cp", jar, "Hello.HelloPackage");
run("hello.run", "-cp", jar, "Hello.HelloPackage");
}
@Test
public void helloAppVarargMain() throws Exception {
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "hello.jar";
public void testHelloAppVarargMain() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "hello.kt", "-d", jar));
runJava("hello.run", "-cp", jar, "Hello.HelloPackage");
run("hello.run", "-cp", jar, "Hello.HelloPackage");
}
@Test
public void compilationFailed() throws Exception {
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "smoke.jar";
public void testCompilationFailed() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "smoke.jar";
runCompiler("hello.compile", "hello.kt", "-d", jar);
}
@Test
public void syntaxErrors() throws Exception {
String jar = tmpdir.getTmpDir().getAbsolutePath() + File.separator + "smoke.jar";
public void testSyntaxErrors() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "smoke.jar";
runCompiler("test.compile", "test.kt", "-d", jar);
}
@Test
public void simpleScript() throws Exception {
public void testSimpleScript() throws Exception {
runCompiler("script", "-script", "script.kts", "hi", "there");
}
@Test
public void scriptWithClasspath() throws Exception {
public void testScriptWithClasspath() throws Exception {
runCompiler("script", "-cp", new File("lib/javax.inject.jar").getAbsolutePath(), "-script", "script.kts");
}
}
@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.integration;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.OutputListener;
import com.intellij.execution.configurations.GeneralCommandLine;
@@ -31,33 +29,22 @@ import kotlin.text.MatchResult;
import kotlin.text.Regex;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.cli.common.KotlinVersion;
import org.jetbrains.kotlin.test.JetTestUtils;
import org.jetbrains.kotlin.test.Tmpdir;
import org.jetbrains.kotlin.test.TestCaseWithTmpdir;
import org.jetbrains.kotlin.utils.PathUtil;
import org.junit.ComparisonFailure;
import org.junit.Rule;
import java.io.File;
import java.io.IOException;
import static org.junit.Assert.*;
public abstract class KotlinIntegrationTestBase {
protected static final File INTEGRATION_TEST_DATA_BASE_DIR = new File(JetTestUtils.getTestDataPathBase(), "integration");
@Rule
public final Tmpdir tmpdir = new Tmpdir();
public abstract class KotlinIntegrationTestBase extends TestCaseWithTmpdir {
static {
System.setProperty("java.awt.headless", "true");
}
@NotNull
protected abstract File getTestDataDir();
protected int runJava(String logName, String... arguments) throws Exception {
GeneralCommandLine commandLine = new GeneralCommandLine().withWorkDirectory(getTestDataDir());
protected int runJava(@NotNull String testDataDir, @Nullable String logName, @NotNull String... arguments) throws Exception {
GeneralCommandLine commandLine = new GeneralCommandLine().withWorkDirectory(testDataDir);
commandLine.setExePath(getJavaRuntime().getAbsolutePath());
commandLine.addParameters(arguments);
@@ -68,7 +55,7 @@ public abstract class KotlinIntegrationTestBase {
assertEquals("Non-zero exit code", 0, exitCode);
}
else {
check(logName, executionLog.toString());
check(testDataDir, logName, executionLog.toString());
}
return exitCode;
@@ -88,9 +75,10 @@ public abstract class KotlinIntegrationTestBase {
});
}
protected String normalizeOutput(String content) {
content = normalizePath(content, getTestDataDir(), "[TestData]");
content = normalizePath(content, tmpdir.getTmpDir(), "[Temp]");
@NotNull
protected String normalizeOutput(@NotNull File testDataDir, @NotNull String content) {
content = normalizePath(content, testDataDir, "[TestData]");
content = normalizePath(content, tmpdir, "[Temp]");
content = normalizePath(content, getCompilerLib(), "[CompilerLib]");
content = normalizePath(content, getKotlinProjectHome(), "[KotlinProjectHome]");
content = content.replaceAll(KotlinVersion.VERSION, "[KotlinVersion]");
@@ -98,26 +86,11 @@ public abstract class KotlinIntegrationTestBase {
return content;
}
private void check(String baseName, String content) throws IOException {
File actualFile = new File(getTestDataDir(), baseName + ".actual");
File expectedFile = new File(getTestDataDir(), baseName + ".expected");
private void check(String testDataDir, String baseName, String content) throws IOException {
File expectedFile = new File(testDataDir, baseName + ".expected");
String normalizedContent = normalizeOutput(new File(testDataDir), content);
String normalizedContent = normalizeOutput(content);
if (!expectedFile.isFile()) {
Files.write(normalizedContent, actualFile, Charsets.UTF_8);
fail("No .expected file " + expectedFile);
}
try {
JetTestUtils.assertEqualsToFile(expectedFile, normalizedContent);
//noinspection ResultOfMethodCallIgnored
actualFile.delete();
}
catch (ComparisonFailure e) {
Files.write(normalizedContent, actualFile, Charsets.UTF_8);
throw e;
}
JetTestUtils.assertEqualsToFile(expectedFile, normalizedContent);
}
private static int runProcess(GeneralCommandLine commandLine, StringBuilder executionLog) throws ExecutionException {
@@ -92,6 +92,7 @@ import org.jetbrains.kotlin.idea.structureView.AbstractKotlinFileStructureTest
import org.jetbrains.kotlin.idea.stubs.AbstractMultiFileHighlightingTest
import org.jetbrains.kotlin.idea.stubs.AbstractResolveByStubTest
import org.jetbrains.kotlin.idea.stubs.AbstractStubBuilderTest
import org.jetbrains.kotlin.integration.AbstractAntTaskTest
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterForWebDemoTest
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterMultiFileTest
import org.jetbrains.kotlin.j2k.AbstractJavaToKotlinConverterSingleFileTest
@@ -272,6 +273,10 @@ fun main(args: Array<String>) {
model("repl", extension = "repl")
}
testClass(javaClass<AbstractAntTaskTest>()) {
model("integration/ant/jvm", extension = null, recursive = false, excludeParentDirs = true)
}
testClass(javaClass<AbstractControlFlowTest>()) {
model("cfg")
}