Skip to content

Commit c47dcb0

Browse files
authored
Merge pull request scalacenter#1773 from dos65/fix_test_porject_rewrites_in-test
fix: avoid resource file updates in test
2 parents 13310fd + 71c54be commit c47dcb0

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

frontend/src/test/scala/bloop/testing/BloopHelpers.scala

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ trait BloopHelpers {
9898
val all = files.map { f =>
9999
Task {
100100
val configFile = f.path.underlying
101-
val oldWorkspace = AbsolutePath(baseDir)
102-
loadTestProjectFromDisk(configFile, oldWorkspace.syntax, workspace.syntax)
101+
loadTestProjectFromDisk(configFile, workspace.syntax)
103102
}
104103
}
105104

@@ -117,25 +116,28 @@ trait BloopHelpers {
117116

118117
private def loadTestProjectFromDisk(
119118
configFile: Path,
120-
previousBaseDir: String,
121119
newBaseDir: String
122120
): TestProject = {
123121
val bytes = Files.readAllBytes(configFile)
124-
val contents = new String(bytes, StandardCharsets.UTF_8)
125-
val newContents = contents.replace(previousBaseDir, newBaseDir)
126-
import java.nio.file.StandardOpenOption
127-
Files.write(
128-
configFile,
129-
newContents.getBytes(StandardCharsets.UTF_8),
130-
StandardOpenOption.TRUNCATE_EXISTING,
131-
StandardOpenOption.SYNC,
132-
StandardOpenOption.WRITE
133-
)
134-
135-
bloop.config.read(newContents.getBytes(StandardCharsets.UTF_8)) match {
122+
val contents = new String(bytes)
123+
124+
bloop.config.read(contents.getBytes()).flatMap { cfg =>
125+
import java.nio.file.StandardOpenOption
126+
val previousBaseDir = cfg.project.workspaceDir.get.toString()
127+
val newContents = contents.replace(previousBaseDir, newBaseDir)
128+
Files.write(
129+
configFile,
130+
newContents.getBytes,
131+
StandardOpenOption.TRUNCATE_EXISTING,
132+
StandardOpenOption.SYNC,
133+
StandardOpenOption.WRITE
134+
)
135+
bloop.config.read(newContents.getBytes())
136+
} match {
136137
case Left(error) => throw error
137138
case Right(file) => TestProject(file.project, None)
138139
}
140+
139141
}
140142

141143
final class TestState(val state: State) {

0 commit comments

Comments
 (0)