Move ensureCorrectVersion to the shared module and reuse it with JUnit5.

There also should be an error, not skip. Broken environment shouldn't pass silently.

GitOrigin-RevId: 847fd28db1b809693acdef73a41b816f7fdcfb65
This commit is contained in:
Ilya.Kazakevich
2024-07-16 20:38:55 +02:00
committed by intellij-monorepo-bot
parent fdb0da5997
commit b25a5eedf0
2 changed files with 27 additions and 16 deletions

View File

@@ -3,8 +3,8 @@ package com.intellij.execution.wsl
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.util.io.IoTestUtil
import com.intellij.testFramework.ensureCorrectVersion
import org.junit.Assume.assumeTrue
import org.junit.jupiter.api.Assumptions
import org.junit.rules.ExternalResource
import java.io.IOException
import kotlin.io.path.exists
@@ -36,21 +36,6 @@ class WslFixture private constructor(val vms: List<WSLDistribution>) {
companion object {
private val LOG = logger<WslFixture>()
fun ensureCorrectVersion(wsl: WSLDistribution) {
System.getenv("WSL_VERSION")?.let {
if (it.toInt() != wsl.version) {
val error = """
Variable provided by environment claims WSL is $it.
But wsl is ${wsl.version}.
Hence, environment provides wrong information.
With all of that, test can't continue. Fix your environment.
""".trimIndent()
logger<WslRule>().warn(error)
Assumptions.abort<Nothing>(error)
}
}
}
@JvmStatic
fun create(assume: Boolean = true): WslFixture {
if (assume) {

View File

@@ -0,0 +1,26 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.testFramework
import com.intellij.execution.wsl.WSLDistribution
import com.intellij.openapi.diagnostic.Logger
private val LOGGER = Logger.getInstance("WslTeamCityTestTool")
/**
* Early failure for IJI-1731
*/
fun ensureCorrectVersion(wsl: WSLDistribution) {
System.getenv("WSL_VERSION")?.let { // This var must be set on TC manually
if (it.toInt() != wsl.version) {
val error = """
Variable provided by environment claims WSL is $it.
But wsl is ${wsl.version}.
Hence, environment provides wrong information.
With all of that, test can't continue. Fix your environment.
""".trimIndent()
LOGGER.error(error)
error(error)
}
}
}