From bfc4133eccc20415c232ea9398e5e991970e640a Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Wed, 21 Aug 2024 13:32:29 +0200 Subject: [PATCH] NIT Move the BSP-related `JMH` tests to the `JmhTests` suite --- .../cli/integration/BspTestDefinitions.scala | 48 ------------------- .../scala/cli/integration/JmhTests.scala | 25 +++++++++- 2 files changed, 23 insertions(+), 50 deletions(-) diff --git a/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala index 15e4f4e836..593cbb237b 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala @@ -263,54 +263,6 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg } } - for { - useDirective <- Seq(None, Some("//> using jmh")) - directiveString = useDirective.getOrElse("") - jmhOptions = if (useDirective.isEmpty) Seq("--jmh") else Nil - testMessage = useDirective match { - case None => jmhOptions.mkString(" ") - case Some(directive) => directive - } - } - test(s"simple jmh ($testMessage)") { - val inputs = TestInputs( - os.rel / "benchmark.scala" -> - s"""$directiveString - |package bench - | - |import java.util.concurrent.TimeUnit - |import org.openjdk.jmh.annotations._ - | - |@BenchmarkMode(Array(Mode.AverageTime)) - |@OutputTimeUnit(TimeUnit.NANOSECONDS) - |@Warmup(iterations = 1, time = 100, timeUnit = TimeUnit.MILLISECONDS) - |@Measurement(iterations = 10, time = 100, timeUnit = TimeUnit.MILLISECONDS) - |@Fork(0) - |class Benchmarks { - | - | @Benchmark - | def foo(): Unit = { - | (1L to 10000000L).sum - | } - | - |} - |""".stripMargin - ) - - withBsp(inputs, Seq(".", "--power") ++ jmhOptions) { (_, _, remoteServer) => - async { - val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala) - val targets = buildTargetsResp.getTargets.asScala.map(_.getId).toSeq - expect(targets.length == 2) - - val compileResult = - await(remoteServer.buildTargetCompile(new b.CompileParams(targets.asJava)).asScala) - expect(compileResult.getStatusCode == b.StatusCode.OK) - - } - } - } - test("diagnostics") { val inputs = TestInputs( os.rel / "Test.scala" -> diff --git a/modules/integration/src/test/scala/scala/cli/integration/JmhTests.scala b/modules/integration/src/test/scala/scala/cli/integration/JmhTests.scala index bc7106d3ce..740d3c3620 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/JmhTests.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/JmhTests.scala @@ -1,13 +1,18 @@ package scala.cli.integration +import ch.epfl.scala.bsp4j as b import com.eed3si9n.expecty.Expecty.expect import java.nio.file.Files +import scala.async.Async.{async, await} +import scala.concurrent.ExecutionContext.Implicits.global +import scala.jdk.CollectionConverters.* import scala.util.Properties -class JmhTests extends ScalaCliSuite with JmhSuite { - override def group: ScalaCliSuite.TestGroup = ScalaCliSuite.TestGroup.First +class JmhTests extends ScalaCliSuite with JmhSuite with BspSuite { + override def group: ScalaCliSuite.TestGroup = ScalaCliSuite.TestGroup.First + override protected val extraOptions: Seq[String] = TestUtil.extraOptions for { useDirective <- Seq(None, Some("//> using jmh")) @@ -52,6 +57,22 @@ class JmhTests extends ScalaCliSuite with JmhSuite { } } + test(s"bsp ($testMessage)") { + withBsp(simpleBenchmarkingInputs(directiveString), Seq(".", "--power") ++ jmhOptions) { + (_, _, remoteServer) => + async { + val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala) + val targets = buildTargetsResp.getTargets.asScala.map(_.getId).toSeq + expect(targets.length == 2) + + val compileResult = + await(remoteServer.buildTargetCompile(new b.CompileParams(targets.asJava)).asScala) + expect(compileResult.getStatusCode == b.StatusCode.OK) + + } + } + } + test(s"package ($testMessage)") { // TODO make package with --jmh build an artifact that actually runs benchmarks val expectedMessage = "Placeholder main method"