Skip to content

Commit f44e79d

Browse files
committed
Ensure MockRoot test folder is always cleared before tests run
Several of Scala Steward's tests (eg `PullRequestRepositoryTest`) write files to the filesystem, using `MockConfig.mockRoot` as the base folder. Previously, the folder was erased by using sbt configuration: `Tests.Cleanup` in the `testOptions` setting (see https://www.scala-sbt.org/1.x/docs/Testing.html#Setup+and+Cleanup ), but as documented in https://youtrack.jetbrains.com/issue/SCL-21353 this doesn't work well with IntelliJ's quickly-run-individual-test feature. This change ensures that running the tests with IntelliJ, or with sbt, both work: we now delete the `mockRoot` folder in Scala, rather than sbt configuration. We also do it _before_ tests run, rather than after, which I think is better - sometimes you want to examine the files after tests have failed, and it's only when you're about to run the tests that you want the previous files deleted. See also: #3101 (comment)
1 parent 5a5bbec commit f44e79d

File tree

2 files changed

+1
-2
lines changed

2 files changed

+1
-2
lines changed

build.sbt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ lazy val core = myCrossProject("core")
212212
// Uncomment for remote debugging:
213213
// run / javaOptions += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005",
214214
Test / fork := true,
215-
Test / testOptions +=
216-
Tests.Cleanup(() => Path(file(Properties.tmpDir) / "scala-steward").deleteRecursively()),
217215
Compile / resourceGenerators += Def.task {
218216
val outDir = (Compile / resourceManaged).value
219217
def downloadPlugin(v: String): File = {

modules/core/src/test/scala/org/scalasteward/core/mock/MockConfig.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.scalasteward.core.application.{Cli, Config}
66

77
object MockConfig {
88
val mockRoot: File = File.temp / "scala-steward"
9+
mockRoot.delete(true) // Ensure folder is cleared of previous test files
910
private val args: List[String] = List(
1011
s"--workspace=$mockRoot/workspace",
1112
s"--repos-file=$mockRoot/repos.md",

0 commit comments

Comments
 (0)