From 15f04fa0c750a6269e1066f4884097a6d543779b Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Sat, 23 Sep 2023 18:27:02 +0200 Subject: [PATCH 01/21] Compiling Scripts in CI through sbt itself --- .github/workflows/ci.yml | 2 +- .mergify.yml | 8 ++ build.sbt | 36 ++++++++- project/plugins.sbt | 1 + .../toolkit/ToolkitCompilationTest.scala | 79 +++++++++++++++++++ 5 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 54f97fc..ed5b7b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -235,7 +235,7 @@ jobs: - name: Submit Dependencies uses: scalacenter/sbt-dependency-submission@v2 with: - modules-ignore: rootjs_2.13 rootjs_3 docs_3 rootjvm_2.13 rootjvm_3 rootnative_2.13 rootnative_3 + modules-ignore: rootjs_2.13 rootjs_3 docs_3 rootjvm_2.13 rootjvm_3 rootnative_2.13 rootnative_3 toolkit-testing_2.13 toolkit-testing_3 configs-ignore: test scala-tool scala-doc-tool test-internal site: diff --git a/.mergify.yml b/.mergify.yml index 49ba5cc..49be9db 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -42,3 +42,11 @@ pull_request_rules: add: - toolkit-test remove: [] +- name: Label toolkit-testing PRs + conditions: + - files~=^toolkit-testing/ + actions: + label: + add: + - toolkit-testing + remove: [] diff --git a/build.sbt b/build.sbt index c3f457d..e5d4a3a 100644 --- a/build.sbt +++ b/build.sbt @@ -11,7 +11,11 @@ ThisBuild / mergifyStewardConfig ~= { ThisBuild / crossScalaVersions := Seq("2.13.12", "3.3.1") -lazy val root = tlCrossRootProject.aggregate(toolkit, toolkitTest) +lazy val root = tlCrossRootProject + .aggregate(toolkit, toolkitTest) + .settings( + (Test / test) := (Test / test).dependsOn(toolkitTesting / Test / test).value + ) lazy val toolkit = crossProject(JVMPlatform, JSPlatform, NativePlatform) .in(file("toolkit")) @@ -44,6 +48,36 @@ lazy val toolkitTest = crossProject(JVMPlatform, JSPlatform, NativePlatform) mimaPreviousArtifacts := Set() ) +lazy val toolkitTesting = project + .in(file("toolkit-testing")) + .settings( + name := "toolkit-testing", + Test / test := (Test / test).dependsOn(toolkit.jvm / publishLocal).value, + scalacOptions ++= { + if (scalaBinaryVersion.value == "2.13") Seq("-Ytasty-reader") else Nil + }, + libraryDependencies ++= Seq( + "org.typelevel" %% "munit-cats-effect" % "2.0.0-M3" % Test, + "co.fs2" %% "fs2-io" % "3.9.2" % Test, + // https://github.com/VirtusLab/scala-cli/issues/2421 + "org.virtuslab.scala-cli" %% "cli" % "1.0.4" % Test cross (CrossVersion.for2_13Use3) excludeAll ( + ExclusionRule("com.lihaoyi:geny_2.13"), + ExclusionRule( + "org.scala-lang.modules", + "scala-collection-compat_2.13" + ), + ExclusionRule( + "com.github.plokhotnyuk.jsoniter-scala", + "jsoniter-scala-core_2.13" + ), + ExclusionRule("com.lihaoyi", "sourcecode_2.13"), + ExclusionRule("ai.kien", "python-native-libs_2.13"), + ExclusionRule("com.lihaoyi", "os-lib_2.13") + ) + ) + ) + .enablePlugins(BuildInfoPlugin, NoPublishPlugin) + lazy val docs = project .in(file("site")) .enablePlugins(TypelevelSitePlugin) diff --git a/project/plugins.sbt b/project/plugins.sbt index ce60d6b..6333e60 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -4,3 +4,4 @@ addSbtPlugin("org.typelevel" % "sbt-typelevel-mergify" % sbtTlVersion) addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % sbtTlVersion) addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.2") addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.15") +addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") diff --git a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala new file mode 100644 index 0000000..bea3520 --- /dev/null +++ b/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -0,0 +1,79 @@ +package org.typelevel.toolkit + +import munit.{CatsEffectSuite, TestOptions} +import cats.effect.IO +import fs2.Stream +import fs2.io.file.Files +import scala.cli.ScalaCli +import buildinfo.BuildInfo.{version, scalaVersion} + +class ToolkitCompilationTest extends CatsEffectSuite { + + testCompilation213("Toolkit should compile a simple Hello Cats Effect") { + s"""|import cats.effect._ + | + |object Hello extends IOApp.Simple { + | def run = IO.println("Hello toolkit!") + |}""" + } + + testCompilation3("Toolkit should compile a simple Hello Cats Effect") { + s"""|import cats.effect.* + | + |object Hello extends IOApp.Simple: + | def run = IO.println("Hello toolkit!")""" + } + + testCompilation213("Toolkit should compile a script with every dependency") { + s"""|import cats.syntax.all._ + |import cats.effect._ + |import com.monovore.decline.effect._ + |import fs2.data.csv.generic.semiauto._ + |import fs2.io.file._ + |import io.circe._ + |import org.http4s.ember.client._ + | + |object Hello extends IOApp.Simple { + | def run = IO.println("Hello toolkit!") + |}""" + } + + testCompilation3("Toolkit should compile a script with every dependency") { + s"""|import cats.syntax.all.* + |import cats.effect.* + |import com.monovore.decline.effect.* + |import fs2.data.csv.generic.semiauto.* + |import fs2.io.file.* + |import org.http4s.ember.client.* + | + |object Hello extends IOApp.Simple: + | def run = IO.println("Hello toolkit!")""" + } + + def testCompilation213: String => String => Unit = testCompilation("2.13.12") + + def testCompilation3: String => String => Unit = testCompilation("3.3.1") + + def testCompilation( + expectedLangVersion: String + )(testName: String)(scriptBody: String): Unit = { + val options: TestOptions = TestOptions(s"$testName - $expectedLangVersion") + val testOptions: TestOptions = + if (scalaVersion == expectedLangVersion) options else options.ignore + test(testOptions)( + Files[IO] + .tempFile(None, "", ".scala", None) + .use { path => + val header = + s"//> using scala $scalaVersion\n//> using toolkit typelevel:$version\n" + Stream(header, scriptBody.stripMargin) + .through(Files[IO].writeUtf8(path)) + .compile + .drain >> IO.delay( + ScalaCli.main(Array("compile", path.toString)) + ) + } + ) + } + +} From 562d4f75653e32672dc6035510830c40169bf2ee Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Sun, 24 Sep 2023 00:04:19 +0200 Subject: [PATCH 02/21] Changing the projects aggregation --- build.sbt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/build.sbt b/build.sbt index e5d4a3a..bd9fc0e 100644 --- a/build.sbt +++ b/build.sbt @@ -12,10 +12,7 @@ ThisBuild / mergifyStewardConfig ~= { ThisBuild / crossScalaVersions := Seq("2.13.12", "3.3.1") lazy val root = tlCrossRootProject - .aggregate(toolkit, toolkitTest) - .settings( - (Test / test) := (Test / test).dependsOn(toolkitTesting / Test / test).value - ) + .aggregate(toolkit, toolkitTest, toolkitTesting) lazy val toolkit = crossProject(JVMPlatform, JSPlatform, NativePlatform) .in(file("toolkit")) From 6859bea0f3597dd5bc8721a8e801dd026fab2645 Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Sun, 24 Sep 2023 00:07:29 +0200 Subject: [PATCH 03/21] Adding missing header --- .../toolkit/ToolkitCompilationTest.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala index bea3520..dcef0c3 100644 --- a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala +++ b/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -1,3 +1,19 @@ +/* + * Copyright 2023 Typelevel + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.typelevel.toolkit import munit.{CatsEffectSuite, TestOptions} From 0c9851e4a43c114f9673b94d384e05f5997315c0 Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Sun, 24 Sep 2023 14:34:13 +0200 Subject: [PATCH 04/21] Relying on external process --- build.sbt | 7 +- .../typelevel/toolkit/ScalaCliProcess.scala | 73 +++++++++++++++++++ .../toolkit/ToolkitCompilationTest.scala | 5 +- 3 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala diff --git a/build.sbt b/build.sbt index bd9fc0e..23dd5c9 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,6 @@ import laika.helium.config._ import laika.rewrite.nav.{ChoiceConfig, Selections, SelectionConfig} +import java.io.File ThisBuild / tlBaseVersion := "0.1" ThisBuild / startYear := Some(2023) @@ -71,7 +72,11 @@ lazy val toolkitTesting = project ExclusionRule("ai.kien", "python-native-libs_2.13"), ExclusionRule("com.lihaoyi", "os-lib_2.13") ) - ) + ), + Test / fork := true, + Test / javaOptions += s"-Dtoolkit.testing.classpath=${(Test / fullClasspath).value + .map(_.data.getAbsolutePath) + .mkString(File.pathSeparator)}" ) .enablePlugins(BuildInfoPlugin, NoPublishPlugin) diff --git a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala b/toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala new file mode 100644 index 0000000..300637e --- /dev/null +++ b/toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala @@ -0,0 +1,73 @@ +package org.typelevel.toolkit + +import fs2.io.process.{Process, ProcessBuilder, Processes} +import cats.effect.kernel.Concurrent +import cats.effect.std.Console +import cats.syntax.all._ +import cats.effect.syntax.all._ +import cats.effect.std.Supervisor +import cats.ApplicativeThrow + +object ScalaCliProcess { + + private val ClassPath: String = + System.getProperty("toolkit.testing.classpath") + private val JavaHome: String = { + val path = sys.env.get("JAVA_HOME").orElse(sys.props.get("java.home")).get + if (path.endsWith("/jre")) { + // handle JDK 8 installations + path.replace("/jre", "") + } else path + } + + private def scalaCli[F[_]: Processes: ApplicativeThrow: Concurrent: Console]( + args: List[String] + ): F[Unit] = ProcessBuilder( + s"$JavaHome/bin/java", + args.prependedAll(List("-cp", ClassPath, "scala.cli.ScalaCli")) + ).spawn[F] + .use(process => + process.exitValue.flatMap { + case 0 => ApplicativeThrow[F].unit + case x => + printStreams(process) >> ApplicativeThrow[F].raiseError( + new Exception(s"Non zero exit code ($x) for ${args.mkString(" ")}") + ) + } + ) + + private def printStreams[F[_]: Concurrent: Console]( + process: Process[F] + ): F[Unit] = { + Supervisor[F](await = true).use(supervisor => + for { + _ <- process.stdout + .through(fs2.text.utf8.decode) + .foreach(Console[F].println) + .compile + .drain + .supervise(supervisor) + _ <- process.stderr + .through(fs2.text.utf8.decode) + .foreach(Console[F].errorln) + .compile + .drain + .supervise(supervisor) + } yield () + ) + + } + + def command[F[_]: Processes: ApplicativeThrow: Concurrent: Console]( + args: List[String] + ): F[Unit] = scalaCli[F](args) + + def compile[F[_]: Processes: ApplicativeThrow: Concurrent: Console]( + fileName: String + ): F[Unit] = scalaCli[F]("compile" :: fileName :: Nil) + + def run[F[_]: Processes: ApplicativeThrow: Concurrent: Console]( + fileName: String + ): F[Unit] = scalaCli[F]("run" :: fileName :: Nil) + +} diff --git a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala index dcef0c3..74e98a6 100644 --- a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala +++ b/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -20,7 +20,6 @@ import munit.{CatsEffectSuite, TestOptions} import cats.effect.IO import fs2.Stream import fs2.io.file.Files -import scala.cli.ScalaCli import buildinfo.BuildInfo.{version, scalaVersion} class ToolkitCompilationTest extends CatsEffectSuite { @@ -85,9 +84,7 @@ class ToolkitCompilationTest extends CatsEffectSuite { Stream(header, scriptBody.stripMargin) .through(Files[IO].writeUtf8(path)) .compile - .drain >> IO.delay( - ScalaCli.main(Array("compile", path.toString)) - ) + .drain >> ScalaCliProcess.compile(path.toString) } ) } From ed5c60819926d177ca04c5fd5c8ea99e7e5ef99f Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Sun, 24 Sep 2023 14:35:20 +0200 Subject: [PATCH 05/21] Adding the header --- .../typelevel/toolkit/ScalaCliProcess.scala | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala b/toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala index 300637e..ce915a0 100644 --- a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala +++ b/toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala @@ -1,3 +1,19 @@ +/* + * Copyright 2023 Typelevel + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.typelevel.toolkit import fs2.io.process.{Process, ProcessBuilder, Processes} @@ -38,7 +54,7 @@ object ScalaCliProcess { private def printStreams[F[_]: Concurrent: Console]( process: Process[F] - ): F[Unit] = { + ): F[Unit] = Supervisor[F](await = true).use(supervisor => for { _ <- process.stdout @@ -56,8 +72,6 @@ object ScalaCliProcess { } yield () ) - } - def command[F[_]: Processes: ApplicativeThrow: Concurrent: Console]( args: List[String] ): F[Unit] = scalaCli[F](args) From 5809039aacaae6f485aab447ea4370d4c2f5a3fb Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Sun, 24 Sep 2023 14:46:28 +0200 Subject: [PATCH 06/21] Fixing some context bounds --- .../scala/org/typelevel/toolkit/ScalaCliProcess.scala | 8 ++++---- .../org/typelevel/toolkit/ToolkitCompilationTest.scala | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala b/toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala index ce915a0..b094e3b 100644 --- a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala +++ b/toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala @@ -36,7 +36,7 @@ object ScalaCliProcess { } else path } - private def scalaCli[F[_]: Processes: ApplicativeThrow: Concurrent: Console]( + private def scalaCli[F[_]: Processes: Concurrent: Console]( args: List[String] ): F[Unit] = ProcessBuilder( s"$JavaHome/bin/java", @@ -72,15 +72,15 @@ object ScalaCliProcess { } yield () ) - def command[F[_]: Processes: ApplicativeThrow: Concurrent: Console]( + def command[F[_]: Processes: Concurrent: Console]( args: List[String] ): F[Unit] = scalaCli[F](args) - def compile[F[_]: Processes: ApplicativeThrow: Concurrent: Console]( + def compile[F[_]: Processes: Concurrent: Console]( fileName: String ): F[Unit] = scalaCli[F]("compile" :: fileName :: Nil) - def run[F[_]: Processes: ApplicativeThrow: Concurrent: Console]( + def run[F[_]: Processes: Concurrent: Console]( fileName: String ): F[Unit] = scalaCli[F]("run" :: fileName :: Nil) diff --git a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala index 74e98a6..616818c 100644 --- a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala +++ b/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -84,7 +84,7 @@ class ToolkitCompilationTest extends CatsEffectSuite { Stream(header, scriptBody.stripMargin) .through(Files[IO].writeUtf8(path)) .compile - .drain >> ScalaCliProcess.compile(path.toString) + .drain >> ScalaCliProcess.compile[IO](path.toString) } ) } From d2de81ce7107066dacca5dbfce9942d11115cdd9 Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Sun, 24 Sep 2023 18:00:08 +0200 Subject: [PATCH 07/21] BuildInfo fu and cross platform testing --- build.sbt | 38 ++++++++++++++----- .../typelevel/toolkit/ScalaCliProcess.scala | 12 ++---- .../toolkit/ToolkitCompilationTest.scala | 9 +++-- 3 files changed, 38 insertions(+), 21 deletions(-) rename toolkit-testing/{ => shared}/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala (87%) rename toolkit-testing/{ => shared}/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala (91%) diff --git a/build.sbt b/build.sbt index 23dd5c9..ea19920 100644 --- a/build.sbt +++ b/build.sbt @@ -46,19 +46,18 @@ lazy val toolkitTest = crossProject(JVMPlatform, JSPlatform, NativePlatform) mimaPreviousArtifacts := Set() ) -lazy val toolkitTesting = project +lazy val toolkitTesting = crossProject(JVMPlatform, JSPlatform, NativePlatform) .in(file("toolkit-testing")) .settings( name := "toolkit-testing", - Test / test := (Test / test).dependsOn(toolkit.jvm / publishLocal).value, scalacOptions ++= { if (scalaBinaryVersion.value == "2.13") Seq("-Ytasty-reader") else Nil }, libraryDependencies ++= Seq( - "org.typelevel" %% "munit-cats-effect" % "2.0.0-M3" % Test, - "co.fs2" %% "fs2-io" % "3.9.2" % Test, + "org.typelevel" %%% "munit-cats-effect" % "2.0.0-M3" % Test, + "co.fs2" %%% "fs2-io" % "3.9.2" % Test, // https://github.com/VirtusLab/scala-cli/issues/2421 - "org.virtuslab.scala-cli" %% "cli" % "1.0.4" % Test cross (CrossVersion.for2_13Use3) excludeAll ( + "org.virtuslab.scala-cli" %% "cli" % "1.0.4" cross (CrossVersion.for2_13Use3) excludeAll ( ExclusionRule("com.lihaoyi:geny_2.13"), ExclusionRule( "org.scala-lang.modules", @@ -73,10 +72,31 @@ lazy val toolkitTesting = project ExclusionRule("com.lihaoyi", "os-lib_2.13") ) ), - Test / fork := true, - Test / javaOptions += s"-Dtoolkit.testing.classpath=${(Test / fullClasspath).value - .map(_.data.getAbsolutePath) - .mkString(File.pathSeparator)}" + buildInfoKeys += BuildInfoKey.map(Compile / dependencyClasspath) { + case (_, v) => + "classPath" -> v.seq + .map(_.data.getAbsolutePath) + .mkString(File.pathSeparator) + }, + buildInfoKeys += BuildInfoKey.action("javaHome") { + val path = sys.env.get("JAVA_HOME").orElse(sys.props.get("java.home")).get + if (path.endsWith("/jre")) { + // handle JDK 8 installations + path.replace("/jre", "") + } else path + } + ) + .jvmSettings( + Test / test := (Test / test).dependsOn(toolkit.jvm / publishLocal).value, + buildInfoKeys += "platform" -> "jvm" + ) + .jsSettings( + Test / test := (Test / test).dependsOn(toolkit.js / publishLocal).value, + buildInfoKeys += "platform" -> "js" + ) + .nativeSettings( + Test / test := (Test / test).dependsOn(toolkit.native / publishLocal).value, + buildInfoKeys += "platform" -> "native" ) .enablePlugins(BuildInfoPlugin, NoPublishPlugin) diff --git a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala b/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala similarity index 87% rename from toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala rename to toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala index b094e3b..19cfb32 100644 --- a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala +++ b/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala @@ -23,18 +23,12 @@ import cats.syntax.all._ import cats.effect.syntax.all._ import cats.effect.std.Supervisor import cats.ApplicativeThrow +import buildinfo.BuildInfo object ScalaCliProcess { - private val ClassPath: String = - System.getProperty("toolkit.testing.classpath") - private val JavaHome: String = { - val path = sys.env.get("JAVA_HOME").orElse(sys.props.get("java.home")).get - if (path.endsWith("/jre")) { - // handle JDK 8 installations - path.replace("/jre", "") - } else path - } + private val ClassPath: String = BuildInfo.classPath + private val JavaHome: String = BuildInfo.javaHome private def scalaCli[F[_]: Processes: Concurrent: Console]( args: List[String] diff --git a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala similarity index 91% rename from toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala rename to toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala index 616818c..da0e128 100644 --- a/toolkit-testing/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala +++ b/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -20,7 +20,7 @@ import munit.{CatsEffectSuite, TestOptions} import cats.effect.IO import fs2.Stream import fs2.io.file.Files -import buildinfo.BuildInfo.{version, scalaVersion} +import buildinfo.BuildInfo.{version, scalaVersion, platform} class ToolkitCompilationTest extends CatsEffectSuite { @@ -79,8 +79,11 @@ class ToolkitCompilationTest extends CatsEffectSuite { Files[IO] .tempFile(None, "", ".scala", None) .use { path => - val header = - s"//> using scala $scalaVersion\n//> using toolkit typelevel:$version\n" + val header = List( + s"//> using scala $scalaVersion", + s"//> using toolkit typelevel:$version", + s"//> using platform $platform" + ).mkString("", "\n", "\n") Stream(header, scriptBody.stripMargin) .through(Files[IO].writeUtf8(path)) .compile From f048cb09328e1cc8d672d9b69a634a510f4a4479 Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Sun, 24 Sep 2023 18:00:49 +0200 Subject: [PATCH 08/21] Called prePR --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ed5b7b2..e4f5c3c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -235,7 +235,7 @@ jobs: - name: Submit Dependencies uses: scalacenter/sbt-dependency-submission@v2 with: - modules-ignore: rootjs_2.13 rootjs_3 docs_3 rootjvm_2.13 rootjvm_3 rootnative_2.13 rootnative_3 toolkit-testing_2.13 toolkit-testing_3 + modules-ignore: toolkit-testing_native0.4_2.13 toolkit-testing_native0.4_3 toolkit-testing_sjs1_2.13 toolkit-testing_sjs1_3 rootjs_2.13 rootjs_3 docs_3 rootjvm_2.13 rootjvm_3 rootnative_2.13 rootnative_3 toolkit-testing_2.13 toolkit-testing_3 configs-ignore: test scala-tool scala-doc-tool test-internal site: From 65aebe986e2f93787b505cfc1f16821982e81a53 Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Sun, 24 Sep 2023 22:25:04 +0200 Subject: [PATCH 09/21] Fixing js linking --- build.sbt | 3 +- .../typelevel/toolkit/ScalaCliProcess.scala | 33 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/build.sbt b/build.sbt index ea19920..a6e012e 100644 --- a/build.sbt +++ b/build.sbt @@ -92,7 +92,8 @@ lazy val toolkitTesting = crossProject(JVMPlatform, JSPlatform, NativePlatform) ) .jsSettings( Test / test := (Test / test).dependsOn(toolkit.js / publishLocal).value, - buildInfoKeys += "platform" -> "js" + buildInfoKeys += "platform" -> "js", + scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) } ) .nativeSettings( Test / test := (Test / test).dependsOn(toolkit.native / publishLocal).value, diff --git a/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala b/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala index 19cfb32..e170654 100644 --- a/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala +++ b/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala @@ -48,23 +48,22 @@ object ScalaCliProcess { private def printStreams[F[_]: Concurrent: Console]( process: Process[F] - ): F[Unit] = - Supervisor[F](await = true).use(supervisor => - for { - _ <- process.stdout - .through(fs2.text.utf8.decode) - .foreach(Console[F].println) - .compile - .drain - .supervise(supervisor) - _ <- process.stderr - .through(fs2.text.utf8.decode) - .foreach(Console[F].errorln) - .compile - .drain - .supervise(supervisor) - } yield () - ) + ): F[Unit] = Supervisor[F](await = true).use(supervisor => + for { + _ <- process.stdout + .through(fs2.text.utf8.decode) + .foreach(Console[F].println) + .compile + .drain + .supervise(supervisor) + _ <- process.stderr + .through(fs2.text.utf8.decode) + .foreach(Console[F].errorln) + .compile + .drain + .supervise(supervisor) + } yield () + ) def command[F[_]: Processes: Concurrent: Console]( args: List[String] From 77b457d31e94f9f34b4e1cb97caffe90c38c25af Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Sun, 24 Sep 2023 22:53:26 +0200 Subject: [PATCH 10/21] Added test run too --- .../typelevel/toolkit/ScalaCliProcess.scala | 38 ++++- .../toolkit/ToolkitCompilationTest.scala | 142 +++++++++++------- 2 files changed, 120 insertions(+), 60 deletions(-) diff --git a/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala b/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala index e170654..27a8188 100644 --- a/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala +++ b/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala @@ -24,6 +24,8 @@ import cats.effect.syntax.all._ import cats.effect.std.Supervisor import cats.ApplicativeThrow import buildinfo.BuildInfo +import fs2.Stream +import fs2.io.file.Files object ScalaCliProcess { @@ -65,16 +67,40 @@ object ScalaCliProcess { } yield () ) + private def writeToFile[F[_]: Files: Concurrent]( + scriptBody: String + ): F[String] = + Files[F] + .tempFile(None, "", ".scala", None) + .use { path => + val header = List( + s"//> using scala ${BuildInfo.scalaVersion}", + s"//> using toolkit typelevel:${BuildInfo.version}", + s"//> using platform ${BuildInfo.platform}" + ).mkString("", "\n", "\n") + Stream(header, scriptBody.stripMargin) + .through(Files[F].writeUtf8(path)) + .compile + .drain + .as(path.toString) + } + def command[F[_]: Processes: Concurrent: Console]( args: List[String] ): F[Unit] = scalaCli[F](args) - def compile[F[_]: Processes: Concurrent: Console]( - fileName: String - ): F[Unit] = scalaCli[F]("compile" :: fileName :: Nil) + def compile[F[_]: Processes: Concurrent: Console: Files]( + body: String + ): F[Unit] = for { + fileName <- writeToFile(body) + _ <- scalaCli[F]("compile" :: fileName :: Nil) + } yield () - def run[F[_]: Processes: Concurrent: Console]( - fileName: String - ): F[Unit] = scalaCli[F]("run" :: fileName :: Nil) + def run[F[_]: Processes: Concurrent: Console: Files]( + body: String + ): F[Unit] = for { + fileName <- writeToFile(body) + _ <- scalaCli[F]("run" :: fileName :: Nil) + } yield () } diff --git a/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala index da0e128..62838c7 100644 --- a/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala +++ b/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -18,78 +18,112 @@ package org.typelevel.toolkit import munit.{CatsEffectSuite, TestOptions} import cats.effect.IO -import fs2.Stream -import fs2.io.file.Files -import buildinfo.BuildInfo.{version, scalaVersion, platform} +import buildinfo.BuildInfo.scalaVersion class ToolkitCompilationTest extends CatsEffectSuite { testCompilation213("Toolkit should compile a simple Hello Cats Effect") { - s"""|import cats.effect._ - | - |object Hello extends IOApp.Simple { - | def run = IO.println("Hello toolkit!") - |}""" + """|import cats.effect._ + | + |object Hello extends IOApp.Simple { + | def run = IO.println("Hello toolkit!") + |}""" + } + + testRun213("Toolkit should run a simple Hello Cats Effect") { + """|import cats.effect._ + | + |object Hello extends IOApp.Simple { + | def run = IO.println("Hello toolkit!") + |}""" } testCompilation3("Toolkit should compile a simple Hello Cats Effect") { - s"""|import cats.effect.* - | - |object Hello extends IOApp.Simple: - | def run = IO.println("Hello toolkit!")""" + """|import cats.effect.* + | + |object Hello extends IOApp.Simple: + | def run = IO.println("Hello toolkit!")""" + } + + testRun3("Toolkit should run a simple Hello Cats Effect") { + """|import cats.effect.* + | + |object Hello extends IOApp.Simple: + | def run = IO.println("Hello toolkit!")""" } testCompilation213("Toolkit should compile a script with every dependency") { - s"""|import cats.syntax.all._ - |import cats.effect._ - |import com.monovore.decline.effect._ - |import fs2.data.csv.generic.semiauto._ - |import fs2.io.file._ - |import io.circe._ - |import org.http4s.ember.client._ - | - |object Hello extends IOApp.Simple { - | def run = IO.println("Hello toolkit!") - |}""" + """|import cats.syntax.all._ + |import cats.effect._ + |import com.monovore.decline.effect._ + |import fs2.data.csv.generic.semiauto._ + |import fs2.io.file._ + |import io.circe._ + |import org.http4s.ember.client._ + | + |object Hello extends IOApp.Simple { + | def run = IO.println("Hello toolkit!") + |}""" + } + + testRun213("Toolkit should run a script with every dependency") { + """|import cats.syntax.all._ + |import cats.effect._ + |import com.monovore.decline.effect._ + |import fs2.data.csv.generic.semiauto._ + |import fs2.io.file._ + |import io.circe._ + |import org.http4s.ember.client._ + | + |object Hello extends IOApp.Simple { + | def run = IO.println("Hello toolkit!") + |}""" } testCompilation3("Toolkit should compile a script with every dependency") { - s"""|import cats.syntax.all.* - |import cats.effect.* - |import com.monovore.decline.effect.* - |import fs2.data.csv.generic.semiauto.* - |import fs2.io.file.* - |import org.http4s.ember.client.* - | - |object Hello extends IOApp.Simple: - | def run = IO.println("Hello toolkit!")""" + """|import cats.syntax.all.* + |import cats.effect.* + |import com.monovore.decline.effect.* + |import fs2.data.csv.generic.semiauto.* + |import fs2.io.file.* + |import org.http4s.ember.client.* + | + |object Hello extends IOApp.Simple: + | def run = IO.println("Hello toolkit!")""" } - def testCompilation213: String => String => Unit = testCompilation("2.13.12") + testRun3("Toolkit should run a script with every dependency") { + """|import cats.syntax.all.* + |import cats.effect.* + |import com.monovore.decline.effect.* + |import fs2.data.csv.generic.semiauto.* + |import fs2.io.file.* + |import org.http4s.ember.client.* + | + |object Hello extends IOApp.Simple: + | def run = IO.println("Hello toolkit!")""" + } - def testCompilation3: String => String => Unit = testCompilation("3.3.1") + def testCompilation213 = testCompilation("2.13.12") + + def testCompilation3 = testCompilation("3.3.1") + + def testRun213 = testCompilation("2.13.12") + + def testRun3 = testCompilation("3.3.1") def testCompilation( expectedLangVersion: String - )(testName: String)(scriptBody: String): Unit = { - val options: TestOptions = TestOptions(s"$testName - $expectedLangVersion") - val testOptions: TestOptions = - if (scalaVersion == expectedLangVersion) options else options.ignore - test(testOptions)( - Files[IO] - .tempFile(None, "", ".scala", None) - .use { path => - val header = List( - s"//> using scala $scalaVersion", - s"//> using toolkit typelevel:$version", - s"//> using platform $platform" - ).mkString("", "\n", "\n") - Stream(header, scriptBody.stripMargin) - .through(Files[IO].writeUtf8(path)) - .compile - .drain >> ScalaCliProcess.compile[IO](path.toString) - } - ) - } + )(testName: TestOptions)(scriptBody: String): Unit = test { + val t = testName.withName(s"${testName.name} - $expectedLangVersion") + if (scalaVersion == expectedLangVersion) t else t.ignore + }(ScalaCliProcess.compile[IO](scriptBody)) + + def testRun( + expectedLangVersion: String + )(testName: TestOptions)(scriptBody: String): Unit = test { + val t = testName.withName(s"${testName.name} - $expectedLangVersion") + if (scalaVersion == expectedLangVersion) t else t.ignore + }(ScalaCliProcess.run[IO](scriptBody)) } From c9752b26ddf390fd81e989b86816ef95dd70e383 Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Sun, 24 Sep 2023 22:59:58 +0200 Subject: [PATCH 11/21] Added correct tempFile handling to test --- .../org/typelevel/toolkit/ScalaCliProcess.scala | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala b/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala index 27a8188..2bf6c70 100644 --- a/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala +++ b/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala @@ -17,7 +17,7 @@ package org.typelevel.toolkit import fs2.io.process.{Process, ProcessBuilder, Processes} -import cats.effect.kernel.Concurrent +import cats.effect.kernel.{Concurrent, Resource} import cats.effect.std.Console import cats.syntax.all._ import cats.effect.syntax.all._ @@ -69,10 +69,10 @@ object ScalaCliProcess { private def writeToFile[F[_]: Files: Concurrent]( scriptBody: String - ): F[String] = + ): Resource[F, String] = Files[F] .tempFile(None, "", ".scala", None) - .use { path => + .flatMap { path => val header = List( s"//> using scala ${BuildInfo.scalaVersion}", s"//> using toolkit typelevel:${BuildInfo.version}", @@ -83,6 +83,7 @@ object ScalaCliProcess { .compile .drain .as(path.toString) + .toResource } def command[F[_]: Processes: Concurrent: Console]( @@ -91,16 +92,10 @@ object ScalaCliProcess { def compile[F[_]: Processes: Concurrent: Console: Files]( body: String - ): F[Unit] = for { - fileName <- writeToFile(body) - _ <- scalaCli[F]("compile" :: fileName :: Nil) - } yield () + ): F[Unit] = writeToFile(body).use(f => scalaCli[F]("compile" :: f :: Nil)) def run[F[_]: Processes: Concurrent: Console: Files]( body: String - ): F[Unit] = for { - fileName <- writeToFile(body) - _ <- scalaCli[F]("run" :: fileName :: Nil) - } yield () + ): F[Unit] = writeToFile(body).use(f => scalaCli[F]("run" :: f :: Nil)) } From 4661c86f3b88bed129bd3b25e376c06464d0ba00 Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Mon, 25 Sep 2023 23:30:14 +0200 Subject: [PATCH 12/21] Removing tagless final style from tests --- .github/workflows/ci.yml | 2 +- .mergify.yml | 16 ++-- build.sbt | 8 +- .../typelevel/toolkit/ScalaCliProcess.scala | 77 ++++++++----------- .../toolkit/ToolkitCompilationTest.scala | 5 +- 5 files changed, 46 insertions(+), 62 deletions(-) rename {toolkit-testing => tests}/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala (50%) rename {toolkit-testing => tests}/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala (97%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4f5c3c..fbd3be3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -235,7 +235,7 @@ jobs: - name: Submit Dependencies uses: scalacenter/sbt-dependency-submission@v2 with: - modules-ignore: toolkit-testing_native0.4_2.13 toolkit-testing_native0.4_3 toolkit-testing_sjs1_2.13 toolkit-testing_sjs1_3 rootjs_2.13 rootjs_3 docs_3 rootjvm_2.13 rootjvm_3 rootnative_2.13 rootnative_3 toolkit-testing_2.13 toolkit-testing_3 + modules-ignore: rootjs_2.13 rootjs_3 docs_3 tests_sjs1_2.13 tests_sjs1_3 rootjvm_2.13 rootjvm_3 rootnative_2.13 rootnative_3 tests_2.13 tests_3 tests_native0.4_2.13 tests_native0.4_3 configs-ignore: test scala-tool scala-doc-tool test-internal site: diff --git a/.mergify.yml b/.mergify.yml index 49be9db..d7f8f95 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -26,6 +26,14 @@ pull_request_rules: add: - site remove: [] +- name: Label tests PRs + conditions: + - files~=^tests/ + actions: + label: + add: + - tests + remove: [] - name: Label toolkit PRs conditions: - files~=^toolkit/ @@ -42,11 +50,3 @@ pull_request_rules: add: - toolkit-test remove: [] -- name: Label toolkit-testing PRs - conditions: - - files~=^toolkit-testing/ - actions: - label: - add: - - toolkit-testing - remove: [] diff --git a/build.sbt b/build.sbt index a6e012e..1cf3759 100644 --- a/build.sbt +++ b/build.sbt @@ -13,7 +13,7 @@ ThisBuild / mergifyStewardConfig ~= { ThisBuild / crossScalaVersions := Seq("2.13.12", "3.3.1") lazy val root = tlCrossRootProject - .aggregate(toolkit, toolkitTest, toolkitTesting) + .aggregate(toolkit, toolkitTest, tests) lazy val toolkit = crossProject(JVMPlatform, JSPlatform, NativePlatform) .in(file("toolkit")) @@ -46,10 +46,10 @@ lazy val toolkitTest = crossProject(JVMPlatform, JSPlatform, NativePlatform) mimaPreviousArtifacts := Set() ) -lazy val toolkitTesting = crossProject(JVMPlatform, JSPlatform, NativePlatform) - .in(file("toolkit-testing")) +lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform) + .in(file("tests")) .settings( - name := "toolkit-testing", + name := "tests", scalacOptions ++= { if (scalaBinaryVersion.value == "2.13") Seq("-Ytasty-reader") else Nil }, diff --git a/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala similarity index 50% rename from toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala rename to tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala index 2bf6c70..4ed3752 100644 --- a/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala @@ -16,86 +16,71 @@ package org.typelevel.toolkit -import fs2.io.process.{Process, ProcessBuilder, Processes} -import cats.effect.kernel.{Concurrent, Resource} +import cats.effect.kernel.Resource import cats.effect.std.Console -import cats.syntax.all._ -import cats.effect.syntax.all._ -import cats.effect.std.Supervisor -import cats.ApplicativeThrow +import cats.effect.IO import buildinfo.BuildInfo import fs2.Stream import fs2.io.file.Files +import fs2.io.process.{Process, ProcessBuilder, Processes} object ScalaCliProcess { private val ClassPath: String = BuildInfo.classPath private val JavaHome: String = BuildInfo.javaHome - private def scalaCli[F[_]: Processes: Concurrent: Console]( - args: List[String] - ): F[Unit] = ProcessBuilder( + private def scalaCli(args: List[String]): IO[Unit] = ProcessBuilder( s"$JavaHome/bin/java", args.prependedAll(List("-cp", ClassPath, "scala.cli.ScalaCli")) - ).spawn[F] + ).spawn[IO] .use(process => process.exitValue.flatMap { - case 0 => ApplicativeThrow[F].unit + case 0 => IO.unit case x => - printStreams(process) >> ApplicativeThrow[F].raiseError( + printStreams(process) >> IO.raiseError( new Exception(s"Non zero exit code ($x) for ${args.mkString(" ")}") ) } ) - private def printStreams[F[_]: Concurrent: Console]( - process: Process[F] - ): F[Unit] = Supervisor[F](await = true).use(supervisor => - for { - _ <- process.stdout - .through(fs2.text.utf8.decode) - .foreach(Console[F].println) - .compile - .drain - .supervise(supervisor) - _ <- process.stderr - .through(fs2.text.utf8.decode) - .foreach(Console[F].errorln) - .compile - .drain - .supervise(supervisor) - } yield () - ) + private def printStreams(process: Process[IO]): IO[Unit] = { + val stdout: IO[Unit] = process.stdout + .through(fs2.text.utf8.decode) + .foreach(Console[IO].print) + .compile + .drain + val stderr: IO[Unit] = process.stderr + .through(fs2.text.utf8.decode) + .foreach(Console[IO].error) + .compile + .drain + stdout.both(stderr).void + } - private def writeToFile[F[_]: Files: Concurrent]( + private def writeToFile( scriptBody: String - ): Resource[F, String] = - Files[F] + ): Resource[IO, String] = + Files[IO] .tempFile(None, "", ".scala", None) - .flatMap { path => + .evalTap { path => val header = List( s"//> using scala ${BuildInfo.scalaVersion}", s"//> using toolkit typelevel:${BuildInfo.version}", s"//> using platform ${BuildInfo.platform}" ).mkString("", "\n", "\n") Stream(header, scriptBody.stripMargin) - .through(Files[F].writeUtf8(path)) + .through(Files[IO].writeUtf8(path)) .compile .drain - .as(path.toString) - .toResource } + .map(_.toString) - def command[F[_]: Processes: Concurrent: Console]( - args: List[String] - ): F[Unit] = scalaCli[F](args) + def command(args: List[String]): IO[Unit] = scalaCli(args) - def compile[F[_]: Processes: Concurrent: Console: Files]( - body: String - ): F[Unit] = writeToFile(body).use(f => scalaCli[F]("compile" :: f :: Nil)) + def compile(body: String): IO[Unit] = + writeToFile(body).use(f => scalaCli("compile" :: f :: Nil)) - def run[F[_]: Processes: Concurrent: Console: Files]( - body: String - ): F[Unit] = writeToFile(body).use(f => scalaCli[F]("run" :: f :: Nil)) + def run(body: String): IO[Unit] = + writeToFile(body).use(f => scalaCli("run" :: f :: Nil)) } diff --git a/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala similarity index 97% rename from toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala rename to tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala index 62838c7..ed41031 100644 --- a/toolkit-testing/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -17,7 +17,6 @@ package org.typelevel.toolkit import munit.{CatsEffectSuite, TestOptions} -import cats.effect.IO import buildinfo.BuildInfo.scalaVersion class ToolkitCompilationTest extends CatsEffectSuite { @@ -117,13 +116,13 @@ class ToolkitCompilationTest extends CatsEffectSuite { )(testName: TestOptions)(scriptBody: String): Unit = test { val t = testName.withName(s"${testName.name} - $expectedLangVersion") if (scalaVersion == expectedLangVersion) t else t.ignore - }(ScalaCliProcess.compile[IO](scriptBody)) + }(ScalaCliProcess.compile(scriptBody)) def testRun( expectedLangVersion: String )(testName: TestOptions)(scriptBody: String): Unit = test { val t = testName.withName(s"${testName.name} - $expectedLangVersion") if (scalaVersion == expectedLangVersion) t else t.ignore - }(ScalaCliProcess.run[IO](scriptBody)) + }(ScalaCliProcess.run(scriptBody)) } From 1f1c1357579b7beaf4fd9a24553a4a71b976d89b Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Mon, 25 Sep 2023 23:49:10 +0200 Subject: [PATCH 13/21] Changing test implementation --- build.sbt | 3 +- .../toolkit/ToolkitCompilationTest.scala | 138 +++++------------- 2 files changed, 40 insertions(+), 101 deletions(-) diff --git a/build.sbt b/build.sbt index 1cf3759..9a4506c 100644 --- a/build.sbt +++ b/build.sbt @@ -84,7 +84,8 @@ lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform) // handle JDK 8 installations path.replace("/jre", "") } else path - } + }, + buildInfoKeys += "scala3" -> (scalaVersion.value.head == '3') ) .jvmSettings( Test / test := (Test / test).dependsOn(toolkit.jvm / publishLocal).value, diff --git a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala index ed41031..20c54b2 100644 --- a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -17,112 +17,50 @@ package org.typelevel.toolkit import munit.{CatsEffectSuite, TestOptions} -import buildinfo.BuildInfo.scalaVersion +import buildinfo.BuildInfo.scala3 class ToolkitCompilationTest extends CatsEffectSuite { - testCompilation213("Toolkit should compile a simple Hello Cats Effect") { - """|import cats.effect._ - | - |object Hello extends IOApp.Simple { - | def run = IO.println("Hello toolkit!") - |}""" + testRun("Toolkit should run a simple Hello Cats Effect") { + if (scala3) + """|import cats.effect.* + | + |object Hello extends IOApp.Simple: + | def run = IO.println("Hello toolkit!")""" + else + """|import cats.effect._ + | + |object Hello extends IOApp.Simple { + | def run = IO.println("Hello toolkit!") + |}""" } - testRun213("Toolkit should run a simple Hello Cats Effect") { - """|import cats.effect._ - | - |object Hello extends IOApp.Simple { - | def run = IO.println("Hello toolkit!") - |}""" + testRun("Toolkit should run a script with every dependency") { + if (scala3) + """|import cats.syntax.all.* + |import cats.effect.* + |import com.monovore.decline.effect.* + |import fs2.data.csv.generic.semiauto.* + |import fs2.io.file.* + |import org.http4s.ember.client.* + | + |object Hello extends IOApp.Simple: + | def run = IO.println("Hello toolkit!")""" + else + """|import cats.syntax.all._ + |import cats.effect._ + |import com.monovore.decline.effect._ + |import fs2.data.csv.generic.semiauto._ + |import fs2.io.file._ + |import io.circe._ + |import org.http4s.ember.client._ + | + |object Hello extends IOApp.Simple { + | def run = IO.println("Hello toolkit!") + |}""" } - testCompilation3("Toolkit should compile a simple Hello Cats Effect") { - """|import cats.effect.* - | - |object Hello extends IOApp.Simple: - | def run = IO.println("Hello toolkit!")""" - } - - testRun3("Toolkit should run a simple Hello Cats Effect") { - """|import cats.effect.* - | - |object Hello extends IOApp.Simple: - | def run = IO.println("Hello toolkit!")""" - } - - testCompilation213("Toolkit should compile a script with every dependency") { - """|import cats.syntax.all._ - |import cats.effect._ - |import com.monovore.decline.effect._ - |import fs2.data.csv.generic.semiauto._ - |import fs2.io.file._ - |import io.circe._ - |import org.http4s.ember.client._ - | - |object Hello extends IOApp.Simple { - | def run = IO.println("Hello toolkit!") - |}""" - } - - testRun213("Toolkit should run a script with every dependency") { - """|import cats.syntax.all._ - |import cats.effect._ - |import com.monovore.decline.effect._ - |import fs2.data.csv.generic.semiauto._ - |import fs2.io.file._ - |import io.circe._ - |import org.http4s.ember.client._ - | - |object Hello extends IOApp.Simple { - | def run = IO.println("Hello toolkit!") - |}""" - } - - testCompilation3("Toolkit should compile a script with every dependency") { - """|import cats.syntax.all.* - |import cats.effect.* - |import com.monovore.decline.effect.* - |import fs2.data.csv.generic.semiauto.* - |import fs2.io.file.* - |import org.http4s.ember.client.* - | - |object Hello extends IOApp.Simple: - | def run = IO.println("Hello toolkit!")""" - } - - testRun3("Toolkit should run a script with every dependency") { - """|import cats.syntax.all.* - |import cats.effect.* - |import com.monovore.decline.effect.* - |import fs2.data.csv.generic.semiauto.* - |import fs2.io.file.* - |import org.http4s.ember.client.* - | - |object Hello extends IOApp.Simple: - | def run = IO.println("Hello toolkit!")""" - } - - def testCompilation213 = testCompilation("2.13.12") - - def testCompilation3 = testCompilation("3.3.1") - - def testRun213 = testCompilation("2.13.12") - - def testRun3 = testCompilation("3.3.1") - - def testCompilation( - expectedLangVersion: String - )(testName: TestOptions)(scriptBody: String): Unit = test { - val t = testName.withName(s"${testName.name} - $expectedLangVersion") - if (scalaVersion == expectedLangVersion) t else t.ignore - }(ScalaCliProcess.compile(scriptBody)) - - def testRun( - expectedLangVersion: String - )(testName: TestOptions)(scriptBody: String): Unit = test { - val t = testName.withName(s"${testName.name} - $expectedLangVersion") - if (scalaVersion == expectedLangVersion) t else t.ignore - }(ScalaCliProcess.run(scriptBody)) + def testRun(testName: TestOptions)(scriptBody: String): Unit = + test(testName)(ScalaCliProcess.run(scriptBody)) } From d26e164adb292a7ca43c1c8071a77a822ceafbfd Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Mon, 25 Sep 2023 23:52:24 +0200 Subject: [PATCH 14/21] Removing useless import --- .../typelevel/toolkit/ScalaCliProcess.scala | 2 +- .../toolkit/ToolkitCompilationTest.scala | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala index 4ed3752..1cff4c8 100644 --- a/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala @@ -22,7 +22,7 @@ import cats.effect.IO import buildinfo.BuildInfo import fs2.Stream import fs2.io.file.Files -import fs2.io.process.{Process, ProcessBuilder, Processes} +import fs2.io.process.{Process, ProcessBuilder} object ScalaCliProcess { diff --git a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala index 20c54b2..64f1e18 100644 --- a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -60,6 +60,31 @@ class ToolkitCompilationTest extends CatsEffectSuite { |}""" } + testRun("Toolkit should run a script with every dependency") { + if (scala3) + """|import cats.syntax.all.* + |import cats.effect.* + |import com.monovore.decline.effect.* + |import fs2.data.csv.generic.semiauto.* + |import fs2.io.file.* + |import org.http4s.ember.client.* + | + |object Hello extends IOApp.Simple: + | def run = IO.println("Hello toolkit!")""" + else + """|import cats.syntax.all._ + |import cats.effect._ + |import com.monovore.decline.effect._ + |import fs2.data.csv.generic.semiauto._ + |import fs2.io.file._ + |import io.circe._ + |import org.http4s.ember.client._ + | + |object Hello extends IOApp.Simple { + | def run = IO.println("Hello toolkit!") + |}""" + } + def testRun(testName: TestOptions)(scriptBody: String): Unit = test(testName)(ScalaCliProcess.run(scriptBody)) From d6841b5a326c1b7388c99757d0c7f1b8a70ca44e Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Tue, 26 Sep 2023 00:42:19 +0200 Subject: [PATCH 15/21] Avoiding js filename issue --- .../typelevel/toolkit/ScalaCliProcess.scala | 2 +- .../toolkit/ToolkitCompilationTest.scala | 25 ------------------- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala index 1cff4c8..ce341d0 100644 --- a/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala @@ -61,7 +61,7 @@ object ScalaCliProcess { scriptBody: String ): Resource[IO, String] = Files[IO] - .tempFile(None, "", ".scala", None) + .tempFile(None, "", "-toolkit.scala", None) .evalTap { path => val header = List( s"//> using scala ${BuildInfo.scalaVersion}", diff --git a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala index 64f1e18..20c54b2 100644 --- a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -60,31 +60,6 @@ class ToolkitCompilationTest extends CatsEffectSuite { |}""" } - testRun("Toolkit should run a script with every dependency") { - if (scala3) - """|import cats.syntax.all.* - |import cats.effect.* - |import com.monovore.decline.effect.* - |import fs2.data.csv.generic.semiauto.* - |import fs2.io.file.* - |import org.http4s.ember.client.* - | - |object Hello extends IOApp.Simple: - | def run = IO.println("Hello toolkit!")""" - else - """|import cats.syntax.all._ - |import cats.effect._ - |import com.monovore.decline.effect._ - |import fs2.data.csv.generic.semiauto._ - |import fs2.io.file._ - |import io.circe._ - |import org.http4s.ember.client._ - | - |object Hello extends IOApp.Simple { - | def run = IO.println("Hello toolkit!") - |}""" - } - def testRun(testName: TestOptions)(scriptBody: String): Unit = test(testName)(ScalaCliProcess.run(scriptBody)) From fdc037cefd37082fa177eb355e2f2e8c5495e0c3 Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Tue, 26 Sep 2023 01:11:42 +0200 Subject: [PATCH 16/21] Adding toolkit-test tests too --- build.sbt | 15 ++++++++++--- .../typelevel/toolkit/ScalaCliProcess.scala | 22 ++++++++++++------- .../toolkit/ToolkitCompilationTest.scala | 19 ++++++++++++++++ 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/build.sbt b/build.sbt index 9a4506c..a8124c9 100644 --- a/build.sbt +++ b/build.sbt @@ -88,16 +88,25 @@ lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform) buildInfoKeys += "scala3" -> (scalaVersion.value.head == '3') ) .jvmSettings( - Test / test := (Test / test).dependsOn(toolkit.jvm / publishLocal).value, + Test / test := (Test / test) + .dependsOn(toolkit.jvm / publishLocal, toolkitTest.jvm / publishLocal) + .value, buildInfoKeys += "platform" -> "jvm" ) .jsSettings( - Test / test := (Test / test).dependsOn(toolkit.js / publishLocal).value, + Test / test := (Test / test) + .dependsOn(toolkit.js / publishLocal, toolkitTest.js / publishLocal) + .value, buildInfoKeys += "platform" -> "js", scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) } ) .nativeSettings( - Test / test := (Test / test).dependsOn(toolkit.native / publishLocal).value, + Test / test := (Test / test) + .dependsOn( + toolkit.native / publishLocal, + toolkitTest.native / publishLocal + ) + .value, buildInfoKeys += "platform" -> "native" ) .enablePlugins(BuildInfoPlugin, NoPublishPlugin) diff --git a/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala index ce341d0..4cce169 100644 --- a/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala @@ -23,6 +23,7 @@ import buildinfo.BuildInfo import fs2.Stream import fs2.io.file.Files import fs2.io.process.{Process, ProcessBuilder} +import munit.Assertions.fail object ScalaCliProcess { @@ -37,8 +38,8 @@ object ScalaCliProcess { process.exitValue.flatMap { case 0 => IO.unit case x => - printStreams(process) >> IO.raiseError( - new Exception(s"Non zero exit code ($x) for ${args.mkString(" ")}") + printStreams(process) >> IO.delay( + fail(s"Non zero exit code ($x) for ${args.mkString(" ")}") ) } ) @@ -59,9 +60,14 @@ object ScalaCliProcess { private def writeToFile( scriptBody: String - ): Resource[IO, String] = + )(isTest: Boolean): Resource[IO, String] = Files[IO] - .tempFile(None, "", "-toolkit.scala", None) + .tempFile( + None, + "", + if (isTest) "-toolkit.test.scala" else "-toolkit.scala", + None + ) .evalTap { path => val header = List( s"//> using scala ${BuildInfo.scalaVersion}", @@ -77,10 +83,10 @@ object ScalaCliProcess { def command(args: List[String]): IO[Unit] = scalaCli(args) - def compile(body: String): IO[Unit] = - writeToFile(body).use(f => scalaCli("compile" :: f :: Nil)) - def run(body: String): IO[Unit] = - writeToFile(body).use(f => scalaCli("run" :: f :: Nil)) + writeToFile(body)(false).use(f => scalaCli("run" :: f :: Nil)) + + def test(body: String): IO[Unit] = + writeToFile(body)(true).use(f => scalaCli("test" :: f :: Nil)) } diff --git a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala index 20c54b2..e679d7b 100644 --- a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -60,7 +60,26 @@ class ToolkitCompilationTest extends CatsEffectSuite { |}""" } + testTest("Toolkit should execute a simple munit suite") { + if (scala3) + """|import cats.effect.* + |import munit.* + | + |class Test extends CatsEffectSuite: + | test("test")(IO.raiseError(new Exception))""" + else + """|import cats.effect._ + |import munit._ + | + |class Test extends CatsEffectSuite { + | test("test")(IO.unit) + |}""" + } + def testRun(testName: TestOptions)(scriptBody: String): Unit = test(testName)(ScalaCliProcess.run(scriptBody)) + def testTest(testName: TestOptions)(scriptBody: String): Unit = + test(testName)(ScalaCliProcess.test(scriptBody)) + } From 33219aafe0878e005337c9dcfcf4479e25410a22 Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Tue, 26 Sep 2023 01:19:16 +0200 Subject: [PATCH 17/21] Correcting the unit test --- .../scala/org/typelevel/toolkit/ToolkitCompilationTest.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala index e679d7b..5ba3c49 100644 --- a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -66,7 +66,7 @@ class ToolkitCompilationTest extends CatsEffectSuite { |import munit.* | |class Test extends CatsEffectSuite: - | test("test")(IO.raiseError(new Exception))""" + | test("test")(IO.unit)""" else """|import cats.effect._ |import munit._ From 9c11a87c8d0d76a0ed3d492e2f8c43368c718246 Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Tue, 26 Sep 2023 09:25:57 +0200 Subject: [PATCH 18/21] Temp fix for native --- .../scala/org/typelevel/toolkit/ScalaCliProcess.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala index 4cce169..febe66f 100644 --- a/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala @@ -84,9 +84,13 @@ object ScalaCliProcess { def command(args: List[String]): IO[Unit] = scalaCli(args) def run(body: String): IO[Unit] = - writeToFile(body)(false).use(f => scalaCli("run" :: f :: Nil)) + writeToFile(body)(false).use(f => + scalaCli("run" :: "--native-version" :: "0.4.15" :: f :: Nil) + ) def test(body: String): IO[Unit] = - writeToFile(body)(true).use(f => scalaCli("test" :: f :: Nil)) + writeToFile(body)(true).use(f => + scalaCli("test" :: "--native-version" :: "0.4.15" :: f :: Nil) + ) } From 5e47966f6d37f5f62969445583f6d67c94e8bbcc Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Tue, 26 Sep 2023 12:42:17 +0200 Subject: [PATCH 19/21] Let's not deadlock the code execution waiting for the exitcode w/o consuming stdout/stderr --- .../typelevel/toolkit/ScalaCliProcess.scala | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala index febe66f..47a87b2 100644 --- a/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ScalaCliProcess.scala @@ -19,10 +19,11 @@ package org.typelevel.toolkit import cats.effect.kernel.Resource import cats.effect.std.Console import cats.effect.IO +import cats.syntax.parallel._ import buildinfo.BuildInfo import fs2.Stream import fs2.io.file.Files -import fs2.io.process.{Process, ProcessBuilder} +import fs2.io.process.ProcessBuilder import munit.Assertions.fail object ScalaCliProcess { @@ -35,29 +36,19 @@ object ScalaCliProcess { args.prependedAll(List("-cp", ClassPath, "scala.cli.ScalaCli")) ).spawn[IO] .use(process => - process.exitValue.flatMap { - case 0 => IO.unit - case x => - printStreams(process) >> IO.delay( - fail(s"Non zero exit code ($x) for ${args.mkString(" ")}") + ( + process.exitValue, + process.stdout.through(fs2.text.utf8.decode).compile.string, + process.stderr.through(fs2.text.utf8.decode).compile.string + ).parFlatMapN { + case (0, _, _) => IO.unit + case (exitCode, stdout, stdErr) => + IO.println(stdout) >> Console[IO].errorln(stdErr) >> IO.delay( + fail(s"Non zero exit code ($exitCode) for ${args.mkString(" ")}") ) } ) - private def printStreams(process: Process[IO]): IO[Unit] = { - val stdout: IO[Unit] = process.stdout - .through(fs2.text.utf8.decode) - .foreach(Console[IO].print) - .compile - .drain - val stderr: IO[Unit] = process.stderr - .through(fs2.text.utf8.decode) - .foreach(Console[IO].error) - .compile - .drain - stdout.both(stderr).void - } - private def writeToFile( scriptBody: String )(isTest: Boolean): Resource[IO, String] = From 2297c31a49c852b1f711889cbe83792e3d99387d Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Tue, 26 Sep 2023 13:20:39 +0200 Subject: [PATCH 20/21] Increasing the test timeout --- .../scala/org/typelevel/toolkit/ToolkitCompilationTest.scala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala index 5ba3c49..c8dca0b 100644 --- a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -18,9 +18,13 @@ package org.typelevel.toolkit import munit.{CatsEffectSuite, TestOptions} import buildinfo.BuildInfo.scala3 +import scala.concurrent.duration._ class ToolkitCompilationTest extends CatsEffectSuite { + // Sometimes it will take more than 30 seconds for native code to get compiled and executed + override def munitIOTimeout: Duration = 1.minute + testRun("Toolkit should run a simple Hello Cats Effect") { if (scala3) """|import cats.effect.* From 98290a773ffeed86cb8f6260251ffa91e09d239e Mon Sep 17 00:00:00 2001 From: Antonio Gelameris Date: Tue, 26 Sep 2023 15:27:44 +0200 Subject: [PATCH 21/21] Increasing the test timeout to 2 minutes --- .../org/typelevel/toolkit/ToolkitCompilationTest.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala index c8dca0b..252c284 100644 --- a/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala +++ b/tests/shared/src/test/scala/org/typelevel/toolkit/ToolkitCompilationTest.scala @@ -22,8 +22,11 @@ import scala.concurrent.duration._ class ToolkitCompilationTest extends CatsEffectSuite { - // Sometimes it will take more than 30 seconds for native code to get compiled and executed - override def munitIOTimeout: Duration = 1.minute + // 2 minutes may seem a lot, but consider that the first test for + // each (scalaVersion, platform) will have to download the compiler + // (if it's not the default), compile (that for native takes awhile) + // and then finally run the code. + override def munitIOTimeout: Duration = 2.minute testRun("Toolkit should run a simple Hello Cats Effect") { if (scala3)