Replace JS metadata version with '$ABI_VERSION$' in tests

Similarly to the JVM metadata version, this is done in order to avoid
changing any test data when the version is increased
This commit is contained in:
Alexander Udalov
2017-03-20 11:24:45 +03:00
parent e6f6b0dad5
commit 87ff70ee0f
4 changed files with 14 additions and 18 deletions
@@ -1,2 +1,2 @@
error: file '$TMP_DIR$/library.meta.js' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 42.0.0, expected version is 1.0.0 error: file '$TMP_DIR$/library.meta.js' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 42.0.0, expected version is $ABI_VERSION$
COMPILATION_ERROR COMPILATION_ERROR
@@ -31,7 +31,6 @@ 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.config.KotlinCompilerVersion; import org.jetbrains.kotlin.config.KotlinCompilerVersion;
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.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.TestCaseWithTmpdir; import org.jetbrains.kotlin.test.TestCaseWithTmpdir;
@@ -67,18 +66,14 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
} }
@NotNull @NotNull
public static String getNormalizedCompilerOutput( public static String getNormalizedCompilerOutput(@NotNull String pureOutput, @NotNull ExitCode exitCode, @NotNull String testDataDir) {
@NotNull String pureOutput,
@NotNull ExitCode exitCode,
@NotNull String testDataDir,
@NotNull BinaryVersion version
) {
String testDataAbsoluteDir = new File(testDataDir).getAbsolutePath(); String testDataAbsoluteDir = new File(testDataDir).getAbsolutePath();
String normalizedOutputWithoutExitCode = StringUtil.convertLineSeparators(pureOutput) String normalizedOutputWithoutExitCode = StringUtil.convertLineSeparators(pureOutput)
.replace(testDataAbsoluteDir, "$TESTDATA_DIR$") .replace(testDataAbsoluteDir, "$TESTDATA_DIR$")
.replace(FileUtil.toSystemIndependentName(testDataAbsoluteDir), "$TESTDATA_DIR$") .replace(FileUtil.toSystemIndependentName(testDataAbsoluteDir), "$TESTDATA_DIR$")
.replace(PathUtil.getKotlinPathsForDistDirectory().getHomePath().getAbsolutePath(), "$PROJECT_DIR$") .replace(PathUtil.getKotlinPathsForDistDirectory().getHomePath().getAbsolutePath(), "$PROJECT_DIR$")
.replace("expected version is " + version, "expected version is $ABI_VERSION$") .replace("expected version is " + JvmMetadataVersion.INSTANCE, "expected version is $ABI_VERSION$")
.replace("expected version is " + JsMetadataVersion.INSTANCE, "expected version is $ABI_VERSION$")
.replace("\\", "/") .replace("\\", "/")
.replaceAll("^.+running the Kotlin compiler under Java 6 or 7 is unsupported and will no longer be possible in a future update\\.\n", "") .replaceAll("^.+running the Kotlin compiler under Java 6 or 7 is unsupported and will no longer be possible in a future update\\.\n", "")
.replace(KotlinCompilerVersion.VERSION, "$VERSION$"); .replace(KotlinCompilerVersion.VERSION, "$VERSION$");
@@ -86,11 +81,11 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
return normalizedOutputWithoutExitCode + exitCode; return normalizedOutputWithoutExitCode + exitCode;
} }
private void doTest(@NotNull String fileName, @NotNull CLICompiler<?> compiler, BinaryVersion version) throws Exception { private void doTest(@NotNull String fileName, @NotNull CLICompiler<?> compiler) throws Exception {
System.setProperty("java.awt.headless", "true"); System.setProperty("java.awt.headless", "true");
Pair<String, ExitCode> outputAndExitCode = executeCompilerGrabOutput(compiler, readArgs(fileName, tmpdir.getPath())); Pair<String, ExitCode> outputAndExitCode = executeCompilerGrabOutput(compiler, readArgs(fileName, tmpdir.getPath()));
String actual = getNormalizedCompilerOutput( String actual = getNormalizedCompilerOutput(
outputAndExitCode.getFirst(), outputAndExitCode.getSecond(), new File(fileName).getParent(), version outputAndExitCode.getFirst(), outputAndExitCode.getSecond(), new File(fileName).getParent()
); );
File outFile = new File(fileName.replaceFirst("\\.args$", ".out")); File outFile = new File(fileName.replaceFirst("\\.args$", ".out"));
@@ -156,11 +151,11 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
} }
protected void doJvmTest(@NotNull String fileName) throws Exception { protected void doJvmTest(@NotNull String fileName) throws Exception {
doTest(fileName, new K2JVMCompiler(), JvmMetadataVersion.INSTANCE); doTest(fileName, new K2JVMCompiler());
} }
protected void doJsTest(@NotNull String fileName) throws Exception { protected void doJsTest(@NotNull String fileName) throws Exception {
doTest(fileName, new K2JSCompiler(), JsMetadataVersion.INSTANCE); doTest(fileName, new K2JSCompiler());
} }
public static String removePerfOutput(String output) { public static String removePerfOutput(String output) {
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil
import org.jetbrains.kotlin.load.java.JvmAnnotationNames import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion import org.jetbrains.kotlin.load.java.JvmBytecodeBinaryVersion
import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion
import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
import org.jetbrains.org.objectweb.asm.* import org.jetbrains.org.objectweb.asm.*
@@ -54,7 +55,8 @@ class WrongBytecodeVersionTest : KtUsefulTestCase() {
assertEquals("Compilation error expected", ExitCode.COMPILATION_ERROR, exitCode) assertEquals("Compilation error expected", ExitCode.COMPILATION_ERROR, exitCode)
val normalized = AbstractCliTest.getNormalizedCompilerOutput(output, exitCode, tmpdir.path, JvmBytecodeBinaryVersion.INSTANCE) val normalized = AbstractCliTest.getNormalizedCompilerOutput(output, exitCode, tmpdir.path)
.replace("expected version is ${JvmBytecodeBinaryVersion.INSTANCE}", "expected version is \$ABI_VERSION\$")
KotlinTestUtils.assertEqualsToFile(File(directory, "output.txt"), normalized) KotlinTestUtils.assertEqualsToFile(File(directory, "output.txt"), normalized)
} }
@@ -109,9 +109,8 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
@NotNull @NotNull
private String normalizeOutput(@NotNull Pair<String, ExitCode> output) { private String normalizeOutput(@NotNull Pair<String, ExitCode> output) {
return AbstractCliTest.getNormalizedCompilerOutput( return AbstractCliTest.getNormalizedCompilerOutput(output.getFirst(), output.getSecond(), getTestDataDirectory().getPath())
output.getFirst(), output.getSecond(), getTestDataDirectory().getPath(), JvmMetadataVersion.INSTANCE .replace(FileUtil.toSystemIndependentName(tmpdir.getAbsolutePath()), "$TMP_DIR$");
).replace(FileUtil.toSystemIndependentName(tmpdir.getAbsolutePath()), "$TMP_DIR$");
} }
private void doTestWithTxt(@NotNull File... extraClassPath) throws Exception { private void doTestWithTxt(@NotNull File... extraClassPath) throws Exception {