Skip to content

Commit

Permalink
SBT: refactor tests, move those for cli and sysops
Browse files Browse the repository at this point in the history
As a result, `tests` contains only `core` tests; the reason for it to
remain separate is due to special BuildInfo handling, to capture the
resource directories holding `.stat` files to test with.
  • Loading branch information
kitbellew committed Jan 25, 2025
1 parent 5ef0557 commit f3871d3
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 12 deletions.
9 changes: 5 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ commands += Command.command("ci-test-jvm") { s =>
case _ => scala213
}
val docsTest = if (scalaVersion == scala212) "docs/run" else "version"
s"++$scalaVersion" :: "tests/test" :: "dynamic/test" :: "publishLocal" ::
s"++$scalaVersion" :: "tests/test" :: "cli/test" :: "publishLocal" ::
docsTest :: s
}

Expand All @@ -62,7 +62,7 @@ commands += Command.command("ci-test-native") { s =>
case Some("2.12") => scala212
case _ => scala213
}
s"++$scalaVersion" :: "testsNative/test" :: s
s"++$scalaVersion" :: "testsNative/test" :: "cliNative/test" :: s
}

lazy val dynamic = crossProject(JVMPlatform, NativePlatform)
Expand Down Expand Up @@ -113,6 +113,7 @@ lazy val sysops = crossProject(JVMPlatform, NativePlatform)
case _ => Seq()
}
},
sharedTestSettings,
)

lazy val config = crossProject(JVMPlatform, NativePlatform)
Expand Down Expand Up @@ -200,6 +201,7 @@ lazy val cli = crossProject(JVMPlatform, NativePlatform)
),
scalacOptions ++= scalacJvmOptions.value,
Compile / mainClass := Some("org.scalafmt.cli.Cli"),
sharedTestSettings,
).jvmSettings(
nativeImageInstalled := isCI,
nativeImageOptions += "-march=compatibility",
Expand Down Expand Up @@ -233,8 +235,7 @@ lazy val tests = crossProject(JVMPlatform, NativePlatform)
.get
}),
).enablePlugins(BuildInfoPlugin)
.jvmSettings(javaOptions += "-Dfile.encoding=UTF8")
.dependsOn(core, dynamic, cli)
.jvmSettings(javaOptions += "-Dfile.encoding=UTF8").dependsOn(core)

lazy val sharedTestSettings = Seq(libraryDependencies += munit.value % Test)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scalafmt.util
package org.scalafmt.sysops

import java.io.IOException
import java.nio.file.FileVisitResult
Expand All @@ -8,7 +8,7 @@ import java.nio.file.Path
import java.nio.file.attribute.BasicFileAttributes

object DeleteTree {
def deleteTree(path: Path): Unit = {
def apply(path: Path): Unit = {
Files.walkFileTree(path, new DeleteTree)
()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.scalafmt.sysops

import org.scalafmt.util.DeleteTree.deleteTree

import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Path
Expand All @@ -18,7 +16,7 @@ class FileOpsTest extends munit.FunSuite {
path = Files.createTempDirectory("FileOpsTestDir")

override def afterEach(context: AfterEach): Unit =
try deleteTree(path)
try DeleteTree(path)
catch {
case e: Throwable =>
println("Unable to delete test files")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.scalafmt.sysops

import org.scalafmt.util.DeleteTree.deleteTree

import java.io.File
import java.nio.charset.StandardCharsets
import java.nio.file.Files
Expand Down Expand Up @@ -36,7 +34,7 @@ class GitOpsTest extends FunSuite {
}

override def afterEach(context: AfterEach): Unit =
try deleteTree(path.path)
try DeleteTree(path.path)
catch {
case e: Throwable =>
println("Unable to delete test files")
Expand Down

0 comments on commit f3871d3

Please sign in to comment.