Skip to content

Commit

Permalink
Port to CE3 (#336)
Browse files Browse the repository at this point in the history
* adding VSCode+bloop toolchain to .gitignore

* port to CE3

* polishing up build aliases
  • Loading branch information
sirocchj authored May 13, 2021
1 parent 22ba156 commit 97f7ad8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 39 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ project/target
project/project/*
!project/project/plugins.sbt

# Metals + Bloop
.metals/
metals.sbt
.bloop/
.bsp/
.vscode/

# IDEA specific
.idea

Expand Down
26 changes: 8 additions & 18 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ lazy val scala_213 = "2.13.5"

lazy val versionOf = new {
val cats = "2.6.0"
val catsEffect = "2.5.0"
val fs2 = "2.5.5"
val catsEffect = "3.1.0"
val fs2 = "3.0.2"
val kindProjector = "0.11.3"
val log4cats = "1.3.0"
val log4cats = "2.1.0"
val log4s = "1.9.0"
val scalaCheck = "1.15.4"
val scalaTest = "3.2.8"
Expand Down Expand Up @@ -139,25 +139,15 @@ lazy val root = project
.settings(
name := "log-effect",
publishArtifact := false,
addCommandAlias("fmt", ";scalafmt;test:scalafmt;scalafmtSbt"),
addCommandAlias(
"checkFormat",
";scalafmtCheck;test:scalafmtCheck;scalafmtSbtCheck"
),
addCommandAlias(
"ciBuild",
";clean;test"
),
addCommandAlias(
"fullBuild",
";checkFormat;ciBuild"
),
// travis release aliases
addCommandAlias("fmt", "scalafmt;Test/scalafmt;scalafmtSbt"),
addCommandAlias("checkFormat", "scalafmtCheck;Test/scalafmtCheck;scalafmtSbtCheck"),
addCommandAlias("ciBuild", "clean;test"),
addCommandAlias("fullBuild", "checkFormat;ciBuild"),
addCommandAlias(
"setReleaseOptions",
"set scalacOptions ++= Seq(\"-opt:l:method\", \"-opt:l:inline\", \"-opt-inline-from:laserdisc.**\", \"-opt-inline-from:<sources>\")"
),
addCommandAlias("releaseIt", ";clean;setReleaseOptions;session list;compile;ci-release")
addCommandAlias("releaseIt", "clean;setReleaseOptions;session list;compile;ci-release")
)

lazy val core = project
Expand Down
18 changes: 9 additions & 9 deletions fs2/src/test/scala/ReadmeLogSubmissionCodeSnippetsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.scalatest.wordspec.AnyWordSpecLike
"`in a streaming environment using `LogWriter`'s syntax` snippet should compile" in {
import java.nio.channels.AsynchronousChannelGroup

import cats.effect.{ConcurrentEffect, ContextShift, Timer}
import cats.effect.Async
import cats.syntax.flatMap._
import log.effect.LogWriter

Expand All @@ -40,18 +40,18 @@ import org.scalatest.wordspec.AnyWordSpecLike
implicit def EC: ExecutionContext = ???
implicit def CG: AsynchronousChannelGroup = ???

def redisClient[F[_]: ConcurrentEffect: ContextShift: Timer](
def redisClient[F[_]: Async](
address: String
)(implicit log: LogWriter[F]): fs2.Stream[F, RedisClient[F]] =
RedisClient[F](address) evalMap { client =>
log.info(s"Laserdisc Redis client for $address") >> ConcurrentEffect[F].pure(client)
log.info(s"Laserdisc Redis client for $address") >> Async[F].pure(client)
}
}

"`in a streaming environment using `fs2` streams' syntax` snippet should compile" in {
import java.nio.channels.AsynchronousChannelGroup

import cats.effect.{ConcurrentEffect, ContextShift, Timer}
import cats.effect.Async
import log.effect.LogWriter
import log.effect.fs2.syntax._

Expand All @@ -68,7 +68,7 @@ import org.scalatest.wordspec.AnyWordSpecLike
implicit def EC: ExecutionContext = ???
implicit def CG: AsynchronousChannelGroup = ???

def redisCache[F[_]: ConcurrentEffect: ContextShift: Timer](
def redisCache[F[_]: Async](
address: String
)(implicit log: LogWriter[F]): fs2.Stream[F, RedisClient[F]] =
for {
Expand Down Expand Up @@ -119,7 +119,7 @@ import org.scalatest.wordspec.AnyWordSpecLike
import java.nio.channels.AsynchronousChannelGroup

import cats.Show
import cats.effect.{ConcurrentEffect, ContextShift, Timer}
import cats.effect.Async
import cats.instances.string._
import cats.syntax.either._
import cats.syntax.flatMap._
Expand All @@ -142,7 +142,7 @@ import org.scalatest.wordspec.AnyWordSpecLike
implicit def EC: ExecutionContext = ???
implicit def CG: AsynchronousChannelGroup = ???

def redisClient[F[_]: ConcurrentEffect: ContextShift: Timer: LogWriter](
def redisClient[F[_]: Async: LogWriter](
address: String
): fs2.Stream[F, Throwable | RedisClient[F]] = {
// Cats Show instances are needed for every logged type
Expand All @@ -152,13 +152,13 @@ import org.scalatest.wordspec.AnyWordSpecLike
LogWriter.write(Debug, "Connected client details:") >> // Or
LogWriter.debug(address) >> // And
LogWriter.debug(client) >>
ConcurrentEffect[F].pure(client.asRight)
Async[F].pure(client.asRight)
} handleErrorWith { th =>
fs2.Stream eval (
LogWriter.write(
Error,
Failure("Ops, something didn't work", th)
) >> ConcurrentEffect[F].pure(th.asLeft)
) >> Async[F].pure(th.asLeft)
)
}
}
Expand Down
1 change: 1 addition & 0 deletions fs2/src/test/scala/log/effect/fs2/TestLogCapture.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package fs2
import java.io.{ByteArrayOutputStream, PrintStream}

import cats.effect.IO
import cats.effect.unsafe.implicits.global

trait TestLogCapture {

Expand Down
4 changes: 2 additions & 2 deletions interop/src/test/scala/InteropTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class InteropTest extends AnyWordSpecLike with Matchers with TestLogCaptur

"A LogWriter instance can be derived from a log4cats Logger" in {
import cats.effect.IO
import cats.syntax.flatMap._
import cats.effect.unsafe.implicits.global
import org.typelevel.log4cats.slf4j.Slf4jLogger
import log.effect.LogWriter
import log.effect.internal.Show
Expand All @@ -21,7 +21,7 @@ final class InteropTest extends AnyWordSpecLike with Matchers with TestLogCaptur
}
}

val logged = capturedLog4sOutOf[IO] { logger =>
val logged = capturedLog4sOutOf { logger =>
import log.effect.interop.log4cats._

implicit val buildMessageLogger =
Expand Down
19 changes: 9 additions & 10 deletions interop/src/test/scala/log/effect/interop/TestLogCapture.scala
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package log.effect
package interop

import cats.effect.{Effect, Sync}
import cats.effect.IO
import cats.effect.unsafe.implicits.global
import cats.syntax.flatMap._
import org.log4s.{LoggedEvent, TestAppender, getLogger}
import org.slf4j.Logger

trait TestLogCapture {

protected final def capturedLog4sOutOf[F[_]: Effect](
logWrite: Logger => F[Unit]
protected final def capturedLog4sOutOf(
logWrite: Logger => IO[Unit]
): Seq[LoggedEvent] = {
val loggingAction: F[Unit] =
Sync[F].delay(getLogger("Test Logger").logger) >>= { logger =>
TestAppender.withAppender() {
logWrite(logger)
}
val loggingAction = IO.delay(getLogger("Test Logger").logger) >>= { logger =>
TestAppender.withAppender() {
logWrite(logger)
}

Effect[F].toIO(loggingAction).unsafeRunSync()
}
loggingAction.unsafeRunSync()

TestAppender.dequeueAll()
}
Expand Down

0 comments on commit 97f7ad8

Please sign in to comment.