From 4c3548b8af46407611d436e6ccdabdfb18a91166 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Sat, 25 Jan 2025 08:32:22 -0800 Subject: [PATCH] SBT: refactor tests, move those for cli and sysops 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. --- build.sbt | 6 ++++-- .../src/test/scala/org/scalafmt/cli/CliOptionsJVMTest.scala | 0 .../src/test/scala/org/scalafmt/cli/CliOptionsTest.scala | 0 .../shared/src/test/scala/org/scalafmt/cli/CliTest.scala | 0 .../shared/src/test/scala/org/scalafmt/cli/FakeGitOps.scala | 0 .../src/test/scala/org/scalafmt/cli/FileTestOps.scala | 0 .../src/test/scala/org/scalafmt/sysops}/DeleteTree.scala | 4 ++-- .../src/test/scala/org/scalafmt/sysops/FileOpsTest.scala | 4 +--- .../src/test/scala/org/scalafmt/sysops/GitOpsTest.scala | 4 +--- 9 files changed, 8 insertions(+), 10 deletions(-) rename {scalafmt-tests => scalafmt-cli}/jvm/src/test/scala/org/scalafmt/cli/CliOptionsJVMTest.scala (100%) rename {scalafmt-tests => scalafmt-cli}/shared/src/test/scala/org/scalafmt/cli/CliOptionsTest.scala (100%) rename {scalafmt-tests => scalafmt-cli}/shared/src/test/scala/org/scalafmt/cli/CliTest.scala (100%) rename {scalafmt-tests => scalafmt-cli}/shared/src/test/scala/org/scalafmt/cli/FakeGitOps.scala (100%) rename {scalafmt-tests => scalafmt-cli}/shared/src/test/scala/org/scalafmt/cli/FileTestOps.scala (100%) rename {scalafmt-tests/shared/src/test/scala/org/scalafmt/util => scalafmt-sysops/shared/src/test/scala/org/scalafmt/sysops}/DeleteTree.scala (93%) rename {scalafmt-tests => scalafmt-sysops}/shared/src/test/scala/org/scalafmt/sysops/FileOpsTest.scala (95%) rename {scalafmt-tests => scalafmt-sysops}/shared/src/test/scala/org/scalafmt/sysops/GitOpsTest.scala (99%) diff --git a/build.sbt b/build.sbt index 098c968d06..e30cf56b27 100644 --- a/build.sbt +++ b/build.sbt @@ -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 } @@ -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) // don't build for NativePlatform @@ -113,6 +113,7 @@ lazy val sysops = crossProject(JVMPlatform, NativePlatform) case _ => Seq() } }, + sharedTestSettings, ) lazy val config = crossProject(JVMPlatform, NativePlatform) @@ -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", diff --git a/scalafmt-tests/jvm/src/test/scala/org/scalafmt/cli/CliOptionsJVMTest.scala b/scalafmt-cli/jvm/src/test/scala/org/scalafmt/cli/CliOptionsJVMTest.scala similarity index 100% rename from scalafmt-tests/jvm/src/test/scala/org/scalafmt/cli/CliOptionsJVMTest.scala rename to scalafmt-cli/jvm/src/test/scala/org/scalafmt/cli/CliOptionsJVMTest.scala diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/cli/CliOptionsTest.scala b/scalafmt-cli/shared/src/test/scala/org/scalafmt/cli/CliOptionsTest.scala similarity index 100% rename from scalafmt-tests/shared/src/test/scala/org/scalafmt/cli/CliOptionsTest.scala rename to scalafmt-cli/shared/src/test/scala/org/scalafmt/cli/CliOptionsTest.scala diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/cli/CliTest.scala b/scalafmt-cli/shared/src/test/scala/org/scalafmt/cli/CliTest.scala similarity index 100% rename from scalafmt-tests/shared/src/test/scala/org/scalafmt/cli/CliTest.scala rename to scalafmt-cli/shared/src/test/scala/org/scalafmt/cli/CliTest.scala diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/cli/FakeGitOps.scala b/scalafmt-cli/shared/src/test/scala/org/scalafmt/cli/FakeGitOps.scala similarity index 100% rename from scalafmt-tests/shared/src/test/scala/org/scalafmt/cli/FakeGitOps.scala rename to scalafmt-cli/shared/src/test/scala/org/scalafmt/cli/FakeGitOps.scala diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/cli/FileTestOps.scala b/scalafmt-cli/shared/src/test/scala/org/scalafmt/cli/FileTestOps.scala similarity index 100% rename from scalafmt-tests/shared/src/test/scala/org/scalafmt/cli/FileTestOps.scala rename to scalafmt-cli/shared/src/test/scala/org/scalafmt/cli/FileTestOps.scala diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/util/DeleteTree.scala b/scalafmt-sysops/shared/src/test/scala/org/scalafmt/sysops/DeleteTree.scala similarity index 93% rename from scalafmt-tests/shared/src/test/scala/org/scalafmt/util/DeleteTree.scala rename to scalafmt-sysops/shared/src/test/scala/org/scalafmt/sysops/DeleteTree.scala index 3ec783bff9..665a02d726 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/util/DeleteTree.scala +++ b/scalafmt-sysops/shared/src/test/scala/org/scalafmt/sysops/DeleteTree.scala @@ -1,4 +1,4 @@ -package org.scalafmt.util +package org.scalafmt.sysops import java.io.IOException import java.nio.file.FileVisitResult @@ -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) () } diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/sysops/FileOpsTest.scala b/scalafmt-sysops/shared/src/test/scala/org/scalafmt/sysops/FileOpsTest.scala similarity index 95% rename from scalafmt-tests/shared/src/test/scala/org/scalafmt/sysops/FileOpsTest.scala rename to scalafmt-sysops/shared/src/test/scala/org/scalafmt/sysops/FileOpsTest.scala index 08108c0a9d..da818dad27 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/sysops/FileOpsTest.scala +++ b/scalafmt-sysops/shared/src/test/scala/org/scalafmt/sysops/FileOpsTest.scala @@ -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 @@ -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") diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/sysops/GitOpsTest.scala b/scalafmt-sysops/shared/src/test/scala/org/scalafmt/sysops/GitOpsTest.scala similarity index 99% rename from scalafmt-tests/shared/src/test/scala/org/scalafmt/sysops/GitOpsTest.scala rename to scalafmt-sysops/shared/src/test/scala/org/scalafmt/sysops/GitOpsTest.scala index db04cc8278..0b92bba7c4 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/sysops/GitOpsTest.scala +++ b/scalafmt-sysops/shared/src/test/scala/org/scalafmt/sysops/GitOpsTest.scala @@ -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 @@ -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")