-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df9cd7d
commit ba30103
Showing
7 changed files
with
127 additions
and
148 deletions.
There are no files selected for viewing
51 changes: 0 additions & 51 deletions
51
core/jvm/src/main/scala/munit/CatsEffectFixturesPlatform.scala
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
core/jvm/src/main/scala/munit/CatsEffectSuitePlatform.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
core/shared/src/main/scala/munit/catseffect/ResourceFixture.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright 2021 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 munit | ||
package catseffect | ||
|
||
import cats.effect.IO | ||
import cats.effect.Resource | ||
|
||
object ResourceFixture { | ||
|
||
final class FixtureNotInstantiatedException(name: String) | ||
extends Exception( | ||
s"The fixture `$name` was not instantiated. Override `munitFixtures` and include a reference to this fixture." | ||
) | ||
|
||
def testLocal[A](name: String, resource: Resource[IO, A]): IOFixture[A] = | ||
new IOFixture[A](name) { | ||
@volatile var value: Option[(A, IO[Unit])] = None | ||
|
||
def apply() = value match { | ||
case Some(v) => v._1 | ||
case None => throw new FixtureNotInstantiatedException(name) | ||
} | ||
|
||
override def beforeEach(context: BeforeEach) = resource.allocated.flatMap { value => | ||
IO(this.value = Some(value)) | ||
} | ||
|
||
override def afterEach(context: AfterEach) = value.fold(IO.unit)(_._2) | ||
} | ||
|
||
def suiteLocal[A](name: String, resource: Resource[IO, A]): IOFixture[A] = | ||
new IOFixture[A](name) { | ||
@volatile var value: A = _ | ||
@volatile var release: IO[Unit] = IO.unit | ||
|
||
def apply() = value | ||
|
||
override def beforeAll() = resource.allocated.flatMap { case (a, release) => | ||
IO { | ||
value = a | ||
this.release = release | ||
} | ||
} | ||
|
||
override def afterAll() = release | ||
} | ||
|
||
} | ||
|
||
abstract class IOFixture[A](name: String) extends AnyFixture[A](name: String) { | ||
|
||
override def beforeAll(): IO[Unit] = IO.unit | ||
|
||
override def beforeEach(context: BeforeEach): IO[Unit] = IO.unit | ||
|
||
override def afterEach(context: AfterEach): IO[Unit] = IO.unit | ||
|
||
override def afterAll(): IO[Unit] = IO.unit | ||
|
||
} |