From 3b22483fb292dfbf935704495416ce10b1cb9abe Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 8 Feb 2016 21:02:58 +0530 Subject: [PATCH] CLI tests: move file existance checks to config files --- compiler/testData/cli/js/createKjsm.test | 2 + compiler/testData/cli/js/createMetadata.test | 3 ++ compiler/testData/cli/js/emptySources.test | 1 + .../testData/cli/js/libraryDirNotFound.test | 1 + .../cli/js/nonExistingSourcePath.test | 1 + .../testData/cli/js/notValidLibraryDir.test | 1 + .../testData/cli/js/outputIsDirectory.test | 1 + .../cli/js/outputPostfixFileNotFound.test | 1 + .../cli/js/outputPrefixFileNotFound.test | 1 + compiler/testData/cli/js/simple2js.test | 1 + compiler/testData/cli/js/withFolderAsLib.test | 1 + compiler/testData/cli/js/withLib.test | 1 + compiler/testData/cli/js/wrongAbiVersion.test | 1 + .../testData/cli/jvm/duplicateSources.test | 1 + ...onExistingClassPathAndAnnotationsPath.test | 1 + compiler/testData/cli/jvm/simple.test | 1 + .../org/jetbrains/kotlin/cli/CliBaseTest.java | 43 ++++++++++++++++++- .../jetbrains/kotlin/cli/CliCommonTest.java | 7 --- .../jetbrains/kotlin/cli/js/K2JsCliTest.java | 32 -------------- .../kotlin/cli/jvm/K2JvmCliTest.java | 5 --- 20 files changed, 60 insertions(+), 46 deletions(-) create mode 100644 compiler/testData/cli/js/createKjsm.test create mode 100644 compiler/testData/cli/js/createMetadata.test create mode 100644 compiler/testData/cli/js/emptySources.test create mode 100644 compiler/testData/cli/js/libraryDirNotFound.test create mode 100644 compiler/testData/cli/js/nonExistingSourcePath.test create mode 100644 compiler/testData/cli/js/notValidLibraryDir.test create mode 100644 compiler/testData/cli/js/outputIsDirectory.test create mode 100644 compiler/testData/cli/js/outputPostfixFileNotFound.test create mode 100644 compiler/testData/cli/js/outputPrefixFileNotFound.test create mode 100644 compiler/testData/cli/js/simple2js.test create mode 100644 compiler/testData/cli/js/withFolderAsLib.test create mode 100644 compiler/testData/cli/js/withLib.test create mode 100644 compiler/testData/cli/js/wrongAbiVersion.test create mode 100644 compiler/testData/cli/jvm/duplicateSources.test create mode 100644 compiler/testData/cli/jvm/nonExistingClassPathAndAnnotationsPath.test create mode 100644 compiler/testData/cli/jvm/simple.test diff --git a/compiler/testData/cli/js/createKjsm.test b/compiler/testData/cli/js/createKjsm.test new file mode 100644 index 00000000000..f3bbece519f --- /dev/null +++ b/compiler/testData/cli/js/createKjsm.test @@ -0,0 +1,2 @@ +// EXISTS: jslib-example.js +// EXISTS: jslib-example/library/sample/ClassA.kjsm diff --git a/compiler/testData/cli/js/createMetadata.test b/compiler/testData/cli/js/createMetadata.test new file mode 100644 index 00000000000..c8f3f09d1ec --- /dev/null +++ b/compiler/testData/cli/js/createMetadata.test @@ -0,0 +1,3 @@ +// EXISTS: jslib-example.meta.js +// EXISTS: jslib-example.js +// EXISTS: jslib-example/library/sample/ClassA.kjsm diff --git a/compiler/testData/cli/js/emptySources.test b/compiler/testData/cli/js/emptySources.test new file mode 100644 index 00000000000..8c8bba65ee6 --- /dev/null +++ b/compiler/testData/cli/js/emptySources.test @@ -0,0 +1 @@ +// ABSENT: out.js diff --git a/compiler/testData/cli/js/libraryDirNotFound.test b/compiler/testData/cli/js/libraryDirNotFound.test new file mode 100644 index 00000000000..8c8bba65ee6 --- /dev/null +++ b/compiler/testData/cli/js/libraryDirNotFound.test @@ -0,0 +1 @@ +// ABSENT: out.js diff --git a/compiler/testData/cli/js/nonExistingSourcePath.test b/compiler/testData/cli/js/nonExistingSourcePath.test new file mode 100644 index 00000000000..8c8bba65ee6 --- /dev/null +++ b/compiler/testData/cli/js/nonExistingSourcePath.test @@ -0,0 +1 @@ +// ABSENT: out.js diff --git a/compiler/testData/cli/js/notValidLibraryDir.test b/compiler/testData/cli/js/notValidLibraryDir.test new file mode 100644 index 00000000000..8c8bba65ee6 --- /dev/null +++ b/compiler/testData/cli/js/notValidLibraryDir.test @@ -0,0 +1 @@ +// ABSENT: out.js diff --git a/compiler/testData/cli/js/outputIsDirectory.test b/compiler/testData/cli/js/outputIsDirectory.test new file mode 100644 index 00000000000..8c8bba65ee6 --- /dev/null +++ b/compiler/testData/cli/js/outputIsDirectory.test @@ -0,0 +1 @@ +// ABSENT: out.js diff --git a/compiler/testData/cli/js/outputPostfixFileNotFound.test b/compiler/testData/cli/js/outputPostfixFileNotFound.test new file mode 100644 index 00000000000..8c8bba65ee6 --- /dev/null +++ b/compiler/testData/cli/js/outputPostfixFileNotFound.test @@ -0,0 +1 @@ +// ABSENT: out.js diff --git a/compiler/testData/cli/js/outputPrefixFileNotFound.test b/compiler/testData/cli/js/outputPrefixFileNotFound.test new file mode 100644 index 00000000000..8c8bba65ee6 --- /dev/null +++ b/compiler/testData/cli/js/outputPrefixFileNotFound.test @@ -0,0 +1 @@ +// ABSENT: out.js diff --git a/compiler/testData/cli/js/simple2js.test b/compiler/testData/cli/js/simple2js.test new file mode 100644 index 00000000000..cc68ed467c9 --- /dev/null +++ b/compiler/testData/cli/js/simple2js.test @@ -0,0 +1 @@ +// EXISTS: out.js diff --git a/compiler/testData/cli/js/withFolderAsLib.test b/compiler/testData/cli/js/withFolderAsLib.test new file mode 100644 index 00000000000..cc68ed467c9 --- /dev/null +++ b/compiler/testData/cli/js/withFolderAsLib.test @@ -0,0 +1 @@ +// EXISTS: out.js diff --git a/compiler/testData/cli/js/withLib.test b/compiler/testData/cli/js/withLib.test new file mode 100644 index 00000000000..cc68ed467c9 --- /dev/null +++ b/compiler/testData/cli/js/withLib.test @@ -0,0 +1 @@ +// EXISTS: out.js diff --git a/compiler/testData/cli/js/wrongAbiVersion.test b/compiler/testData/cli/js/wrongAbiVersion.test new file mode 100644 index 00000000000..8c8bba65ee6 --- /dev/null +++ b/compiler/testData/cli/js/wrongAbiVersion.test @@ -0,0 +1 @@ +// ABSENT: out.js diff --git a/compiler/testData/cli/jvm/duplicateSources.test b/compiler/testData/cli/jvm/duplicateSources.test new file mode 100644 index 00000000000..4d594134536 --- /dev/null +++ b/compiler/testData/cli/jvm/duplicateSources.test @@ -0,0 +1 @@ +// EXISTS: SimpleKt.class diff --git a/compiler/testData/cli/jvm/nonExistingClassPathAndAnnotationsPath.test b/compiler/testData/cli/jvm/nonExistingClassPathAndAnnotationsPath.test new file mode 100644 index 00000000000..4d594134536 --- /dev/null +++ b/compiler/testData/cli/jvm/nonExistingClassPathAndAnnotationsPath.test @@ -0,0 +1 @@ +// EXISTS: SimpleKt.class diff --git a/compiler/testData/cli/jvm/simple.test b/compiler/testData/cli/jvm/simple.test new file mode 100644 index 00000000000..4d594134536 --- /dev/null +++ b/compiler/testData/cli/jvm/simple.test @@ -0,0 +1 @@ +// EXISTS: SimpleKt.class diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliBaseTest.java b/compiler/tests/org/jetbrains/kotlin/cli/CliBaseTest.java index 60c309898fb..28b2cdc8cc5 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliBaseTest.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliBaseTest.java @@ -30,10 +30,13 @@ import org.jetbrains.kotlin.cli.js.K2JSCompiler; import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler; 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.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; @@ -41,6 +44,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.PrintStream; +import java.util.ArrayList; import java.util.List; public class CliBaseTest { @@ -93,12 +97,47 @@ public class CliBaseTest { private void executeCompilerCompareOutput(@NotNull CLICompiler compiler, @NotNull String testDataDir) throws Exception { System.setProperty("java.awt.headless", "true"); + String testMethodName = testName.getMethodName(); Pair outputAndExitCode = - executeCompilerGrabOutput(compiler, readArgs(testDataDir + "/" + testName.getMethodName() + ".args", testDataDir, + executeCompilerGrabOutput(compiler, readArgs(testDataDir + "/" + testMethodName + ".args", testDataDir, tmpdir.getTmpDir().getPath())); String actual = getNormalizedCompilerOutput(outputAndExitCode.getFirst(), outputAndExitCode.getSecond(), testDataDir); - KotlinTestUtils.assertEqualsToFile(new File(testDataDir + "/" + testName.getMethodName() + ".out"), actual); + KotlinTestUtils.assertEqualsToFile(new File(testDataDir + "/" + testMethodName + ".out"), actual); + + File additionalTestConfig = new File(testDataDir + "/" + testMethodName + ".test"); + if (additionalTestConfig.exists()) { + doTestAdditionalChecks(additionalTestConfig); + } + } + + private void doTestAdditionalChecks(@NotNull File testConfigFile) throws IOException { + List diagnostics = new ArrayList(0); + String content = FilesKt.readText(testConfigFile, Charsets.UTF_8); + + List existsList = InTextDirectivesUtils.findListWithPrefixes(content, "// EXISTS: "); + for (String fileName : existsList) { + File file = new File(tmpdir.getTmpDir(), fileName); + if (!file.exists()) { + diagnostics.add("File does not exist, but should: " + fileName); + } + else if (!file.isFile()) { + diagnostics.add("File is a directory, but should be a normal file: " + fileName); + } + } + + List absentList = InTextDirectivesUtils.findListWithPrefixes(content, "// ABSENT: "); + for (String fileName : absentList) { + File file = new File(tmpdir.getTmpDir(), fileName); + if (file.exists() && file.isFile()) { + diagnostics.add("File exists, but shouldn't: " + fileName); + } + } + + if (!diagnostics.isEmpty()) { + diagnostics.add(0, diagnostics.size() + " problem(s) found:"); + Assert.fail(StringsKt.join(diagnostics, "\n")); + } } @NotNull diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliCommonTest.java b/compiler/tests/org/jetbrains/kotlin/cli/CliCommonTest.java index 04a95fd00e5..603fdb31b1d 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliCommonTest.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliCommonTest.java @@ -16,11 +16,8 @@ package org.jetbrains.kotlin.cli; -import org.junit.Assert; import org.junit.Test; -import java.io.File; - public class CliCommonTest extends CliBaseTest { @Test public void help() throws Exception { @@ -35,15 +32,11 @@ public class CliCommonTest extends CliBaseTest { @Test public void simple() throws Exception { executeCompilerCompareOutputJVM(); - - Assert.assertTrue(new File(tmpdir.getTmpDir(), "SimpleKt.class").isFile()); } @Test public void duplicateSources() throws Exception { executeCompilerCompareOutputJVM(); - - Assert.assertTrue(new File(tmpdir.getTmpDir(), "SimpleKt.class").isFile()); } @Test diff --git a/compiler/tests/org/jetbrains/kotlin/cli/js/K2JsCliTest.java b/compiler/tests/org/jetbrains/kotlin/cli/js/K2JsCliTest.java index 627d53a51e8..180921a0a38 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/js/K2JsCliTest.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/js/K2JsCliTest.java @@ -17,59 +17,42 @@ package org.jetbrains.kotlin.cli.js; import org.jetbrains.kotlin.cli.CliBaseTest; -import org.junit.Assert; import org.junit.Test; -import java.io.File; - public class K2JsCliTest extends CliBaseTest { @Test public void simple2js() throws Exception { executeCompilerCompareOutputJS(); - - Assert.assertTrue(new File(tmpdir.getTmpDir(), "out.js").isFile()); } @Test public void outputIsDirectory() throws Exception { executeCompilerCompareOutputJS(); - - Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").exists()); } @Test public void nonExistingSourcePath() throws Exception { executeCompilerCompareOutputJS(); - - Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").exists()); } @Test public void emptySources() throws Exception { executeCompilerCompareOutputJS(); - - Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").exists()); } @Test public void outputPrefixFileNotFound() throws Exception { executeCompilerCompareOutputJS(); - - Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").exists()); } @Test public void outputPostfixFileNotFound() throws Exception { executeCompilerCompareOutputJS(); - - Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").exists()); } @Test public void wrongAbiVersion() throws Exception { executeCompilerCompareOutputJS(); - - Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").exists()); } @Test @@ -80,45 +63,30 @@ public class K2JsCliTest extends CliBaseTest { @Test public void withLib() throws Exception { executeCompilerCompareOutputJS(); - - Assert.assertTrue(new File(tmpdir.getTmpDir(), "out.js").isFile()); } @Test public void withFolderAsLib() throws Exception { executeCompilerCompareOutputJS(); - - Assert.assertTrue(new File(tmpdir.getTmpDir(), "out.js").isFile()); } @Test public void createMetadata() throws Exception { executeCompilerCompareOutputJS(); - - Assert.assertTrue(new File(tmpdir.getTmpDir(), "jslib-example.meta.js").isFile()); - Assert.assertTrue(new File(tmpdir.getTmpDir(), "jslib-example.js").isFile()); - Assert.assertTrue(new File(tmpdir.getTmpDir(), "jslib-example/library/sample/ClassA.kjsm").isFile()); } @Test public void createKjsm() throws Exception { executeCompilerCompareOutputJS(); - - Assert.assertTrue(new File(tmpdir.getTmpDir(), "jslib-example.js").isFile()); - Assert.assertTrue(new File(tmpdir.getTmpDir(), "jslib-example/library/sample/ClassA.kjsm").isFile()); } @Test public void libraryDirNotFound() throws Exception { executeCompilerCompareOutputJS(); - - Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").isFile()); } @Test public void notValidLibraryDir() throws Exception { executeCompilerCompareOutputJS(); - - Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").isFile()); } } diff --git a/compiler/tests/org/jetbrains/kotlin/cli/jvm/K2JvmCliTest.java b/compiler/tests/org/jetbrains/kotlin/cli/jvm/K2JvmCliTest.java index cbadc7cb2fa..1dff8e5d9d3 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/jvm/K2JvmCliTest.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/jvm/K2JvmCliTest.java @@ -17,11 +17,8 @@ package org.jetbrains.kotlin.cli.jvm; import org.jetbrains.kotlin.cli.CliBaseTest; -import org.junit.Assert; import org.junit.Test; -import java.io.File; - public class K2JvmCliTest extends CliBaseTest { @Test public void wrongAbiVersion() throws Exception { @@ -36,8 +33,6 @@ public class K2JvmCliTest extends CliBaseTest { @Test public void nonExistingClassPathAndAnnotationsPath() throws Exception { executeCompilerCompareOutputJVM(); - - Assert.assertTrue(new File(tmpdir.getTmpDir(), "SimpleKt.class").isFile()); } @Test