CLI tests: move file existance checks to config files

This commit is contained in:
Alexander Udalov
2016-02-08 21:02:58 +05:30
committed by Alexander Udalov
parent 7a6cc71454
commit 3b22483fb2
20 changed files with 60 additions and 46 deletions
+2
View File
@@ -0,0 +1,2 @@
// EXISTS: jslib-example.js
// EXISTS: jslib-example/library/sample/ClassA.kjsm
+3
View File
@@ -0,0 +1,3 @@
// EXISTS: jslib-example.meta.js
// EXISTS: jslib-example.js
// EXISTS: jslib-example/library/sample/ClassA.kjsm
+1
View File
@@ -0,0 +1 @@
// ABSENT: out.js
+1
View File
@@ -0,0 +1 @@
// ABSENT: out.js
+1
View File
@@ -0,0 +1 @@
// ABSENT: out.js
+1
View File
@@ -0,0 +1 @@
// ABSENT: out.js
+1
View File
@@ -0,0 +1 @@
// ABSENT: out.js
@@ -0,0 +1 @@
// ABSENT: out.js
@@ -0,0 +1 @@
// ABSENT: out.js
+1
View File
@@ -0,0 +1 @@
// EXISTS: out.js
+1
View File
@@ -0,0 +1 @@
// EXISTS: out.js
+1
View File
@@ -0,0 +1 @@
// EXISTS: out.js
+1
View File
@@ -0,0 +1 @@
// ABSENT: out.js
+1
View File
@@ -0,0 +1 @@
// EXISTS: SimpleKt.class
@@ -0,0 +1 @@
// EXISTS: SimpleKt.class
+1
View File
@@ -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.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<String, ExitCode> 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<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
@@ -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
@@ -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());
}
}
@@ -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