From 9c7bbad07938ba42c09224956d66f7433df04062 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Fri, 24 Nov 2023 10:53:37 +0100 Subject: [PATCH] Reworked test setup --- build.sc | 6 +- itest/src/01-simple-site/build.sc | 71 ++++++++++++++++--- .../tobiasroeser/mill/jbake/JBakeModule.scala | 7 +- 3 files changed, 69 insertions(+), 15 deletions(-) diff --git a/build.sc b/build.sc index b891f17..9c8afd3 100644 --- a/build.sc +++ b/build.sc @@ -54,7 +54,7 @@ object Setup { } } -val setups = Seq(Setup.R010, Setup.R09, Setup.R07, Setup.R06) +val setups = Seq(Setup.R011, Setup.R010, Setup.R09, Setup.R07, Setup.R06) object jbake extends Cross[JbakeCross](setups.map(_.millPlatform)) trait JbakeCross extends ScalaModule with PublishModule with Cross.Module[String] { @@ -106,8 +106,8 @@ trait ItestCross extends MillIntegrationTestModule with Cross.Module[String] { override def testInvocations: Target[Seq[(PathRef, Seq[TestInvocation.Targets])]] = T { Seq( PathRef(millSourcePath / "src" / "01-simple-site") -> Seq( - TestInvocation.Targets(Seq("verify")), - TestInvocation.Targets(Seq("site.jbake")) + TestInvocation.Targets(Seq("verifyInit")), + TestInvocation.Targets(Seq("verifyBake")) ) ) } diff --git a/itest/src/01-simple-site/build.sc b/itest/src/01-simple-site/build.sc index 4dda161..5944798 100644 --- a/itest/src/01-simple-site/build.sc +++ b/itest/src/01-simple-site/build.sc @@ -1,28 +1,81 @@ import mill._ import mill.define._ -// import $ivy.`de.tototec::de.tobiasroeser.mill.jbake:0.2.0` -import $exec.plugins +import $file.plugins import de.tobiasroeser.mill.jbake._ import $ivy.`org.scalatest::scalatest:3.1.4` import org.scalatest.Assertions -object site extends JBakeModule { - +object siteSp extends JBakeModule { override def jbakeVersion = "2.6.4" override def jbakeProcessMode = JBakeModule.SubProcess +} +object siteCl extends JBakeModule { + override def jbakeVersion = "2.6.4" + + override def jbakeProcessMode = JBakeModule.ClassLoader } -def verify(): Command[Unit] = T.command { +val A = new Assertions {} + +import A._ - val A = new Assertions{} - import A._ +val sites = Seq(siteSp, siteCl) + +def verifyInit(site: JBakeModule): Task[Unit] = T.task { site.jbakeInit()() - val files = os.walk(site.millSourcePath / "src") - assert(files.contains(site.millSourcePath / "src" / "templates")) + val expected = Seq( + os.sub / "jbake.properties", + os.sub / "templates" / "archive.ftl", + os.sub / "templates" / "feed.ftl", + os.sub / "templates" / "footer.ftl", + os.sub / "templates" / "header.ftl", + os.sub / "templates" / "index.ftl", + os.sub / "templates" / "menu.ftl", + os.sub / "templates" / "page.ftl", + os.sub / "templates" / "post.ftl", + os.sub / "templates" / "sitemap.ftl", + os.sub / "templates" / "tags.ftl", + os.sub / "content" / "about.html", + ) + + val dir = site.millSourcePath / "src" + val files = os.walk(dir) + + for { + file <- expected + } assert(files.contains(dir / file)) +} + +def verifyBake(site: JBakeModule): Task[Unit] = T.task { + site.jbake() + + val expected = Seq( + os.sub / "index.html", + os.sub / "favicon.ico", + os.sub / "feed.xml", + os.sub / "archive.html" + + ) + + val dir = T.workspace / "out" / site.toString() / "jbake.dest" + val files = os.walk(dir) + + for { + file <- expected + } assert(files.contains(dir / file)) +} + +def verifyInit(): Command[Unit] = T.command { + T.traverse(sites)(s => verifyInit(s))() + () +} +def verifyBake(): Command[Unit] = T.command { + // Classloader mode does not work anymore with newer Java + T.traverse(Seq(siteSp))(s => verifyBake(s))() () } diff --git a/jbake/src/de/tobiasroeser/mill/jbake/JBakeModule.scala b/jbake/src/de/tobiasroeser/mill/jbake/JBakeModule.scala index 04d8456..677a6f3 100644 --- a/jbake/src/de/tobiasroeser/mill/jbake/JBakeModule.scala +++ b/jbake/src/de/tobiasroeser/mill/jbake/JBakeModule.scala @@ -70,9 +70,9 @@ trait JBakeModule extends Module with TaskModule { parseVersion(jbakeVersion()) match { case Success(Array(2, 0 | 1 | 2 | 3 | 4 | 5, _)) => (Seq(jbakeDistributionDir().path / "jbake-core.jar") ++ - os.list(jbakeDistributionDir().path / 'lib)).map(PathRef(_)) + os.list(jbakeDistributionDir().path / "lib")).map(PathRef(_)) case _ => - os.list(jbakeDistributionDir().path / 'lib).map(PathRef(_)) + os.list(jbakeDistributionDir().path / "lib").map(PathRef(_)) } } @@ -109,7 +109,7 @@ trait JBakeModule extends Module with TaskModule { /** * Initialized the sources for a new project. */ - def jbakeInit() = T.command { + def jbakeInit(): Command[PathRef] = T.command { val src = sources().head.path if (os.exists(src) && !os.walk(src).isEmpty) { throw new RuntimeException(s"Source directory ${src} is not empty. Aborting initialization of fresh JBake project") @@ -119,6 +119,7 @@ trait JBakeModule extends Module with TaskModule { // val baseZip = ??? // IO.unpackZip(baseZip, ) } + PathRef(T.ctx().dest) } /**