1
1
package scala .cli .integration
2
2
3
+ import ch .epfl .scala .bsp4j as b
3
4
import com .eed3si9n .expecty .Expecty .expect
4
5
5
6
import java .nio .file .Files
6
7
8
+ import scala .async .Async .{async , await }
9
+ import scala .concurrent .ExecutionContext .Implicits .global
10
+ import scala .jdk .CollectionConverters .*
7
11
import scala .util .Properties
8
12
9
- class JmhTests extends ScalaCliSuite with JmhSuite {
10
- override def group : ScalaCliSuite .TestGroup = ScalaCliSuite .TestGroup .First
13
+ class JmhTests extends ScalaCliSuite with JmhSuite with BspSuite {
14
+ override def group : ScalaCliSuite .TestGroup = ScalaCliSuite .TestGroup .First
15
+ override protected val extraOptions : Seq [String ] = TestUtil .extraOptions
11
16
12
17
for {
13
18
useDirective <- Seq (None , Some (" //> using jmh" ))
@@ -22,7 +27,7 @@ class JmhTests extends ScalaCliSuite with JmhSuite {
22
27
// TODO extract running benchmarks to a separate scope, or a separate sub-command
23
28
simpleBenchmarkingInputs(directiveString).fromRoot { root =>
24
29
val res =
25
- os.proc(TestUtil .cli, " --power" , TestUtil . extraOptions, " ." , jmhOptions).call(cwd = root)
30
+ os.proc(TestUtil .cli, " --power" , extraOptions, " ." , jmhOptions).call(cwd = root)
26
31
val output = res.out.trim()
27
32
expect(output.contains(expectedInBenchmarkingOutput))
28
33
expect(output.contains(s " JMH version: ${Constants .jmhVersion}" ))
@@ -31,14 +36,14 @@ class JmhTests extends ScalaCliSuite with JmhSuite {
31
36
32
37
test(s " compile ( $testMessage) " ) {
33
38
simpleBenchmarkingInputs(directiveString).fromRoot { root =>
34
- os.proc(TestUtil .cli, " compile" , " --power" , TestUtil . extraOptions, " ." , jmhOptions)
39
+ os.proc(TestUtil .cli, " compile" , " --power" , extraOptions, " ." , jmhOptions)
35
40
.call(cwd = root)
36
41
}
37
42
}
38
43
39
44
test(s " doc ( $testMessage) " ) {
40
45
simpleBenchmarkingInputs(directiveString).fromRoot { root =>
41
- val res = os.proc(TestUtil .cli, " doc" , " --power" , TestUtil . extraOptions, " ." , jmhOptions)
46
+ val res = os.proc(TestUtil .cli, " doc" , " --power" , extraOptions, " ." , jmhOptions)
42
47
.call(cwd = root, stderr = os.Pipe )
43
48
expect(! res.err.trim().contains(" Error" ))
44
49
}
@@ -47,11 +52,27 @@ class JmhTests extends ScalaCliSuite with JmhSuite {
47
52
test(s " setup-ide ( $testMessage) " ) {
48
53
// TODO fix setting jmh via a reload & add tests for it
49
54
simpleBenchmarkingInputs(directiveString).fromRoot { root =>
50
- os.proc(TestUtil .cli, " setup-ide" , " --power" , TestUtil . extraOptions, " ." , jmhOptions)
55
+ os.proc(TestUtil .cli, " setup-ide" , " --power" , extraOptions, " ." , jmhOptions)
51
56
.call(cwd = root)
52
57
}
53
58
}
54
59
60
+ test(s " bsp ( $testMessage) " ) {
61
+ withBsp(simpleBenchmarkingInputs(directiveString), Seq (" ." , " --power" ) ++ jmhOptions) {
62
+ (_, _, remoteServer) =>
63
+ async {
64
+ val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
65
+ val targets = buildTargetsResp.getTargets.asScala.map(_.getId).toSeq
66
+ expect(targets.length == 2 )
67
+
68
+ val compileResult =
69
+ await(remoteServer.buildTargetCompile(new b.CompileParams (targets.asJava)).asScala)
70
+ expect(compileResult.getStatusCode == b.StatusCode .OK )
71
+
72
+ }
73
+ }
74
+ }
75
+
55
76
test(s " package ( $testMessage) " ) {
56
77
// TODO make package with --jmh build an artifact that actually runs benchmarks
57
78
val expectedMessage = " Placeholder main method"
@@ -84,7 +105,7 @@ class JmhTests extends ScalaCliSuite with JmhSuite {
84
105
test(s " export ( $testMessage) " ) {
85
106
simpleBenchmarkingInputs(directiveString).fromRoot { root =>
86
107
// TODO add proper support for JMH export, we're checking if it doesn't fail the command for now
87
- os.proc(TestUtil .cli, " export" , " --power" , TestUtil . extraOptions, " ." , jmhOptions)
108
+ os.proc(TestUtil .cli, " export" , " --power" , extraOptions, " ." , jmhOptions)
88
109
.call(cwd = root)
89
110
}
90
111
}
@@ -102,7 +123,7 @@ class JmhTests extends ScalaCliSuite with JmhSuite {
102
123
} test(s " should not compile when jmh is explicitly disabled ( $testMessage) " ) {
103
124
simpleBenchmarkingInputs(directiveString).fromRoot { root =>
104
125
val res =
105
- os.proc(TestUtil .cli, " compile" , " --power" , TestUtil . extraOptions, " ." , jmhOptions)
126
+ os.proc(TestUtil .cli, " compile" , " --power" , extraOptions, " ." , jmhOptions)
106
127
.call(cwd = root, check = false )
107
128
expect(res.exitCode == 1 )
108
129
}
@@ -128,7 +149,7 @@ class JmhTests extends ScalaCliSuite with JmhSuite {
128
149
} test(s " should use the passed jmh version ( $testMessage) " ) {
129
150
simpleBenchmarkingInputs(directiveString).fromRoot { root =>
130
151
val res =
131
- os.proc(TestUtil .cli, " run" , " --power" , TestUtil . extraOptions, " ." , jmhOptions)
152
+ os.proc(TestUtil .cli, " run" , " --power" , extraOptions, " ." , jmhOptions)
132
153
.call(cwd = root)
133
154
val output = res.out.trim()
134
155
expect(output.contains(expectedInBenchmarkingOutput))
0 commit comments