Skip to content

Commit abfc304

Browse files
committed
[Tests] Implement integration test runner for IJ
#JBRes-6600 Done
1 parent 299751f commit abfc304

File tree

8 files changed

+138
-5
lines changed

8 files changed

+138
-5
lines changed

buildSrc/src/main/kotlin/TraceAgentIntegrationTestsTasks.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ private val projectsToTest = listOf(
4949
repositoryName = "kotlinx-datetime",
5050
commitHash = "deb897d7c6df11734d0468527cc7ebfc41679a94"
5151
),
52+
GithubProjectSnapshot(
53+
organization = "ivandev0",
54+
repositoryName = "intellij-community",
55+
commitHash = "8f65df6d733acefffc32bbeb86538ffd45ca260a"
56+
),
5257
)
5358

5459
lateinit var traceAgentIntegrationTestsPrerequisites: TaskProvider<Task>

integration-test/common/src/main/AbstractGradleTraceIntegrationTest.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ abstract class AbstractGradleTraceIntegrationTest: AbstractTraceIntegrationTest(
6565
extraJvmArgs: List<String>,
6666
extraAgentArgs: Map<String, String>,
6767
): String {
68-
fun String.escapeDollar() = replace("$", "\\$")
69-
70-
val pathToFatJar = File(Paths.get("build", "libs", fatJarName).toString()).absolutePath.escape()
7168
// We need to escape it twice, as our argument parser will de-escape it when split into array
7269
val pathToOutput = fileToDump.absolutePath.escape().escape()
7370
val agentArgs =
@@ -94,6 +91,4 @@ abstract class AbstractGradleTraceIntegrationTest: AbstractTraceIntegrationTest(
9491
}
9592
""".trimIndent()
9693
}
97-
98-
private fun String.escape(): String = this.replace("\\", "\\\\")
9994
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Lincheck
3+
*
4+
* Copyright (C) 2019 - 2025 JetBrains s.r.o.
5+
*
6+
* This Source Code Form is subject to the terms of the
7+
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
8+
* with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
import java.io.File
12+
13+
abstract class AbstractIntellijTraceIntegrationTest: AbstractTraceIntegrationTest() {
14+
override val fatJarName: String = "trace-recorder-fat.jar"
15+
16+
override fun runTestImpl(
17+
testClassName: String,
18+
testMethodName: String,
19+
extraJvmArgs: List<String>,
20+
extraAgentArgs: Map<String, String>,
21+
commands: List<String>,
22+
outputFile: File
23+
) {
24+
if (!File("$projectPath/android").exists()) {
25+
ProcessBuilder("$projectPath/getPlugins.sh")
26+
.directory(File(projectPath))
27+
.inheritIO().start().waitFor()
28+
}
29+
30+
// We need to escape it twice, as our argument parser will de-escape it when split into array
31+
val pathToOutput = outputFile.absolutePath.escape().escape()
32+
ProcessBuilder(
33+
"./tests.cmd",
34+
"-Dintellij.build.test.patterns=${testClassName.escapeDollar()}",
35+
"-Dintellij.build.test.trace.recorder.enabled=true",
36+
"-Dintellij.build.test.trace.recorder.className=${testClassName.escapeDollar()}",
37+
"-Dintellij.build.test.trace.recorder.methodName=${testMethodName.escapeDollar()}",
38+
"-Dintellij.build.test.trace.recorder.traceDump=$pathToOutput",
39+
"-Dintellij.build.test.trace.recorder.agentJar=$pathToFatJar"
40+
).directory(File(projectPath))
41+
.inheritIO().start().waitFor()
42+
}
43+
}

integration-test/common/src/main/AbstractTraceIntegrationTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ abstract class AbstractTraceIntegrationTest {
2121
abstract val fatJarName: String
2222
abstract val projectPath: String
2323

24+
protected val pathToFatJar: String
25+
get() = File(Paths.get("build", "libs", fatJarName).toString()).absolutePath.escape()
26+
2427
private fun getGoldenDataFileFor(
2528
testClassName: String,
2629
testMethodName: String,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Lincheck
3+
*
4+
* Copyright (C) 2019 - 2025 JetBrains s.r.o.
5+
*
6+
* This Source Code Form is subject to the terms of the
7+
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
8+
* with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
fun String.escape(): String = this.replace("\\", "\\\\")
12+
fun String.escapeDollar() = replace("$", "\\$")
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Lincheck
3+
*
4+
* Copyright (C) 2019 - 2025 JetBrains s.r.o.
5+
*
6+
* This Source Code Form is subject to the terms of the
7+
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
8+
* with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
package org.jetbrains.trace.recorder.test.impl
12+
13+
import AbstractIntellijTraceIntegrationTest
14+
import AbstractTraceIntegrationTest
15+
import org.jetbrains.trace.recorder.test.runner.AbstractTraceRecorderIntegrationTest
16+
import org.jetbrains.trace.recorder.test.runner.ExtendedTraceRecorderTest
17+
import org.jetbrains.trace.recorder.test.runner.loadResourceText
18+
import org.jetbrains.trace.recorder.test.runner.parseJsonEntries
19+
import org.jetbrains.trace.recorder.test.runner.transformEntriesToArray
20+
import org.junit.Test
21+
import org.junit.experimental.categories.Category
22+
import org.junit.experimental.runners.Enclosed
23+
import org.junit.runner.RunWith
24+
import org.junit.runners.Parameterized
25+
import java.nio.file.Paths
26+
27+
@RunWith(Enclosed::class)
28+
class IntellijTraceRecorderIntegrationTest {
29+
@Category(ExtendedTraceRecorderTest::class)
30+
@RunWith(Parameterized::class)
31+
class Parametrized(
32+
private val testClassName: String,
33+
private val testMethodName: String,
34+
@Suppress("unused") private val gradleCommand: String,
35+
private val perEntryJvmArgs: List<String>,
36+
private val perEntryCheckRepresentation: Boolean,
37+
) : AbstractIntellijTraceIntegrationTest() {
38+
override val projectPath: String = Paths.get("build", "integrationTestProjects", "intellij-community").toAbsolutePath().toString()
39+
40+
@Test(timeout = 30 * 60 * 1000L)
41+
fun runIntellijTest() = runTest(
42+
testClassName = testClassName,
43+
testMethodName = testMethodName,
44+
extraJvmArgs = perEntryJvmArgs,
45+
extraAgentArgs = emptyMap(),
46+
commands = emptyList(),
47+
checkRepresentation = perEntryCheckRepresentation
48+
)
49+
50+
companion object {
51+
@JvmStatic
52+
@Parameterized.Parameters(name = "{index}: {0}::{1}")
53+
fun data(): Collection<Array<Any>> {
54+
val json = loadResourceText(
55+
"/integrationTestData/intellijTests.json",
56+
IntellijTraceRecorderIntegrationTest::class.java
57+
)
58+
val entries = parseJsonEntries(json)
59+
return entries.transformEntriesToArray()
60+
}
61+
}
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Thread 1
2+
ArrayUtilTest.testInsertString() at :0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"class": "com.intellij.util.ArrayUtilTest",
4+
"gradleCommand": ":kotlinx-collections-immutable:jvmTest",
5+
"methods": [
6+
"testInsertString"
7+
],
8+
"checkRepresentation": true
9+
}
10+
]

0 commit comments

Comments
 (0)