From 8cd2d2e44cf27115c56769422bad7d921af52070 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Fri, 25 May 2018 14:08:05 +0300 Subject: [PATCH] Support `WITH_UNSIGNED` kind in diagnostics tests, add tests --- .../unsignedLiteralsInsideConstVals.kt | 8 ++++ .../unsignedLiteralsInsideConstVals.txt | 7 ++++ .../unsignedLiteralsTypeCheck.kt | 25 +++++++++++ .../unsignedLiteralsTypeCheck.txt | 17 ++++++++ .../AbstractDiagnosticsWithUnsignedTypes.kt | 14 +++++++ ...DiagnosticsWithUnsignedTypesGenerated.java | 41 +++++++++++++++++++ .../generators/tests/GenerateCompilerTests.kt | 4 ++ 7 files changed, 116 insertions(+) create mode 100644 compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsInsideConstVals.kt create mode 100644 compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsInsideConstVals.txt create mode 100644 compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsTypeCheck.kt create mode 100644 compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsTypeCheck.txt create mode 100644 compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsWithUnsignedTypes.kt create mode 100644 compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsWithUnsignedTypesGenerated.java diff --git a/compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsInsideConstVals.kt b/compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsInsideConstVals.kt new file mode 100644 index 00000000000..7f58c80cfab --- /dev/null +++ b/compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsInsideConstVals.kt @@ -0,0 +1,8 @@ +// !LANGUAGE: +InlineClasses +// !SKIP_METADATA_VERSION_CHECK + +const val u0 = 1u +const val u1: UByte = 2u +const val u2: UShort = 3u +const val u3: UInt = 3u +const val u4: ULong = 4u diff --git a/compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsInsideConstVals.txt b/compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsInsideConstVals.txt new file mode 100644 index 00000000000..5d9c84da6b5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsInsideConstVals.txt @@ -0,0 +1,7 @@ +package + +public const val u0: kotlin.UInt = 1.toUInt() +public const val u1: kotlin.UByte = 2.toUByte() +public const val u2: kotlin.UShort = 3.toUShort() +public const val u3: kotlin.UInt = 3.toUInt() +public const val u4: kotlin.ULong = 4.toULong() diff --git a/compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsTypeCheck.kt b/compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsTypeCheck.kt new file mode 100644 index 00000000000..a47fae4cd8e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsTypeCheck.kt @@ -0,0 +1,25 @@ +// !LANGUAGE: +InlineClasses +// !SKIP_METADATA_VERSION_CHECK + +val a0: Any = 1u + +val n0: Number = 1u + +val c0: Comparable<*> = 1u +val c1: Comparable = 1u + +val u0: UInt = 1u +val u1: UInt? = 1u +val u2: UInt? = u0 +val u3: UInt? = u1 + +val i0: Int = 1u + +val m0 = -1u +val m1: UInt = -1u + +val h1 = 0xFFu +val h2: UShort = 0xFFu + +val b1 = 0b11u +val b2: UByte = 0b11u \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsTypeCheck.txt b/compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsTypeCheck.txt new file mode 100644 index 00000000000..9bb84503afa --- /dev/null +++ b/compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsTypeCheck.txt @@ -0,0 +1,17 @@ +package + +public val a0: kotlin.Any = 1.toUInt() +public val b1: kotlin.UInt = 3.toUInt() +public val b2: kotlin.UByte = 3.toUByte() +public val c0: kotlin.Comparable<*> +public val c1: kotlin.Comparable +public val h1: kotlin.UInt = 255.toUInt() +public val h2: kotlin.UShort = 255.toUShort() +public val i0: kotlin.Int = 1.toUInt() +public val m0: [ERROR : Type for -1u] +public val m1: kotlin.UInt +public val n0: kotlin.Number = 1.toUInt() +public val u0: kotlin.UInt = 1.toUInt() +public val u1: kotlin.UInt? = 1.toUInt() +public val u2: kotlin.UInt? = 1 +public val u3: kotlin.UInt? = 1 diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsWithUnsignedTypes.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsWithUnsignedTypes.kt new file mode 100644 index 00000000000..15022085a3e --- /dev/null +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/checkers/AbstractDiagnosticsWithUnsignedTypes.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.checkers + +import org.jetbrains.kotlin.test.ConfigurationKind + +abstract class AbstractDiagnosticsWithUnsignedTypes : AbstractDiagnosticsTest() { + override fun getConfigurationKind(): ConfigurationKind { + return ConfigurationKind.WITH_UNSIGNED_TYPES + } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsWithUnsignedTypesGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsWithUnsignedTypesGenerated.java new file mode 100644 index 00000000000..00eb3aa1e59 --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsWithUnsignedTypesGenerated.java @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.checkers; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.KotlinTestUtils; +import org.jetbrains.kotlin.test.TargetBackend; +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/diagnostics/testsWithUnsignedTypes") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class DiagnosticsWithUnsignedTypesGenerated extends AbstractDiagnosticsWithUnsignedTypes { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInTestsWithUnsignedTypes() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithUnsignedTypes"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("unsignedLiteralsInsideConstVals.kt") + public void testUnsignedLiteralsInsideConstVals() throws Exception { + runTest("compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsInsideConstVals.kt"); + } + + @TestMetadata("unsignedLiteralsTypeCheck.kt") + public void testUnsignedLiteralsTypeCheck() throws Exception { + runTest("compiler/testData/diagnostics/testsWithUnsignedTypes/unsignedLiteralsTypeCheck.kt"); + } +} diff --git a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt index f528185af80..585a4e1ad55 100644 --- a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt +++ b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt @@ -106,6 +106,10 @@ fun main(args: Array) { model("diagnostics/testsWithJava9") } + testClass { + model("diagnostics/testsWithUnsignedTypes") + } + testClass { model("multiplatform", extension = null, recursive = true, excludeParentDirs = true) }