Skip to content

Commit 12a9f02

Browse files
Merge pull request quarkusio#48277 from holly-cummins/improve-vscode-detection
Use tenuous pattern to detect VS Code in cases where classpath check does not work
2 parents 35bf36d + ad59a7e commit 12a9f02

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractJvmQuarkusTestExtension.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,22 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
160160
.unwrap(SmallRyeConfig.class)
161161
.getConfigMapping(TestConfig.class);
162162
} catch (Exception | ServiceConfigurationError e) {
163-
boolean isEclipse = System.getProperty("sun.java.command") != null
164-
&& System.getProperty("sun.java.command").contains("JUnit5TestLoader");
163+
String javaCommand = System.getProperty("sun.java.command");
164+
boolean isEclipse = javaCommand != null
165+
&& javaCommand.contains("JUnit5TestLoader");
165166

166167
// VS Code has the exact same java command and runner as Eclipse, but needs its own message
167-
boolean isVSCode = isEclipse && System.getProperty("java.class.path").contains("vscode");
168+
boolean isVSCode = isEclipse && (System.getProperty("java.class.path").contains("vscode"));
169+
boolean isMaybeVSCode = isEclipse && (javaCommand.contains("testNames") && javaCommand.contains("testNameFile"));
168170

169171
if (isVSCode) {
170172
// Will need https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2257 and a reconsume by VSCode
171173
Log.error(
172174
"Could not read configuration while evaluating whether to run a test. This is a known issue when running tests in the VS Code IDE. To work around the problem, run individual test methods.");
175+
} else if (isMaybeVSCode) {
176+
// Will need https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2257 and a reconsume by VSCode
177+
Log.error(
178+
"Could not read configuration while evaluating whether to run a test. It looks like you're probably running tests with VS Code. This is a known issue when running tests in the VS Code IDE. To work around the problem, run individual test methods.");
173179
} else if (isEclipse) {
174180
// Tracked by https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2257; fixed in Eclipse 4.37
175181
Log.error(
@@ -185,7 +191,7 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
185191
Log.debug("Underlying exception: " + e);
186192
Log.debug("Thread Context Classloader: " + Thread.currentThread().getContextClassLoader());
187193
Log.debug("The class of the class we use for mapping is " + TestConfig.class.getClassLoader());
188-
String message = isVSCode
194+
String message = isVSCode || isMaybeVSCode
189195
? "Could not execute test class because it was loaded with the wrong classloader by the VS Code test runner. Try running test methods individually instead."
190196
: isEclipse
191197
? "Could not execute test class because it was loaded with the wrong classloader by the Eclipse test runner. Try running test methods individually, or edit the run configuration and add `-uniqueId [engine:junit-jupiter]/[class:"

0 commit comments

Comments
 (0)