From 9edad2787b73b7ee98454a8874681181e0b5059c Mon Sep 17 00:00:00 2001 From: Keith Pinson Date: Mon, 13 Jul 2020 11:54:01 -0400 Subject: [PATCH 01/13] Add doobie-munit package to integrate Doobie with the shiny new MUnit MUnit is a the new Scala testing framework on the block. Seems reasonable for Doobie to support it along with the other two it already supports. I copied off `scalatest` because it is fairly similar to MUnit. Hopefully I didn't forget to change anything after the copy and paste, particularly in the documentation (the test is green, at least). --- build.sbt | 18 +++++ .../docs/src/main/mdoc/docs/06-Checking.md | 2 +- .../src/main/mdoc/docs/13-Unit-Testing.md | 24 ++++++- .../src/main/scala/doobie/munit/Checker.scala | 68 +++++++++++++++++++ .../scala/doobie/munit/CheckerTests.scala | 30 ++++++++ 5 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 modules/munit/src/main/scala/doobie/munit/Checker.scala create mode 100644 modules/munit/src/test/scala/doobie/munit/CheckerTests.scala diff --git a/build.sbt b/build.sbt index c76d95e7b..4d5606628 100644 --- a/build.sbt +++ b/build.sbt @@ -16,6 +16,7 @@ lazy val postgresVersion = "42.2.12" lazy val refinedVersion = "0.9.13" lazy val scalaCheckVersion = "1.14.2" lazy val scalatestVersion = "3.1.1" +lazy val munitVersion = "0.7.9" lazy val shapelessVersion = "2.3.3" lazy val silencerVersion = "1.6.0" lazy val sourcecodeVersion = "0.2.1" @@ -114,6 +115,7 @@ lazy val doobie = project.in(file(".")) quill, refined, scalatest, + munit, specs2, ) @@ -339,6 +341,22 @@ lazy val scalatest = project ) ) +lazy val munit = project + .in(file("modules/munit")) + .enablePlugins(AutomateHeaderPlugin) + .dependsOn(core) + .settings(doobieSettings) + .settings(publishSettings) + .settings( + name := s"doobie-munit", + description := "MUnit support for doobie.", + testFrameworks += new TestFramework("munit.Framework"), + libraryDependencies ++= Seq( + "org.scalameta" %% "munit" % munitVersion, + "com.h2database" % "h2" % h2Version % "test" + ) + ) + lazy val bench = project .in(file("modules/bench")) .enablePlugins(AutomateHeaderPlugin) diff --git a/modules/docs/src/main/mdoc/docs/06-Checking.md b/modules/docs/src/main/mdoc/docs/06-Checking.md index 5dd83f396..9ca640867 100644 --- a/modules/docs/src/main/mdoc/docs/06-Checking.md +++ b/modules/docs/src/main/mdoc/docs/06-Checking.md @@ -99,7 +99,7 @@ def biggerThan2(minPop: Int) = biggerThan2(0).check.unsafeRunSync ``` -**doobie** supports `check` for queries and updates in three ways: programmatically, via YOLO mode in the REPL, and via the `doobie-specs2` and `doobie-scalatest` packages, which allow checking to become part of your unit test suite. We will investigate this in the chapter on testing. +**doobie** supports `check` for queries and updates in four ways: programmatically, via YOLO mode in the REPL, and via the `doobie-specs2`, `doobie-scalatest` and `doobie-munit` packages, which allow checking to become part of your unit test suite. We will investigate this in the chapter on testing. ### Working Around Bad Metadata diff --git a/modules/docs/src/main/mdoc/docs/13-Unit-Testing.md b/modules/docs/src/main/mdoc/docs/13-Unit-Testing.md index afa5597ad..d4095b0e0 100644 --- a/modules/docs/src/main/mdoc/docs/13-Unit-Testing.md +++ b/modules/docs/src/main/mdoc/docs/13-Unit-Testing.md @@ -1,6 +1,6 @@ ## Unit Testing -The YOLO-mode query checking feature demonstated in an earlier chapter is also available as a trait you can mix into your [Specs2](http://etorreborre.github.io/specs2/) or [ScalaTest](http://www.scalatest.org/) unit tests. +The YOLO-mode query checking feature demonstated in an earlier chapter is also available as a trait you can mix into your [Specs2](http://etorreborre.github.io/specs2/), [ScalaTest](http://www.scalatest.org/) or [MUnit](https://scalameta.org/munit) unit tests. ### Setting Up @@ -129,3 +129,25 @@ Details are shown for failing tests. // Run a test programmatically. Usually you would do this from sbt, bloop, etc. (new AnalysisTestScalaCheck).execute(color = false) ``` + +### The MUnit Package + +The `doobie-munit` add-on provides a mix-in trait that we can add to any `Assertions` implementation (like `FunSuite`) much like the ScalaTest package above. + +```scala mdoc:silent +import munit._ + +class AnalysisTestScalaCheck extends FunSuite with doobie.munit.IOChecker { + + override val colors = doobie.util.Colors.None // just for docs + + val transactor = Transactor.fromDriverManager[IO]( + "org.postgresql.Driver", "jdbc:postgresql:world", "postgres", "" + ) + + test("trivial") { check(trivial) } + test("biggerThan") { check(biggerThan(0)) } + test("update") { check(update("", "")) } + +} +``` diff --git a/modules/munit/src/main/scala/doobie/munit/Checker.scala b/modules/munit/src/main/scala/doobie/munit/Checker.scala new file mode 100644 index 000000000..3103b8d5c --- /dev/null +++ b/modules/munit/src/main/scala/doobie/munit/Checker.scala @@ -0,0 +1,68 @@ +// Copyright (c) 2013-2020 Rob Norris and Contributors +// This software is licensed under the MIT License (MIT). +// For more information see LICENSE or https://opensource.org/licenses/MIT + +package doobie.munit + +import cats.effect.{ Effect, IO } +import doobie.util.query.{Query, Query0} +import doobie.util.testing._ +import munit.Assertions +import scala.reflect.runtime.universe.TypeTag + +/** + * Mix-in trait for specifications that enables checking of doobie `Query` and `Update` values. + * Users must provide an effect type `M` as well as a `Transactor[M]` and instances. As a + * convenience doobie provides specializations for common effect types (see other types in this + * package). + * + * {{{ + * class ExampleSpec extends FunSuite with IOChecker { + * + * // The transactor to use for the tests. + * val transactor = Transactor.fromDriverManager[IO]( + * "org.postgresql.Driver", + * "jdbc:postgresql:world", + * "postgres", "" + * ) + * + * // Now just mention the queries. Arguments are not used. + * test("findByNameAndAge") { check(MyDaoModule.findByNameAndAge(null, 0)) } + * test("allWoozles") { check(MyDaoModule.allWoozles) } + * + * } + * }}} + */ +trait Checker[M[_]] extends CheckerBase[M] { self: Assertions => + + def check[A: Analyzable](a: A) = checkImpl(Analyzable.unpack(a)) + + @SuppressWarnings(Array("org.wartremover.warts.Overloading")) + def checkOutput[A: TypeTag](q: Query0[A]) = + checkImpl(AnalysisArgs( + s"Query0[${typeName[A]}]", q.pos, q.sql, q.outputAnalysis + )) + + @SuppressWarnings(Array("org.wartremover.warts.Overloading")) + def checkOutput[A: TypeTag, B: TypeTag](q: Query[A, B]) = + checkImpl(AnalysisArgs( + s"Query[${typeName[A]}, ${typeName[B]}]", q.pos, q.sql, q.outputAnalysis + )) + + private def checkImpl(args: AnalysisArgs) = { + val report = analyzeIO(args, transactor).unsafeRunSync + if (!report.succeeded) { + fail( + formatReport(args, report, colors) + .padLeft(" ") + .toString + ) + } + } +} + +/** Implementation of Checker[IO] */ +trait IOChecker extends Checker[IO] { + self: Assertions => + val M: Effect[IO] = implicitly +} diff --git a/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala b/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala new file mode 100644 index 000000000..cb5119ca0 --- /dev/null +++ b/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala @@ -0,0 +1,30 @@ +// Copyright (c) 2013-2020 Rob Norris and Contributors +// This software is licensed under the MIT License (MIT). +// For more information see LICENSE or https://opensource.org/licenses/MIT + +package doobie.munit + +import cats.effect.{ ContextShift, IO } +import doobie.syntax.string._ +import doobie.util.transactor.Transactor +import munit._ +import scala.concurrent.ExecutionContext + +trait CheckerChecks[M[_]] extends FunSuite with Checker[M] { + + implicit def contextShift: ContextShift[M] + + lazy val transactor = Transactor.fromDriverManager[M]( + "org.h2.Driver", + "jdbc:h2:mem:queryspec;DB_CLOSE_DELAY=-1", + "sa", "" + ) + + test("trivial") { check(sql"select 1".query[Int]) } + +} + +class IOCheckerCheck extends CheckerChecks[IO] with IOChecker { + def contextShift: ContextShift[IO] = + IO.contextShift(ExecutionContext.global) +} From ff5e0ce220795849b88440155d66cfb68ae942a3 Mon Sep 17 00:00:00 2001 From: Keith Pinson Date: Mon, 13 Jul 2020 12:05:55 -0400 Subject: [PATCH 02/13] fix: header check requires the copyright to have expired to years ago --- modules/munit/src/main/scala/doobie/munit/Checker.scala | 2 +- modules/munit/src/test/scala/doobie/munit/CheckerTests.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/munit/src/main/scala/doobie/munit/Checker.scala b/modules/munit/src/main/scala/doobie/munit/Checker.scala index 3103b8d5c..e52df20d8 100644 --- a/modules/munit/src/main/scala/doobie/munit/Checker.scala +++ b/modules/munit/src/main/scala/doobie/munit/Checker.scala @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2020 Rob Norris and Contributors +// Copyright (c) 2013-2018 Rob Norris and Contributors // This software is licensed under the MIT License (MIT). // For more information see LICENSE or https://opensource.org/licenses/MIT diff --git a/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala b/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala index cb5119ca0..155af7863 100644 --- a/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala +++ b/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2020 Rob Norris and Contributors +// Copyright (c) 2013-2018 Rob Norris and Contributors // This software is licensed under the MIT License (MIT). // For more information see LICENSE or https://opensource.org/licenses/MIT From d641056b3587c18e58e6fc0c506cca0fcbba354e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez?= Date: Wed, 18 Nov 2020 18:26:45 +0100 Subject: [PATCH 03/13] Update MUnit version --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 35a846b08..cfa2079d7 100644 --- a/build.sbt +++ b/build.sbt @@ -16,7 +16,7 @@ lazy val postgresVersion = "42.2.18" lazy val refinedVersion = "0.9.18" lazy val scalaCheckVersion = "1.15.1" lazy val scalatestVersion = "3.2.3" -lazy val munitVersion = "0.7.9" +lazy val munitVersion = "0.7.18" lazy val shapelessVersion = "2.3.3" lazy val silencerVersion = "1.7.1" lazy val sourcecodeVersion = "0.2.1" From 1d96dfec91d131a857811fea5b1440c21ecf92b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez?= Date: Wed, 18 Nov 2020 18:30:11 +0100 Subject: [PATCH 04/13] Avoid `Auto-application to `()` is deprecated` error --- modules/munit/src/main/scala/doobie/munit/Checker.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/munit/src/main/scala/doobie/munit/Checker.scala b/modules/munit/src/main/scala/doobie/munit/Checker.scala index e52df20d8..503562d6e 100644 --- a/modules/munit/src/main/scala/doobie/munit/Checker.scala +++ b/modules/munit/src/main/scala/doobie/munit/Checker.scala @@ -50,7 +50,7 @@ trait Checker[M[_]] extends CheckerBase[M] { self: Assertions => )) private def checkImpl(args: AnalysisArgs) = { - val report = analyzeIO(args, transactor).unsafeRunSync + val report = analyzeIO(args, transactor).unsafeRunSync() if (!report.succeeded) { fail( formatReport(args, report, colors) From 662a4dc6f43453733ee6d9ef8efdc53d82b009a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez?= Date: Wed, 18 Nov 2020 18:31:43 +0100 Subject: [PATCH 05/13] Pass `Location` around so failure occurs at the `check` call --- modules/munit/src/main/scala/doobie/munit/Checker.scala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/munit/src/main/scala/doobie/munit/Checker.scala b/modules/munit/src/main/scala/doobie/munit/Checker.scala index 503562d6e..60435e719 100644 --- a/modules/munit/src/main/scala/doobie/munit/Checker.scala +++ b/modules/munit/src/main/scala/doobie/munit/Checker.scala @@ -9,6 +9,7 @@ import doobie.util.query.{Query, Query0} import doobie.util.testing._ import munit.Assertions import scala.reflect.runtime.universe.TypeTag +import munit.Location /** * Mix-in trait for specifications that enables checking of doobie `Query` and `Update` values. @@ -35,21 +36,21 @@ import scala.reflect.runtime.universe.TypeTag */ trait Checker[M[_]] extends CheckerBase[M] { self: Assertions => - def check[A: Analyzable](a: A) = checkImpl(Analyzable.unpack(a)) + def check[A: Analyzable](a: A)(implicit loc: Location) = checkImpl(Analyzable.unpack(a)) @SuppressWarnings(Array("org.wartremover.warts.Overloading")) - def checkOutput[A: TypeTag](q: Query0[A]) = + def checkOutput[A: TypeTag](q: Query0[A])(implicit loc: Location) = checkImpl(AnalysisArgs( s"Query0[${typeName[A]}]", q.pos, q.sql, q.outputAnalysis )) @SuppressWarnings(Array("org.wartremover.warts.Overloading")) - def checkOutput[A: TypeTag, B: TypeTag](q: Query[A, B]) = + def checkOutput[A: TypeTag, B: TypeTag](q: Query[A, B])(implicit loc: Location) = checkImpl(AnalysisArgs( s"Query[${typeName[A]}, ${typeName[B]}]", q.pos, q.sql, q.outputAnalysis )) - private def checkImpl(args: AnalysisArgs) = { + private def checkImpl(args: AnalysisArgs)(implicit loc: Location) = { val report = analyzeIO(args, transactor).unsafeRunSync() if (!report.succeeded) { fail( From 32f2de39a8cc82f221486985847755d1a8d03dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez?= Date: Wed, 18 Nov 2020 18:40:39 +0100 Subject: [PATCH 06/13] Update `setup-scala` Github Action to latest version to fix build fail --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 61970f316..4b2608d10 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up JDK 13 - uses: olafurpg/setup-scala@v2 + uses: olafurpg/setup-scala@v10 with: java-version: 13 - name: Cache SBT diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 60238186a..47c78c0d3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - uses: olafurpg/setup-scala@v2 + - uses: olafurpg/setup-scala@v10 - name: Cache SBT uses: coursier/cache-action@v3 - uses: olafurpg/setup-gpg@v2 From 357e6d47d885c37a0fd9444b84f39e0b4153323e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez?= Date: Wed, 18 Nov 2020 18:45:04 +0100 Subject: [PATCH 07/13] Re-create headers --- modules/munit/src/main/scala/doobie/munit/Checker.scala | 2 +- modules/munit/src/test/scala/doobie/munit/CheckerTests.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/munit/src/main/scala/doobie/munit/Checker.scala b/modules/munit/src/main/scala/doobie/munit/Checker.scala index 60435e719..b602c3d74 100644 --- a/modules/munit/src/main/scala/doobie/munit/Checker.scala +++ b/modules/munit/src/main/scala/doobie/munit/Checker.scala @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2018 Rob Norris and Contributors +// Copyright (c) 2013-2020 Rob Norris and Contributors // This software is licensed under the MIT License (MIT). // For more information see LICENSE or https://opensource.org/licenses/MIT diff --git a/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala b/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala index 155af7863..cb5119ca0 100644 --- a/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala +++ b/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2018 Rob Norris and Contributors +// Copyright (c) 2013-2020 Rob Norris and Contributors // This software is licensed under the MIT License (MIT). // For more information see LICENSE or https://opensource.org/licenses/MIT From 229e833cb16e8859da159eb51ddae3a121ba4320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez?= Date: Thu, 28 Jan 2021 09:50:30 +0100 Subject: [PATCH 08/13] Conform `doobie-munit` with `doobie-specs2` --- .../src/main/scala/doobie/munit/Checker.scala | 69 ------------------- .../scala/doobie/munit/analysisspec.scala | 67 ++++++++++++++++++ .../src/main/scala/doobie/munit/package.scala | 12 ++++ 3 files changed, 79 insertions(+), 69 deletions(-) delete mode 100644 modules/munit/src/main/scala/doobie/munit/Checker.scala create mode 100644 modules/munit/src/main/scala/doobie/munit/analysisspec.scala create mode 100644 modules/munit/src/main/scala/doobie/munit/package.scala diff --git a/modules/munit/src/main/scala/doobie/munit/Checker.scala b/modules/munit/src/main/scala/doobie/munit/Checker.scala deleted file mode 100644 index b602c3d74..000000000 --- a/modules/munit/src/main/scala/doobie/munit/Checker.scala +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2013-2020 Rob Norris and Contributors -// This software is licensed under the MIT License (MIT). -// For more information see LICENSE or https://opensource.org/licenses/MIT - -package doobie.munit - -import cats.effect.{ Effect, IO } -import doobie.util.query.{Query, Query0} -import doobie.util.testing._ -import munit.Assertions -import scala.reflect.runtime.universe.TypeTag -import munit.Location - -/** - * Mix-in trait for specifications that enables checking of doobie `Query` and `Update` values. - * Users must provide an effect type `M` as well as a `Transactor[M]` and instances. As a - * convenience doobie provides specializations for common effect types (see other types in this - * package). - * - * {{{ - * class ExampleSpec extends FunSuite with IOChecker { - * - * // The transactor to use for the tests. - * val transactor = Transactor.fromDriverManager[IO]( - * "org.postgresql.Driver", - * "jdbc:postgresql:world", - * "postgres", "" - * ) - * - * // Now just mention the queries. Arguments are not used. - * test("findByNameAndAge") { check(MyDaoModule.findByNameAndAge(null, 0)) } - * test("allWoozles") { check(MyDaoModule.allWoozles) } - * - * } - * }}} - */ -trait Checker[M[_]] extends CheckerBase[M] { self: Assertions => - - def check[A: Analyzable](a: A)(implicit loc: Location) = checkImpl(Analyzable.unpack(a)) - - @SuppressWarnings(Array("org.wartremover.warts.Overloading")) - def checkOutput[A: TypeTag](q: Query0[A])(implicit loc: Location) = - checkImpl(AnalysisArgs( - s"Query0[${typeName[A]}]", q.pos, q.sql, q.outputAnalysis - )) - - @SuppressWarnings(Array("org.wartremover.warts.Overloading")) - def checkOutput[A: TypeTag, B: TypeTag](q: Query[A, B])(implicit loc: Location) = - checkImpl(AnalysisArgs( - s"Query[${typeName[A]}, ${typeName[B]}]", q.pos, q.sql, q.outputAnalysis - )) - - private def checkImpl(args: AnalysisArgs)(implicit loc: Location) = { - val report = analyzeIO(args, transactor).unsafeRunSync() - if (!report.succeeded) { - fail( - formatReport(args, report, colors) - .padLeft(" ") - .toString - ) - } - } -} - -/** Implementation of Checker[IO] */ -trait IOChecker extends Checker[IO] { - self: Assertions => - val M: Effect[IO] = implicitly -} diff --git a/modules/munit/src/main/scala/doobie/munit/analysisspec.scala b/modules/munit/src/main/scala/doobie/munit/analysisspec.scala new file mode 100644 index 000000000..5a68e8b4c --- /dev/null +++ b/modules/munit/src/main/scala/doobie/munit/analysisspec.scala @@ -0,0 +1,67 @@ +// Copyright (c) 2013-2020 Rob Norris and Contributors +// This software is licensed under the MIT License (MIT). +// For more information see LICENSE or https://opensource.org/licenses/MIT + +package doobie.munit + +import cats.effect.{ Effect, IO } +import doobie.util.query.{Query, Query0} +import doobie.util.testing._ +import org.tpolecat.typename._ +import munit.Assertions +import munit.Location + +/** + * Module with a mix-in trait for specifications that enables checking of doobie `Query` and `Update` values. + * + * {{{ + * class ExampleSuite extends FunSuite with IOChecker { + * + * // The transactor to use for the tests. + * val transactor = Transactor.fromDriverManager[IO]( + * "org.postgresql.Driver", + * "jdbc:postgresql:world", + * "postgres", "" + * ) + * + * // Now just mention the queries. Arguments are not used. + * test("findByNameAndAge") { check(MyDaoModule.findByNameAndAge(null, 0)) } + * test("allWoozles") { check(MyDaoModule.allWoozles) } + * + * } + * }}} + */ +object analysisspec { + + trait Checker[M[_]] extends CheckerBase[M] { this: Assertions => + + def check[A: Analyzable](a: A)(implicit loc: Location) = checkImpl(Analyzable.unpack(a)) + + def checkOutput[A: TypeName](q: Query0[A])(implicit loc: Location) = + checkImpl(AnalysisArgs( + s"Query0[${typeName[A]}]", q.pos, q.sql, q.outputAnalysis + )) + + def checkOutput[A: TypeName, B: TypeName](q: Query[A, B])(implicit loc: Location) = + checkImpl(AnalysisArgs( + s"Query[${typeName[A]}, ${typeName[B]}]", q.pos, q.sql, q.outputAnalysis + )) + + private def checkImpl(args: AnalysisArgs)(implicit loc: Location) = { + val report = analyzeIO(args, transactor).unsafeRunSync() + if (!report.succeeded) { + fail( + formatReport(args, report, colors) + .padLeft(" ") + .toString + ) + } + } + } + + /** Implementation of Checker[IO] */ + trait IOChecker extends Checker[IO] { + self: Assertions => + val M: Effect[IO] = implicitly + } +} diff --git a/modules/munit/src/main/scala/doobie/munit/package.scala b/modules/munit/src/main/scala/doobie/munit/package.scala new file mode 100644 index 000000000..913be7c61 --- /dev/null +++ b/modules/munit/src/main/scala/doobie/munit/package.scala @@ -0,0 +1,12 @@ +// Copyright (c) 2013-2020 Rob Norris and Contributors +// This software is licensed under the MIT License (MIT). +// For more information see LICENSE or https://opensource.org/licenses/MIT + +package doobie + +package object munit { + + type Checker[M[_]] = analysisspec.Checker[M] + type IOChecker = analysisspec.IOChecker + +} From 56938930b51c5822113101665d3fc4b9c4886655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez?= Date: Thu, 28 Jan 2021 10:25:13 +0100 Subject: [PATCH 09/13] Update MUnit version so it works in Scala 3 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 4caafd3ef..becf2199a 100644 --- a/build.sbt +++ b/build.sbt @@ -17,7 +17,7 @@ lazy val postgresVersion = "42.2.18" lazy val refinedVersion = "0.9.19" lazy val scalaCheckVersion = "1.15.1" lazy val scalatestVersion = "3.2.3" -lazy val munitVersion = "0.7.18" +lazy val munitVersion = "0.7.21" lazy val silencerVersion = "1.7.1" lazy val specs2Version = "4.10.6" lazy val scala212Version = "2.12.12" From 991b1fd231cb1074b279f968e199851bc171b334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez?= Date: Thu, 28 Jan 2021 11:16:02 +0100 Subject: [PATCH 10/13] `docs` should depend on `munit` --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index becf2199a..f7f73fe1d 100644 --- a/build.sbt +++ b/build.sbt @@ -418,7 +418,7 @@ lazy val bench = project lazy val docs = project .in(file("modules/docs")) - .dependsOn(core, postgres, specs2, hikari, h2, scalatest, quill) + .dependsOn(core, postgres, specs2, munit, hikari, h2, scalatest, quill) .enablePlugins(ParadoxPlugin) .enablePlugins(ParadoxSitePlugin) .enablePlugins(GhpagesPlugin) From f89be9b53dbb239a82565e42222c7c41c73e1874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez?= Date: Thu, 28 Jan 2021 13:13:34 +0100 Subject: [PATCH 11/13] `munit` package has to be imported as `_root_.munit` --- modules/docs/src/main/mdoc/docs/13-Unit-Testing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/docs/src/main/mdoc/docs/13-Unit-Testing.md b/modules/docs/src/main/mdoc/docs/13-Unit-Testing.md index d4095b0e0..2c7daee76 100644 --- a/modules/docs/src/main/mdoc/docs/13-Unit-Testing.md +++ b/modules/docs/src/main/mdoc/docs/13-Unit-Testing.md @@ -135,9 +135,9 @@ Details are shown for failing tests. The `doobie-munit` add-on provides a mix-in trait that we can add to any `Assertions` implementation (like `FunSuite`) much like the ScalaTest package above. ```scala mdoc:silent -import munit._ +import _root_.munit._ -class AnalysisTestScalaCheck extends FunSuite with doobie.munit.IOChecker { +class AnalysisTestSuite extends FunSuite with doobie.munit.IOChecker { override val colors = doobie.util.Colors.None // just for docs From 539e1da3896193400ddfdaf458130c27eeea9b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez?= Date: Sat, 13 Feb 2021 13:20:08 +0100 Subject: [PATCH 12/13] Add failing assertion and conform with specs2 tests --- .../munit/src/test/scala/doobie/munit/CheckerTests.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala b/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala index cb5119ca0..7ba145aa0 100644 --- a/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala +++ b/modules/munit/src/test/scala/doobie/munit/CheckerTests.scala @@ -21,6 +21,12 @@ trait CheckerChecks[M[_]] extends FunSuite with Checker[M] { ) test("trivial") { check(sql"select 1".query[Int]) } + + test("fail".fail) { check(sql"select 1".query[String]) } + + final case class Foo[F[_]](x: Int) + + test ("trivial case-class"){ check(sql"select 1".query[Foo[cats.Id]]) } } From 4b3b84bfd336592e213d88ed0701b167205e6188 Mon Sep 17 00:00:00 2001 From: Keith Pinson <3661051+Kazark@users.noreply.github.com> Date: Fri, 21 May 2021 09:05:37 -0400 Subject: [PATCH 13/13] Update build.sbt --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 0f48fa32d..2af6f63f5 100644 --- a/build.sbt +++ b/build.sbt @@ -16,7 +16,7 @@ lazy val postgresVersion = "42.2.20" lazy val refinedVersion = "0.9.25" lazy val scalaCheckVersion = "1.15.4" lazy val scalatestVersion = "3.2.9" -lazy val munitVersion = "0.7.23" +lazy val munitVersion = "0.7.26" lazy val shapelessVersion = "2.3.7" lazy val silencerVersion = "1.7.1" lazy val specs2Version = "4.11.0"