дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-25 10:54:44 +02:00
Gutter Run / Debug of JUnit 5 tests in Maven modules now starts OpenIDEA's own JUnit Platform runner (java/junit-runner, built from the in-tree source and embedded by ide-sdk) on the language server's test classpath instead of mvn test, as IDEA runs Maven tests unless build/run actions are delegated to Maven. The runner reports TeamCity service messages to the existing test tree; Debug and Rerun Failed Tests reuse it. The launcher jar of the engine's version comes from the classpath, else from the engine's Maven/Gradle repository folder, else is downloaded once from Maven Central.
The runner JVM gets the module's Surefire configuration like IDEA's MavenJUnitPatcher: argLine (with @{...} late replacement), systemPropertyVariables / systemProperties, environmentVariables, workingDirectory, additionalClasspathElements and classpathDependencyExcludes, read from the cached effective POM (else the module POM); the console lists what was applied.
Settings › Build Tools › Maven › Run tests using: OpenIDEA (default) or Maven (the previous mvn test -Dtest=... path). JUnit 4-only, TestNG and Gradle tests keep their current runners.
Closes #5553
Co-authored-by: wildcatDownstairs <[email protected]>
70 рядки
3.6 KiB
Python
70 рядки
3.6 KiB
Python
"""Build the committed JUnit Platform runner (Java 8 bytecode), or test it: python3 build.py [--test].
|
|
|
|
Compiles against the JUnit jars of build-dependencies.sha256, taken from the local Maven
|
|
repository (MAVEN_REPO, default ~/.m2/repository; `mvn dependency:get` fetches a missing one).
|
|
--test runs tests/SampleTest.java through the runner and checks its service messages."""
|
|
import hashlib
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import zipfile
|
|
|
|
root = Path(__file__).resolve().parent
|
|
repo = Path(os.environ.get("MAVEN_REPO", Path.home() / ".m2" / "repository"))
|
|
java_home = os.environ.get("JAVA_HOME")
|
|
test = "--test" in sys.argv[1:]
|
|
|
|
|
|
def tool(name):
|
|
return str(Path(java_home) / "bin" / name) if java_home else name
|
|
|
|
|
|
jars = []
|
|
for line in (root / "build-dependencies.sha256").read_text().splitlines():
|
|
digest, path = line.split()
|
|
jar = repo / path
|
|
if hashlib.sha256(jar.read_bytes()).hexdigest() != digest:
|
|
sys.exit(f"{jar}: SHA-256 mismatch")
|
|
jars.append(str(jar))
|
|
# The launcher API only: the runner must not depend on an engine.
|
|
api = [j for j in jars if "/junit-platform-" in j or "apiguardian" in j]
|
|
|
|
with tempfile.TemporaryDirectory() as scratch:
|
|
classes = Path(scratch) / "classes"
|
|
sources = sorted((root / "src").rglob("*.java"))
|
|
subprocess.run([tool("javac"), "--release", "8", "-encoding", "UTF-8", "-g", "-Xlint:-options",
|
|
"-cp", os.pathsep.join(api), "-d", str(classes), *map(str, sources)], check=True)
|
|
if test:
|
|
sample = Path(scratch) / "sample"
|
|
cp = os.pathsep.join(jars)
|
|
subprocess.run([tool("javac"), "-encoding", "UTF-8", "-cp", cp, "-d", str(sample),
|
|
str(root / "tests" / "SampleTest.java")], check=True)
|
|
run = subprocess.run([tool("java"), "-cp", os.pathsep.join([str(classes), str(sample), cp]),
|
|
"ai.openidea.junit.Runner", "sample.SampleTest"], capture_output=True)
|
|
out = run.stdout.decode("utf-8")
|
|
print(out)
|
|
expected = [
|
|
"##teamcity[testStarted name='passes' className='sample.SampleTest']",
|
|
"##teamcity[testStdOut name='passes' className='sample.SampleTest' out='hello |[ünï|]|n']",
|
|
"##teamcity[testFailed name='fails' className='sample.SampleTest' message='org.opentest4j.AssertionFailedError: it|'s wrong ==> expected: <1> but was: <2>'",
|
|
"##teamcity[testIgnored name='disabled' className='sample.SampleTest'",
|
|
"##teamcity[testIgnored name='aborted' className='sample.SampleTest']",
|
|
"##teamcity[testFailed name='parameterized' className='sample.SampleTest'",
|
|
"##teamcity[testFinished name='nested' className='sample.SampleTest$Inner' duration=",
|
|
"7 tests completed, 2 failed, 2 skipped",
|
|
]
|
|
missing = [e for e in expected if e not in out]
|
|
assert not missing, missing
|
|
assert run.returncode == 1, run.returncode
|
|
method = subprocess.run([tool("java"), "-cp", os.pathsep.join([str(classes), str(sample), cp]),
|
|
"ai.openidea.junit.Runner", "sample.SampleTest#parameterized"], capture_output=True)
|
|
assert method.stdout.decode().count("testStarted") == 2, method.stdout
|
|
print("ok")
|
|
sys.exit(0)
|
|
with zipfile.ZipFile(root / "openidea-junit-runner.jar", "w") as jar:
|
|
for path in sorted(classes.rglob("*.class")):
|
|
entry = zipfile.ZipInfo(path.relative_to(classes).as_posix(), (2026, 1, 1, 0, 0, 0))
|
|
jar.writestr(entry, path.read_bytes(), compress_type=zipfile.ZIP_DEFLATED)
|