Skip to content

Commit

Permalink
Add test for lazy message semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
morgen-peschke committed May 31, 2024
1 parent 6c67e4e commit c472303
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.typelevel.log4cats.extras

import cats.effect.IO
import cats.syntax.all.*

import scala.util.control.NoStackTrace

class LogMessageTest extends munit.CatsEffectSuite {
private class HaltAndCatchFire extends IllegalStateException("Oops!") with NoStackTrace

test("LogMessage.apply should preserve lazy message semantics of Logger methods") {
def haltAndCatchFire: String = throw new HaltAndCatchFire

IO.delay(LogMessage(LogLevel.Info, haltAndCatchFire, none, Map.empty))
.attemptTap { result =>
IO.delay(assert(result.isRight), clue("Should be ok here, the lazy exception shouldn't be triggered yet"))
}
.flatTap { lm =>
IO.delay(lm.lazyMessage()).intercept[HaltAndCatchFire]
}
.flatTap { lm =>
IO.delay(lm.toString).intercept[HaltAndCatchFire]
}
.flatTap { lm =>
IO.delay(lm == LogMessage(LogLevel.Info, "Ok", none, Map.empty)).intercept[HaltAndCatchFire]
}
}
}

0 comments on commit c472303

Please sign in to comment.