Skip to content

Commit

Permalink
Remove unused BioAssertions
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyhappydan committed Nov 9, 2023
1 parent 538413e commit 9239905
Showing 1 changed file with 0 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,11 @@ import monix.bio.{IO, UIO}
import munit.{Assertions, Location}

import java.io.{ByteArrayOutputStream, PrintStream}
import scala.concurrent.duration.FiniteDuration
import scala.reflect.ClassTag
import scala.util.control.NonFatal

trait BioAssertions { self: Assertions =>

def assertUIO[A](io: UIO[A], cond: A => Boolean, clue: => Any = "assertion failed")(implicit
loc: Location
): UIO[Unit] = {
io.map(result => assert(cond(result), clue))
}

def assertEqualsIO[E, A, B](
obtained: IO[E, A],
returns: B,
clue: => Any = "values are not the same"
)(implicit loc: Location, ev: B <:< A): IO[E, Unit] =
obtained.flatMap(a => UIO(assertEquals(a, returns, clue)))

def assertError[E, A](obtained: IO[E, A], condition: E => Boolean, clue: E => Any = (_: E) => "assertion failed")(
implicit loc: Location
): IO[E, Unit] = {
obtained.attempt.map {
case Left(err) => Assertions.assert(condition(err), clue(err))
case Right(a) =>
fail(
s"Expected a raised error, but returned successful response: $a"
)
}
}

implicit class UioAssertionsOps[A](uio: UIO[A])(implicit loc: Location) {
def assert(expected: A, clue: Any = "values are not the same"): UIO[Unit] =
uio.map(assertEquals(_, expected, clue))

def assert(expected: A, timeout: FiniteDuration): UIO[Unit] =
uio.timeout(timeout).assertSome(expected)
}

implicit class IoAssertionsOps[E, A](io: IO[E, A])(implicit E: ClassTag[E], loc: Location) {

private def exceptionHandler(err: Throwable) = {
Expand Down Expand Up @@ -73,23 +39,6 @@ trait BioAssertions { self: Assertions =>
a => assertEquals(a, expected, clue)
)

def assert(expected: A, timeout: FiniteDuration): UIO[Unit] =
io.timeout(timeout).assertSome(expected)

def assertError(condition: E => Boolean, clue: => Any = "assertion failed")(implicit loc: Location): UIO[Unit] = {
io.attempt.map {
case Left(E(err)) => Assertions.assert(condition(err), clue)
case Left(err) =>
fail(
s"Wrong raised error type caught, expected: '${E.runtimeClass.getName}', actual: '${err.getClass.getName}'"
)
case Right(a) =>
fail(
s"Expected a raised error, but returned successful response: $a"
)
}
}

def error(expected: E): UIO[Unit] = io.attempt.map {
case Left(E(err)) => assertEquals(err, expected)
case Left(err) =>
Expand All @@ -102,25 +51,6 @@ trait BioAssertions { self: Assertions =>
)
}

def terminated[T <: Throwable](implicit T: ClassTag[T]): UIO[Unit] =
io.redeemCause(
{
case Error(err) =>
fail(
s"Wrong raised error type caught, expected terminal: '${T.runtimeClass.getName}', actual typed: '${err.getClass.getName}'"
)
case Termination(T(_)) => ()
case Termination(t) =>
fail(
s"Wrong raised error type caught, expected terminal: '${T.runtimeClass.getName}', actual terminal: '${t.getClass.getName}'"
)
},
a =>
fail(
s"Expected raising error, but returned successful response with type '${a.getClass.getName}'"
)
)

def terminated[T <: Throwable](expectedMessage: String)(implicit T: ClassTag[T]): UIO[Unit] =
io.redeemCause(
{
Expand Down

0 comments on commit 9239905

Please sign in to comment.