Skip to content

Commit

Permalink
Merge pull request #116 from alexarchambault/merge-upstream
Browse files Browse the repository at this point in the history
Merge upstream changes
  • Loading branch information
alexarchambault authored Aug 16, 2022
2 parents a8b6296 + 244ec0c commit da5813d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions frontend/src/test/scala/bloop/bsp/BspBaseSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ abstract class BspBaseSuite extends BaseSuite with BspClientTest {
def findBuildTarget(project: TestProject): bsp.BuildTarget = {
val workspaceTargetTask = {
Workspace.buildTargets.request(bsp.WorkspaceBuildTargetsRequest()).map {
case Left(_) => fail("The request for build targets in ${state.build.origin} failed!")
case Left(_) => fail(s"The request for build targets in ${state.build.origin} failed!")
case Right(ts) =>
ts.targets.map(t => t.id -> t).find(_._1 == project.bspId) match {
case Some((_, target)) => target
Expand Down Expand Up @@ -128,7 +128,7 @@ abstract class BspBaseSuite extends BaseSuite with BspClientTest {
project: TestProject
)(f: bsp.BuildTargetIdentifier => Task[T]): Task[T] = {
Workspace.buildTargets.request(bsp.WorkspaceBuildTargetsRequest()).flatMap {
case Left(_) => fail("The request for build targets in ${state.build.origin} failed!")
case Left(_) => fail(s"The request for build targets in ${state.build.origin} failed!")
case Right(ts) =>
ts.targets.map(_.id).find(_ == project.bspId) match {
case Some(target) => f(target)
Expand Down
32 changes: 17 additions & 15 deletions frontend/src/test/scala/bloop/testing/BloopHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ trait BloopHelpers {
val all = files.map { f =>
Task {
val configFile = f.path.underlying
val oldWorkspace = AbsolutePath(baseDir)
loadTestProjectFromDisk(configFile, oldWorkspace.syntax, workspace.syntax)
loadTestProjectFromDisk(configFile, workspace.syntax)
}
}

Expand All @@ -117,25 +116,28 @@ trait BloopHelpers {

private def loadTestProjectFromDisk(
configFile: Path,
previousBaseDir: String,
newBaseDir: String
): TestProject = {
val bytes = Files.readAllBytes(configFile)
val contents = new String(bytes, StandardCharsets.UTF_8)
val newContents = contents.replace(previousBaseDir, newBaseDir)
import java.nio.file.StandardOpenOption
Files.write(
configFile,
newContents.getBytes(StandardCharsets.UTF_8),
StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.SYNC,
StandardOpenOption.WRITE
)

bloop.config.read(newContents.getBytes(StandardCharsets.UTF_8)) match {
val contents = new String(bytes)

bloop.config.read(contents.getBytes()).flatMap { cfg =>
import java.nio.file.StandardOpenOption
val previousBaseDir = cfg.project.workspaceDir.get.toString()
val newContents = contents.replace("\"" + previousBaseDir, "\"" + newBaseDir)
Files.write(
configFile,
newContents.getBytes,
StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.SYNC,
StandardOpenOption.WRITE
)
bloop.config.read(newContents.getBytes())
} match {
case Left(error) => throw error
case Right(file) => TestProject(file.project, None)
}

}

final class TestState(val state: State) {
Expand Down

0 comments on commit da5813d

Please sign in to comment.