CLI tests: move file existance checks to config files
This commit is contained in:
committed by
Alexander Udalov
parent
7a6cc71454
commit
3b22483fb2
+2
@@ -0,0 +1,2 @@
|
|||||||
|
// EXISTS: jslib-example.js
|
||||||
|
// EXISTS: jslib-example/library/sample/ClassA.kjsm
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// EXISTS: jslib-example.meta.js
|
||||||
|
// EXISTS: jslib-example.js
|
||||||
|
// EXISTS: jslib-example/library/sample/ClassA.kjsm
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
// ABSENT: out.js
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// ABSENT: out.js
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// ABSENT: out.js
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// ABSENT: out.js
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// ABSENT: out.js
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// ABSENT: out.js
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// ABSENT: out.js
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
// EXISTS: out.js
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// EXISTS: out.js
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
// EXISTS: out.js
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// ABSENT: out.js
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// EXISTS: SimpleKt.class
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// EXISTS: SimpleKt.class
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
// EXISTS: SimpleKt.class
|
||||||
@@ -30,10 +30,13 @@ import org.jetbrains.kotlin.cli.js.K2JSCompiler;
|
|||||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
|
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
|
||||||
import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion;
|
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.KotlinTestUtils;
|
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||||
import org.jetbrains.kotlin.test.Tmpdir;
|
import org.jetbrains.kotlin.test.Tmpdir;
|
||||||
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.junit.Assert;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.rules.TestName;
|
import org.junit.rules.TestName;
|
||||||
|
|
||||||
@@ -41,6 +44,7 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CliBaseTest {
|
public class CliBaseTest {
|
||||||
@@ -93,12 +97,47 @@ 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();
|
||||||
Pair<String, ExitCode> outputAndExitCode =
|
Pair<String, ExitCode> outputAndExitCode =
|
||||||
executeCompilerGrabOutput(compiler, readArgs(testDataDir + "/" + testName.getMethodName() + ".args", testDataDir,
|
executeCompilerGrabOutput(compiler, readArgs(testDataDir + "/" + testMethodName + ".args", testDataDir,
|
||||||
tmpdir.getTmpDir().getPath()));
|
tmpdir.getTmpDir().getPath()));
|
||||||
String actual = getNormalizedCompilerOutput(outputAndExitCode.getFirst(), outputAndExitCode.getSecond(), testDataDir);
|
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<String> diagnostics = new ArrayList<String>(0);
|
||||||
|
String content = FilesKt.readText(testConfigFile, Charsets.UTF_8);
|
||||||
|
|
||||||
|
List<String> 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<String> 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
|
@NotNull
|
||||||
|
|||||||
@@ -16,11 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.cli;
|
package org.jetbrains.kotlin.cli;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class CliCommonTest extends CliBaseTest {
|
public class CliCommonTest extends CliBaseTest {
|
||||||
@Test
|
@Test
|
||||||
public void help() throws Exception {
|
public void help() throws Exception {
|
||||||
@@ -35,15 +32,11 @@ public class CliCommonTest extends CliBaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void simple() throws Exception {
|
public void simple() throws Exception {
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
|
|
||||||
Assert.assertTrue(new File(tmpdir.getTmpDir(), "SimpleKt.class").isFile());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void duplicateSources() throws Exception {
|
public void duplicateSources() throws Exception {
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
|
|
||||||
Assert.assertTrue(new File(tmpdir.getTmpDir(), "SimpleKt.class").isFile());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -17,59 +17,42 @@
|
|||||||
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.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class K2JsCliTest extends CliBaseTest {
|
public class K2JsCliTest extends CliBaseTest {
|
||||||
@Test
|
@Test
|
||||||
public void simple2js() throws Exception {
|
public void simple2js() throws Exception {
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
|
|
||||||
Assert.assertTrue(new File(tmpdir.getTmpDir(), "out.js").isFile());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void outputIsDirectory() throws Exception {
|
public void outputIsDirectory() throws Exception {
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
|
|
||||||
Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").exists());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nonExistingSourcePath() throws Exception {
|
public void nonExistingSourcePath() throws Exception {
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
|
|
||||||
Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").exists());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptySources() throws Exception {
|
public void emptySources() throws Exception {
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
|
|
||||||
Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").exists());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void outputPrefixFileNotFound() throws Exception {
|
public void outputPrefixFileNotFound() throws Exception {
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
|
|
||||||
Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").exists());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void outputPostfixFileNotFound() throws Exception {
|
public void outputPostfixFileNotFound() throws Exception {
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
|
|
||||||
Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").exists());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void wrongAbiVersion() throws Exception {
|
public void wrongAbiVersion() throws Exception {
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
|
|
||||||
Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").exists());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -80,45 +63,30 @@ public class K2JsCliTest extends CliBaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void withLib() throws Exception {
|
public void withLib() throws Exception {
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
|
|
||||||
Assert.assertTrue(new File(tmpdir.getTmpDir(), "out.js").isFile());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withFolderAsLib() throws Exception {
|
public void withFolderAsLib() throws Exception {
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
|
|
||||||
Assert.assertTrue(new File(tmpdir.getTmpDir(), "out.js").isFile());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createMetadata() throws Exception {
|
public void createMetadata() throws Exception {
|
||||||
executeCompilerCompareOutputJS();
|
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
|
@Test
|
||||||
public void createKjsm() throws Exception {
|
public void createKjsm() throws Exception {
|
||||||
executeCompilerCompareOutputJS();
|
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
|
@Test
|
||||||
public void libraryDirNotFound() throws Exception {
|
public void libraryDirNotFound() throws Exception {
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
|
|
||||||
Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").isFile());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notValidLibraryDir() throws Exception {
|
public void notValidLibraryDir() throws Exception {
|
||||||
executeCompilerCompareOutputJS();
|
executeCompilerCompareOutputJS();
|
||||||
|
|
||||||
Assert.assertFalse(new File(tmpdir.getTmpDir(), "out.js").isFile());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,8 @@
|
|||||||
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.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class K2JvmCliTest extends CliBaseTest {
|
public class K2JvmCliTest extends CliBaseTest {
|
||||||
@Test
|
@Test
|
||||||
public void wrongAbiVersion() throws Exception {
|
public void wrongAbiVersion() throws Exception {
|
||||||
@@ -36,8 +33,6 @@ public class K2JvmCliTest extends CliBaseTest {
|
|||||||
@Test
|
@Test
|
||||||
public void nonExistingClassPathAndAnnotationsPath() throws Exception {
|
public void nonExistingClassPathAndAnnotationsPath() throws Exception {
|
||||||
executeCompilerCompareOutputJVM();
|
executeCompilerCompareOutputJVM();
|
||||||
|
|
||||||
Assert.assertTrue(new File(tmpdir.getTmpDir(), "SimpleKt.class").isFile());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user