-
Notifications
You must be signed in to change notification settings - Fork 75
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
6c67e4e
commit c472303
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
testing/shared/src/test/scala/org/typelevel/log4cats/extras/LogMessageTest.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,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] | ||
} | ||
} | ||
} |