Skip to content

Commit d84a543

Browse files
Arthurm1jdneo
authored andcommitted
feat - Add support for running tests (microsoft#144)
Co-authored-by: Arthur McGibbon <arthur.mcgibbon@h3im.com> Co-authored-by: Sheng Chen <sheche@microsoft.com>
1 parent 361c355 commit d84a543

34 files changed

Lines changed: 2674 additions & 109 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Following BSP requests are supported in the current implementation:
2222
- `buildTarget/cleanCache`
2323
- `buildTarget/javacOptions`
2424
- `buildTarget/scalacOptions`
25+
- `buildTarget/test`
2526
- `workspace/buildTargets`
2627
- `workspace/reload`
2728

plugin/src/main/java/com/microsoft/java/bs/gradle/plugin/SourceSetsModelBuilder.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ public Object buildAll(String modelName, Project rootProject) {
7676
gradleSourceSet.setCleanTaskName(cleanTaskName);
7777
Set<String> taskNames = new HashSet<>();
7878
gradleSourceSet.setTaskNames(taskNames);
79-
taskNames.add(classesTaskName);
80-
taskNames.add(cleanTaskName);
81-
taskNames.add(getFullTaskName(projectPath, sourceSet.getProcessResourcesTaskName()));
8279
String projectName = stripPathPrefix(gradleSourceSet.getProjectPath());
8380
if (projectName == null || projectName.length() == 0) {
8481
projectName = gradleSourceSet.getProjectName();

server/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
dependencies {
66
implementation project(':model')
7-
implementation 'org.gradle:gradle-tooling-api:8.7'
7+
implementation 'org.gradle:gradle-tooling-api:8.8'
88
implementation 'ch.epfl.scala:bsp4j:2.1.0-M4'
99
implementation 'org.apache.commons:commons-lang3:3.13.0'
1010

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
package ch.epfl.scala.bsp4j.extended;
5+
6+
import java.util.Objects;
7+
8+
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
9+
import org.eclipse.xtext.xbase.lib.Pure;
10+
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
11+
12+
import ch.epfl.scala.bsp4j.TestFinish;
13+
import ch.epfl.scala.bsp4j.TestStatus;
14+
15+
/**
16+
* Extended {@link TestFinish}, which contains the Suite, class, method.
17+
* {@link TestFinish} only contains file location which Gradle doesn't have.
18+
*/
19+
public class TestFinishEx extends TestFinish {
20+
21+
private TestName testName;
22+
23+
private String stackTrace;
24+
25+
/**
26+
* Create a new instance of {@link TestFinishEx}.
27+
*/
28+
public TestFinishEx(@NonNull String displayName, @NonNull TestStatus status,
29+
@NonNull TestName testName) {
30+
super(displayName, status);
31+
this.testName = testName;
32+
}
33+
34+
35+
public TestName getTestName() {
36+
return testName;
37+
}
38+
39+
public void setTestName(TestName testName) {
40+
this.testName = testName;
41+
}
42+
43+
public String getStackTrace() {
44+
return stackTrace;
45+
}
46+
47+
public void setStackTrace(String stackTrace) {
48+
this.stackTrace = stackTrace;
49+
}
50+
51+
@Override
52+
@Pure
53+
public String toString() {
54+
ToStringBuilder b = new ToStringBuilder(this);
55+
b.add(super.toString());
56+
b.add("testName", this.testName);
57+
b.add("stackTrace", this.stackTrace);
58+
return b.toString();
59+
}
60+
61+
@Override
62+
public int hashCode() {
63+
final int prime = 31;
64+
int result = super.hashCode();
65+
result = prime * result + Objects.hash(testName, stackTrace);
66+
return result;
67+
}
68+
69+
@Override
70+
public boolean equals(Object obj) {
71+
if (this == obj) {
72+
return true;
73+
}
74+
if (!super.equals(obj)) {
75+
return false;
76+
}
77+
if (getClass() != obj.getClass()) {
78+
return false;
79+
}
80+
TestFinishEx other = (TestFinishEx) obj;
81+
return Objects.equals(testName, other.testName)
82+
&& Objects.equals(stackTrace, other.stackTrace);
83+
}
84+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
package ch.epfl.scala.bsp4j.extended;
5+
6+
import java.util.Objects;
7+
8+
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
9+
import org.eclipse.xtext.xbase.lib.Pure;
10+
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
11+
12+
/**
13+
* BSP TestName, which contains the test name and the test hierarchy
14+
* e.g. method/class/suite
15+
*/
16+
public class TestName {
17+
18+
private String displayName;
19+
20+
private String suiteName;
21+
22+
private String className;
23+
24+
private String methodName;
25+
26+
private TestName parent;
27+
28+
/**
29+
* Create a new instance of {@link TestName}.
30+
*/
31+
public TestName(@NonNull String displayName, String suiteName,
32+
String className, String methodName) {
33+
this.displayName = displayName;
34+
this.suiteName = suiteName;
35+
this.className = className;
36+
this.methodName = methodName;
37+
}
38+
39+
public String getDisplayName() {
40+
return displayName;
41+
}
42+
43+
public void setDisplayName(String displayName) {
44+
this.displayName = displayName;
45+
}
46+
47+
public String getSuiteName() {
48+
return suiteName;
49+
}
50+
51+
public void setSuiteName(String suiteName) {
52+
this.suiteName = suiteName;
53+
}
54+
55+
public String getClassName() {
56+
return className;
57+
}
58+
59+
public void setClassName(String className) {
60+
this.className = className;
61+
}
62+
63+
public String getMethodName() {
64+
return methodName;
65+
}
66+
67+
public void setMethodName(String methodName) {
68+
this.methodName = methodName;
69+
}
70+
71+
public TestName getParent() {
72+
return parent;
73+
}
74+
75+
public void setParent(TestName parent) {
76+
this.parent = parent;
77+
}
78+
79+
@Override
80+
@Pure
81+
public String toString() {
82+
ToStringBuilder b = new ToStringBuilder(this);
83+
b.add("displayName", this.displayName);
84+
b.add("suiteName", this.suiteName);
85+
b.add("className", this.className);
86+
b.add("methodName", this.methodName);
87+
b.add("parent", this.parent);
88+
return b.toString();
89+
}
90+
91+
@Override
92+
public int hashCode() {
93+
final int prime = 31;
94+
int result = super.hashCode();
95+
result = prime * result + Objects.hash(displayName, suiteName, className, methodName, parent);
96+
return result;
97+
}
98+
99+
@Override
100+
public boolean equals(Object obj) {
101+
if (this == obj) {
102+
return true;
103+
}
104+
if (!super.equals(obj)) {
105+
return false;
106+
}
107+
if (getClass() != obj.getClass()) {
108+
return false;
109+
}
110+
TestName other = (TestName) obj;
111+
return Objects.equals(displayName, other.displayName)
112+
&& Objects.equals(suiteName, other.suiteName)
113+
&& Objects.equals(className, other.className)
114+
&& Objects.equals(methodName, other.methodName)
115+
&& Objects.equals(parent, other.parent);
116+
}
117+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
package ch.epfl.scala.bsp4j.extended;
5+
6+
import java.util.Objects;
7+
8+
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
9+
import org.eclipse.xtext.xbase.lib.Pure;
10+
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;
11+
12+
import ch.epfl.scala.bsp4j.TestStart;
13+
14+
/**
15+
* Extended {@link TestStart}, which contains the Suite, class, method.
16+
* {@link TestStart} only contains file location which Gradle doesn't have.
17+
*/
18+
public class TestStartEx extends TestStart {
19+
20+
private TestName testName;
21+
22+
/**
23+
* Create a new instance of {@link TestStartEx}.
24+
*/
25+
public TestStartEx(@NonNull String displayName, @NonNull TestName testName) {
26+
super(displayName);
27+
this.testName = testName;
28+
}
29+
30+
public TestName getTestName() {
31+
return testName;
32+
}
33+
34+
public void setTestName(TestName testName) {
35+
this.testName = testName;
36+
}
37+
38+
@Override
39+
@Pure
40+
public String toString() {
41+
ToStringBuilder b = new ToStringBuilder(this);
42+
b.add(super.toString());
43+
b.add("testName", this.testName);
44+
return b.toString();
45+
}
46+
47+
@Override
48+
public int hashCode() {
49+
final int prime = 31;
50+
int result = super.hashCode();
51+
result = prime * result + Objects.hashCode(testName);
52+
return result;
53+
}
54+
55+
@Override
56+
public boolean equals(Object obj) {
57+
if (this == obj) {
58+
return true;
59+
}
60+
if (!super.equals(obj)) {
61+
return false;
62+
}
63+
if (getClass() != obj.getClass()) {
64+
return false;
65+
}
66+
TestStartEx other = (TestStartEx) obj;
67+
return Objects.equals(testName, other.testName);
68+
}
69+
}

0 commit comments

Comments
 (0)