Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A toolkit of great libraries to get started building Typelevel apps on JVM, Node.js, and Native! Our very own flavour of the [Scala Toolkit].

```scala
```scala 3
//> using toolkit typelevel:default

import cats.effect.*
Expand All @@ -25,7 +25,7 @@ scala-cli --power new typelevel/toolkit.g8
* [http4s Ember client]
* [Circe] and http4s integration
* [Decline Effect]
* [Munit Cats Effect]
* [Weaver Test]

[Scala Toolkit]: https://docs.scala-lang.org/toolkit/introduction.html
[Cats]: https://typelevel.org/cats
Expand All @@ -36,4 +36,4 @@ scala-cli --power new typelevel/toolkit.g8
[http4s Ember Client]: https://http4s.org/v0.23/docs/client.html
[Circe]: https://circe.github.io/circe/
[Decline Effect]: https://ben.kirw.in/decline/effect.html
[Munit Cats Effect]: https://github.com/typelevel/munit-cats-effect
[Weaver Test]: https://github.com/typelevel/weaver-test
11 changes: 5 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import laika.helium.config._
import laika.config.{ChoiceConfig, Selections, SelectionConfig}
import java.io.File

ThisBuild / tlBaseVersion := "0.1"
ThisBuild / tlBaseVersion := "0.2"
ThisBuild / startYear := Some(2023)
ThisBuild / tlSitePublishBranch := Some("main")
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("17"))
Expand Down Expand Up @@ -40,8 +40,7 @@ lazy val toolkitTest = crossProject(JVMPlatform, JSPlatform, NativePlatform)
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % "2.13.0",
"org.typelevel" %%% "cats-effect-testkit" % "3.7.0",
"org.scalameta" %%% "munit" % "1.3.0", // not % Test, on purpose :)
"org.typelevel" %%% "munit-cats-effect" % "2.2.0"
"org.typelevel" %%% "weaver-cats" % "0.12.0" // not % Test, on purpose :)
),
libraryDependencySchemes += "org.scala-native" %% "test-interface_native0.5" % VersionScheme.Always,
mimaPreviousArtifacts := Set()
Expand All @@ -52,7 +51,7 @@ lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.settings(
name := "tests",
libraryDependencies ++= Seq(
"org.typelevel" %%% "munit-cats-effect" % "2.2.0" % Test,
"org.typelevel" %%% "weaver-cats" % "0.12.0" % Test,
"co.fs2" %%% "fs2-io" % "3.13.0" % Test,
"org.virtuslab.scala-cli" %% "cli" % "1.13.0" cross (CrossVersion.for2_13Use3)
),
Expand Down Expand Up @@ -117,8 +116,8 @@ lazy val docs = project
"Cats Effect"
),
TextLink.external(
"https://github.com/typelevel/munit-cats-effect",
"Munit Cats Effect"
"https://github.com/typelevel/weaver-test",
"Weaver Test"
)
)
)
Expand Down
10 changes: 5 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Typelevel toolkit is a meta library that currently includes these libraries:
- [Http4s Ember client]
- [Circe] and http4s integration
- [Decline Effect]
- [Munit Cats Effect]
- [Weaver Test]

and it's published for Scala 2.13 and 3.3+.

Expand Down Expand Up @@ -71,14 +71,14 @@ object Hello extends IOApp.Simple {

### Scala Native usage

Since the native flavour of most of the **Typelevel libraries** is, at the moment, built against Scala Native 0.4.15, when using [Scala CLI] you have to declare the Scala native's version, i.e.
Since the native flavour of most of the **Typelevel libraries** is, at the moment, built against Scala Native 0.5.11, when using [Scala CLI] you have to declare the Scala native's version, i.e.

@:select(scala-version)
@:choice(scala-3)
```scala mdoc:reset:silent
//> using toolkit typelevel:default
//> using platform native
//> using nativeVersion 0.4.15
//> using nativeVersion 0.5.11

import cats.effect.*

Expand All @@ -89,7 +89,7 @@ object Hello extends IOApp.Simple:
```scala mdoc:reset:silent
//> using toolkit typelevel:default
//> using platform native
//> using nativeVersion 0.4.17
//> using nativeVersion 0.5.11

import cats.effect._

Expand All @@ -115,7 +115,7 @@ Enumerations in your codebase, see [this comment] for more info.
[Http4s Ember Client]: https://http4s.org/v0.23/docs/client.html
[Circe]: https://circe.github.io/circe/
[Decline Effect]: https://ben.kirw.in/decline/effect.html
[Munit Cats Effect]: https://github.com/typelevel/munit-cats-effect
[Weaver Test]: https://github.com/typelevel/weaver-test

[this Enumeration method]: https://github.com/scala/scala/blob/v2.13.8/src/library/scala/Enumeration.scala#L190-L215=
[this comment]: https://github.com/typelevel/cats-effect/issues/3051#issuecomment-1167026949
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ package org.typelevel.toolkit

import cats.effect.kernel.Resource
import cats.effect.IO
import cats.syntax.parallel._
import cats.syntax.parallel.*
import buildinfo.BuildInfo
import fs2.Stream
import fs2.io.file.Files
import fs2.io.process.ProcessBuilder
import munit.Assertions.fail
import weaver.{Expectations, SourceLocation}
import weaver.Expectations.Helpers.{failure, success}

object ScalaCliProcess {

private val ClassPath: String = BuildInfo.classPath
private val JavaHome: String = BuildInfo.javaHome

private def scalaCli(args: List[String]): IO[Unit] = ProcessBuilder(
private def scalaCli(args: List[String])(implicit
loc: SourceLocation
): IO[Expectations] = ProcessBuilder(
s"$JavaHome/bin/java",
args.prependedAll(List("-cp", ClassPath, "scala.cli.ScalaCli"))
).spawn[IO]
Expand All @@ -40,7 +43,7 @@ object ScalaCliProcess {
process.stdout.through(fs2.text.utf8.decode).compile.string,
process.stderr.through(fs2.text.utf8.decode).compile.string
).parFlatMapN {
case (0, _, _) => IO.unit
case (0, _, _) => IO.pure(success)
case (exitCode, stdout, stdErr) =>
val errorMessage: String = List(
Option(stdout).filter(_.nonEmpty).map(s => s"[STDOUT]: $s"),
Expand All @@ -52,7 +55,7 @@ object ScalaCliProcess {
case (summary, None) => summary
}

IO.delay(fail(errorMessage))
IO.pure(failure(errorMessage))
}
)

Expand All @@ -79,12 +82,13 @@ object ScalaCliProcess {
}
.map(_.toString)

def command(args: List[String]): IO[Unit] = scalaCli(args)
def command(args: List[String])(implicit
loc: SourceLocation
): IO[Expectations] = scalaCli(args)

def run(body: String): IO[Unit] =
def run(body: String)(implicit loc: SourceLocation): IO[Expectations] =
writeToFile(body)(false).use(f => scalaCli("run" :: f :: Nil))

def test(body: String): IO[Unit] =
def test(body: String)(implicit loc: SourceLocation): IO[Expectations] =
writeToFile(body)(true).use(f => scalaCli("test" :: f :: Nil))

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@

package org.typelevel.toolkit

import munit.{CatsEffectSuite, TestOptions}
import cats.effect.IO
import buildinfo.BuildInfo.scala3
import scala.concurrent.duration._
import weaver.*
import scala.concurrent.duration.*

class ToolkitCompilationTest extends CatsEffectSuite {
object ToolkitCompilationTest extends SimpleIOSuite {

// 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
private val TestTimeout = 4.minutes

testRun("Toolkit should run a simple Hello Cats Effect") {
if (scala3)
Expand Down Expand Up @@ -67,26 +68,36 @@ class ToolkitCompilationTest extends CatsEffectSuite {
|}"""
}

testTest("Toolkit should execute a simple munit suite") {
testTest("Toolkit should execute a simple weaver suite") {
if (scala3)
"""|import cats.effect.*
|import munit.*
"""|import cats.effect.IO
|import weaver.*
|
|class Test extends CatsEffectSuite:
| test("test")(IO.unit)"""
|object Test extends SimpleIOSuite:
| test("test")(IO.pure(success))"""
else
"""|import cats.effect._
|import munit._
"""|import cats.effect.IO
|import weaver._
|
|class Test extends CatsEffectSuite {
| test("test")(IO.unit)
|object Test extends SimpleIOSuite {
| test("test")(IO.pure(success))
|}"""
}

def testRun(testName: TestOptions)(scriptBody: String): Unit =
test(testName)(ScalaCliProcess.run(scriptBody))
private def withTimeout(test: IO[Expectations]): IO[Expectations] =
test.timeoutTo(
TestTimeout,
IO.pure(failure(s"Test exceeded timeout of $TestTimeout"))
)
Comment thread
Hombre-x marked this conversation as resolved.

def testRun(testName: String)(scriptBody: String): Unit =
test(testName) {
withTimeout(ScalaCliProcess.run(scriptBody))
}

def testTest(testName: TestOptions)(scriptBody: String): Unit =
test(testName)(ScalaCliProcess.test(scriptBody))
def testTest(testName: String)(scriptBody: String): Unit =
test(testName) {
withTimeout(ScalaCliProcess.test(scriptBody))
}

}