fix - Method parsing error (#1722)
This commit is contained in:
Родитель
eac027fcbb
Коммит
e42565b0fe
|
@ -21,10 +21,10 @@ jobs:
|
|||
sudo /usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
|
||||
sleep 3
|
||||
|
||||
- name: Set up JDK 17
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: '17'
|
||||
java-version: '21'
|
||||
|
||||
- name: Setup Node.js environment
|
||||
uses: actions/setup-node@v2
|
||||
|
@ -57,10 +57,10 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up JDK 17
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: '17'
|
||||
java-version: '21'
|
||||
|
||||
- name: Setup Node.js environment
|
||||
uses: actions/setup-node@v2
|
||||
|
@ -93,10 +93,10 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up JDK 17
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: '17'
|
||||
java-version: '21'
|
||||
|
||||
- name: Setup Node.js environment
|
||||
uses: actions/setup-node@v2
|
||||
|
|
|
@ -16,15 +16,11 @@ import com.microsoft.java.test.plugin.coverage.model.LineCoverage;
|
|||
import com.microsoft.java.test.plugin.coverage.model.MethodCoverage;
|
||||
import com.microsoft.java.test.plugin.coverage.model.SourceFileCoverage;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.jdt.core.IJavaProject;
|
||||
import org.eclipse.jdt.core.JavaCore;
|
||||
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
|
||||
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -36,7 +32,7 @@ public class CoverageHandlerTest extends AbstractProjectsManagerBasedTest {
|
|||
public void testGetCoverageDetail() throws Exception {
|
||||
importProjects(Collections.singleton("coverage-test"));
|
||||
final IJavaProject javaProject = ProjectUtils.getJavaProject("coverage-test");
|
||||
final String basePath = new File("projects/coverage-test").getAbsolutePath();
|
||||
final String basePath = javaProject.getProject().getLocation().toFile().getAbsolutePath();
|
||||
final CoverageHandler coverageHandler = new CoverageHandler(javaProject, basePath);
|
||||
final List<SourceFileCoverage> coverageDetail = coverageHandler.getCoverageDetail(new NullProgressMonitor());
|
||||
for (final SourceFileCoverage fileCoverage : coverageDetail) {
|
||||
|
|
|
@ -31,12 +31,11 @@ import org.eclipse.jdt.core.ICompilationUnit;
|
|||
import org.eclipse.jdt.core.IJavaProject;
|
||||
import org.eclipse.jdt.core.IMethod;
|
||||
import org.eclipse.jdt.core.JavaCore;
|
||||
import org.eclipse.jdt.core.dom.ASTNode;
|
||||
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||
import org.eclipse.jdt.core.dom.ITypeBinding;
|
||||
import org.eclipse.jdt.core.dom.MethodDeclaration;
|
||||
import org.eclipse.jdt.core.dom.NodeFinder;
|
||||
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
|
||||
import org.eclipse.jdt.internal.corext.refactoring.structure.ASTNodeSearchUtil;
|
||||
import org.eclipse.jdt.launching.VMRunnerConfiguration;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
|
@ -156,20 +155,14 @@ public class JUnitLaunchConfigurationDelegate extends org.eclipse.jdt.junit.laun
|
|||
}
|
||||
final CompilationUnit root = (CompilationUnit) TestSearchUtils.parseToAst(unit,
|
||||
false /*fromCache*/, new NullProgressMonitor());
|
||||
final String key = method.getKey();
|
||||
ASTNode methodDeclaration = root.findDeclaringNode(key);
|
||||
final MethodDeclaration methodDeclaration = ASTNodeSearchUtil.getMethodDeclarationNode(method, root);
|
||||
if (methodDeclaration == null) {
|
||||
// fallback to find it according to source range
|
||||
methodDeclaration = NodeFinder.perform(root, method.getSourceRange().getOffset(),
|
||||
method.getSourceRange().getLength(), unit);
|
||||
}
|
||||
if (!(methodDeclaration instanceof MethodDeclaration)) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, JUnitPlugin.PLUGIN_ID, IStatus.ERROR,
|
||||
"Cannot get method declaration of method" + method.getElementName(), null)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
final List<String> parameters = new LinkedList<>();
|
||||
for (final Object obj : ((MethodDeclaration) methodDeclaration).parameters()) {
|
||||
for (final Object obj : methodDeclaration.parameters()) {
|
||||
if (obj instanceof SingleVariableDeclaration) {
|
||||
final ITypeBinding paramTypeBinding = ((SingleVariableDeclaration) obj)
|
||||
.getType().resolveBinding();
|
||||
|
|
|
@ -23,25 +23,19 @@
|
|||
<unit id="org.eclipse.sdk.feature.group" version="0.0.0"/>
|
||||
<unit id="org.mockito.mockito-core" version="0.0.0"/>
|
||||
<unit id="org.apache.commons.commons-io" version="0.0.0"/>
|
||||
<repository location="https://download.eclipse.org/eclipse/updates/4.28/R-4.28-202306050440/"/>
|
||||
<repository location="https://download.eclipse.org/eclipse/updates/4.33-I-builds/I20240728-1800/"/>
|
||||
</location>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<unit id="org.eclipse.xtext.xbase.lib" version="0.0.0"/>
|
||||
<repository location="https://download.eclipse.org/releases/2023-03/"/>
|
||||
<repository location="https://download.eclipse.org/releases/2024-03/"/>
|
||||
</location>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<repository location="https://download.eclipse.org/lsp4j/updates/releases/0.21.1/"/>
|
||||
<repository location="https://download.eclipse.org/lsp4j/updates/releases/0.23.1/"/>
|
||||
<unit id="org.eclipse.lsp4j.sdk.feature.group" version="0.0.0"/>
|
||||
</location>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<unit id="org.eclipse.jdt.ls.core" version="0.0.0"/>
|
||||
<!-- Latest JDT.LS requires JUnit 5.10+, which will break test execution <= 5.9.3
|
||||
See: https://github.com/microsoft/vscode-java-test/pull/1608#issue-1904190398 -->
|
||||
<repository location="https://download.eclipse.org/jdtls/snapshots/repository/1.30.0.202310302327/"/>
|
||||
</location>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<unit id="org.apache.commons.lang3" version="3.1.0.v201403281430"/>
|
||||
<repository location="https://download.eclipse.org/tools/orbit/R-builds/R20200529191137/repository/"/>
|
||||
<repository location="https://download.eclipse.org/jdtls/snapshots/repository/latest/"/>
|
||||
</location>
|
||||
<location includeDependencyDepth="infinite" includeDependencyScopes="compile" includeSource="true" missingManifest="generate" type="Maven">
|
||||
<dependencies>
|
||||
|
@ -50,6 +44,12 @@
|
|||
<artifactId>org.jacoco.core</artifactId>
|
||||
<version>0.8.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.14.0</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</location>
|
||||
</locations>
|
||||
|
|
30
package.json
30
package.json
|
@ -55,22 +55,22 @@
|
|||
"main": "./main.js",
|
||||
"contributes": {
|
||||
"javaExtensions": [
|
||||
"./server/junit-jupiter-api_5.9.3.jar",
|
||||
"./server/junit-jupiter-engine_5.9.3.jar",
|
||||
"./server/junit-jupiter-migrationsupport_5.9.3.jar",
|
||||
"./server/junit-jupiter-params_5.9.3.jar",
|
||||
"./server/junit-platform-commons_1.9.3.jar",
|
||||
"./server/junit-platform-engine_1.9.3.jar",
|
||||
"./server/junit-platform-launcher_1.9.3.jar",
|
||||
"./server/junit-platform-runner_1.9.3.jar",
|
||||
"./server/junit-platform-suite-api_1.9.3.jar",
|
||||
"./server/junit-platform-suite-commons_1.9.3.jar",
|
||||
"./server/junit-platform-suite-engine_1.9.3.jar",
|
||||
"./server/junit-vintage-engine_5.9.3.jar",
|
||||
"./server/junit-jupiter-api_5.10.3.jar",
|
||||
"./server/junit-jupiter-engine_5.10.3.jar",
|
||||
"./server/junit-jupiter-migrationsupport_5.10.3.jar",
|
||||
"./server/junit-jupiter-params_5.10.3.jar",
|
||||
"./server/junit-platform-commons_1.10.3.jar",
|
||||
"./server/junit-platform-engine_1.10.3.jar",
|
||||
"./server/junit-platform-launcher_1.10.3.jar",
|
||||
"./server/junit-platform-runner_1.10.3.jar",
|
||||
"./server/junit-platform-suite-api_1.10.3.jar",
|
||||
"./server/junit-platform-suite-commons_1.10.3.jar",
|
||||
"./server/junit-platform-suite-engine_1.10.3.jar",
|
||||
"./server/junit-vintage-engine_5.10.3.jar",
|
||||
"./server/org.apiguardian.api_1.1.2.jar",
|
||||
"./server/org.eclipse.jdt.junit4.runtime_1.3.0.v20220609-1843.jar",
|
||||
"./server/org.eclipse.jdt.junit5.runtime_1.1.100.v20220907-0450.jar",
|
||||
"./server/org.opentest4j_1.2.0.jar",
|
||||
"./server/org.eclipse.jdt.junit4.runtime_1.3.100.v20231214-1952.jar",
|
||||
"./server/org.eclipse.jdt.junit5.runtime_1.1.300.v20231214-1952.jar",
|
||||
"./server/org.opentest4j_1.3.0.jar",
|
||||
"./server/org.jacoco.core_0.8.12.202403310830.jar",
|
||||
"./server/com.microsoft.java.test.plugin-0.42.0.jar"
|
||||
],
|
||||
|
|
|
@ -79,6 +79,21 @@ suite('LaunchUtils Tests', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('Resolve JUnit 5 parameterized test 5', async () => {
|
||||
const argument: Response<IJUnitLaunchArguments> | undefined = await executeJavaLanguageServerCommand<Response<IJUnitLaunchArguments>>(
|
||||
JavaTestRunnerDelegateCommands.RESOLVE_JUNIT_ARGUMENT, JSON.stringify({
|
||||
projectName: 'junit',
|
||||
testLevel: TestLevel.Method,
|
||||
testKind: TestKind.JUnit5,
|
||||
testNames: ['=junit/src\\/test\\/java=/optional=/true=/=/maven.pomderived=/true=/=/test=/true=/<junit5{TestParameterizedWithStrangeComments.java[TestParameterizedWithStrangeComments~whenInvalidReqCtxSessionId~QLong;~QString;']
|
||||
})
|
||||
);
|
||||
assert.strictEqual(
|
||||
0,
|
||||
argument?.status
|
||||
);
|
||||
});
|
||||
|
||||
test('test parseTags()', () => {
|
||||
const { parseTags } = exportedForTesting;
|
||||
const config = {
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package junit5;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
class TestParameterizedWithStrangeComments {
|
||||
//FORMER_TEST_PARAMS
|
||||
//@CsvSource(
|
||||
// {",must not be null",
|
||||
// "0L,size must be between 1 and 999999999"})
|
||||
//@ParameterizedTest
|
||||
|
||||
/**
|
||||
* [RequestContext.sessionId]
|
||||
* Tests all invalid scenarios for requestContext.logonId.
|
||||
*/
|
||||
@CsvSource(delimiter = '|', textBlock = """
|
||||
-1 | size must be between 1 and 999999999
|
||||
""")
|
||||
@ParameterizedTest
|
||||
void whenInvalidReqCtxSessionId(Long __INPUT, String __EXPECTED) throws Exception {
|
||||
assert(true);
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче