Skip to content

Commit

Permalink
refactor: ensure we're testing the connection with Mill
Browse files Browse the repository at this point in the history
When I opened com-lihaoyi/mill#2123 it made me
wonder why we didn't hit on this in our tests, but then I realized we
were actually never testing the initialization with Mill server. This
adds some more tests to ensure we're not only testing the generation of
the BSP config file, but also connection to the build server.
  • Loading branch information
ckipp01 committed Nov 14, 2022
1 parent 520b6d8 commit babae55
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions tests/slow/src/test/scala/tests/mill/MillServerSuite.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tests.mill

import java.util.concurrent.TimeUnit

import scala.meta.internal.builds.MillBuildTool
import scala.meta.internal.builds.MillDigest
import scala.meta.internal.metals.Messages
Expand All @@ -13,7 +15,7 @@ import tests.MillBuildLayout
import tests.MillServerInitializer

/**
* Basic suite to ensure that a connection to sbt server can be made.
* Basic suite to ensure that a connection to a Mill server can be made.
*/
class MillServerSuite
extends BaseImportSuite("mill-server", MillServerInitializer) {
Expand Down Expand Up @@ -49,25 +51,36 @@ class MillServerSuite
}
}

test("generate") {
def millBspConfig = workspace.resolve(".bsp/mill-bsp.json")
cleanWorkspace()
writeLayout(MillBuildLayout("", V.scala213, supportedBspVersion))
for {
_ <- server.initialize()
_ <- server.initialized()
_ = assertNoDiff(
client.workspaceMessageRequests,
// Project has no .bloop directory so user is asked to "import via bloop"
// since bloop is still the default
importBuildMessage,
)
_ = client.messageRequests.clear() // restart
_ = assert(!millBspConfig.exists)
// At this point, we want to use mill-bsp server, so create the mill-bsp.json file.
_ <- server.executeCommand(ServerCommands.GenerateBspConfig)
} yield {
assert(millBspConfig.exists)
val versionsToTest: List[String] =
List("0.10.0", "0.10.8", supportedBspVersion)

versionsToTest.foreach(testGenerationAndConnection)

private def testGenerationAndConnection(version: String) = {
test(s"generate-and-connect-$version") {
def millBspConfig = workspace.resolve(".bsp/mill-bsp.json")
cleanWorkspace()
writeLayout(MillBuildLayout("", V.scala213, version))
for {
_ <- server.initialize()
_ <- server.initialized()
_ = assertNoDiff(
client.workspaceMessageRequests,
// Project has no .bloop directory so user is asked to "import via bloop"
// since bloop is still the default
importBuildMessage,
)
_ = client.messageRequests.clear() // restart
_ = assert(!millBspConfig.exists)
// At this point, we want to use mill-bsp server, so create the mill-bsp.json file.
_ <- server.executeCommand(ServerCommands.GenerateBspConfig)
// We need to wait a bit just to ensure the connection is made
_ <- server.waitFor(TimeUnit.SECONDS.toMillis(1))
} yield {
assert(millBspConfig.exists)
server.assertBuildServerConnection()
}
}

}
}

0 comments on commit babae55

Please sign in to comment.