Skip to content

Commit

Permalink
[TEST] 2/2 Allow TEST_ONLY language features during testing
Browse files Browse the repository at this point in the history
KT-75113

The commit fixes a bunch of org.jetbrains.kotlin.konan.test.blackbox.FirNativeCodegenBoxTestGenerated tests,
that got broken by the previous commit. In total, 53 tests were broken
by the previous commit.

The downside of this commit is that it's no longer possible to "test"
the effect of `TEST_ONLY` in our test infra. Well, yes, it's part of the
contract of `TEST_ONLY`, I think it's fine, that's why I have to remove
`internalArgTestOnlyFeature` test
  • Loading branch information
nikitabobko authored and Space Team committed Feb 13, 2025
1 parent 439025e commit 66e54d8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.jetbrains.kotlin.cli.common.arguments

import com.intellij.openapi.application.ApplicationManager
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.config.LanguageFeature

Expand Down Expand Up @@ -74,7 +75,7 @@ class LanguageSettingsParser : AbstractInternalArgumentParser<ManualLanguageFeat
val languageFeature = LanguageFeature.fromString(languageFeatureName)
?: return reportAndReturnNull("Unknown language feature '$languageFeatureName' in passed internal argument '$wholeArgument'")

if (languageFeature.kind.testOnly) {
if (languageFeature.kind.testOnly && !areTestOnlyLanguageFeaturesAllowed) {
reportAndReturnNull(
"Language feature '$languageFeatureName' is test-only and cannot be enabled from command line",
severity = CompilerMessageSeverity.ERROR
Expand All @@ -85,6 +86,15 @@ class LanguageSettingsParser : AbstractInternalArgumentParser<ManualLanguageFeat
}
}

fun allowTestsOnlyLanguageFeatures() {
System.setProperty("kotlinc.test.allow.testonly.language.features", "true")
}

private val areTestOnlyLanguageFeaturesAllowed: Boolean by lazy {
// Use system property because test infra in K/N uses an "isolated" classloader
System.getProperty("kotlinc.test.allow.testonly.language.features")?.toBoolean() == true
}

interface InternalArgument {
val stringRepresentation: String
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.jetbrains.kotlin.konan.test.blackbox

import com.intellij.testFramework.TestDataFile
import org.jetbrains.kotlin.cli.common.arguments.allowTestsOnlyLanguageFeatures
import org.jetbrains.kotlin.konan.test.blackbox.support.NativeBlackBoxTestSupport
import org.jetbrains.kotlin.konan.test.blackbox.support.PackageName
import org.jetbrains.kotlin.konan.test.blackbox.support.TestCaseId
Expand Down Expand Up @@ -35,6 +36,7 @@ abstract class AbstractNativeBlackBoxTest {
* This function should be called from a method annotated with [org.junit.jupiter.api.Test].
*/
open fun runTest(@TestDataFile testDataFilePath: String) {
allowTestsOnlyLanguageFeatures()
val absoluteTestFile = getAbsoluteFile(testDataFilePath)
val testCaseId = TestCaseId.TestDataFile(absoluteTestFile)
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@

package org.jetbrains.kotlin.konan.test.blackbox

import org.jetbrains.kotlin.cli.common.arguments.allowTestsOnlyLanguageFeatures
import org.jetbrains.kotlin.konan.test.blackbox.support.NativeSimpleTestSupport
import org.jetbrains.kotlin.konan.test.blackbox.support.TestCase
import org.jetbrains.kotlin.konan.test.blackbox.support.runner.SimpleTestRunProvider
import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestExecutable
import org.jetbrains.kotlin.konan.test.blackbox.support.runner.TestRunners.createProperTestRunner
import org.jetbrains.kotlin.konan.test.blackbox.support.settings.SimpleTestRunSettings
import org.jetbrains.kotlin.test.backend.handlers.UpdateTestDataSupport
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.extension.ExtendWith

@ExtendWith(NativeSimpleTestSupport::class, UpdateTestDataSupport::class)
abstract class AbstractNativeSimpleTest {
lateinit var testRunSettings: SimpleTestRunSettings
internal lateinit var testRunProvider: SimpleTestRunProvider

@BeforeEach
fun setup() {
allowTestsOnlyLanguageFeatures()
}

fun runExecutableAndVerify(testCase: TestCase, executable: TestExecutable) {
val testRun = testRunProvider.getTestRun(testCase, executable)
val testRunner = createProperTestRunner(testRun, testRunSettings)
Expand Down

0 comments on commit 66e54d8

Please sign in to comment.