Skip to content

Commit

Permalink
Merge pull request #593 from lolgab/fix-tests-js-native
Browse files Browse the repository at this point in the history
Fix dependencies to be platformed and fix newly enabled tests
  • Loading branch information
darkfrog26 authored Jun 4, 2024
2 parents bc7bdea + e105088 commit 5e6705f
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 98 deletions.
97 changes: 43 additions & 54 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ val slf4j2Version: String = "2.0.13"
val profigVersion: String = "3.4.1"

// Slack and Logstash Dependencies
val spiceVersion: String = "0.5.8"
val spiceVersion: String = "0.5.9"

// Benchmarking Dependencies
val log4jVersion: String = "2.23.1"
Expand Down Expand Up @@ -100,11 +100,11 @@ val sourceMapSettings = List(

lazy val root = project.in(file("."))
.aggregate(
coreJS, coreJVM, coreNative,
// TODO: Re-enable catsNative when cats-effect supports ScalaNative 0.5
catsJS, catsJVM, //catsNative,
fileJVM, fileNative,
jsonJS, jsonJVM, jsonFabricJS, jsonFabricJVM, jsonCirceJS, jsonCirceJVM,
core.js, core.jvm, core.native,
// TODO: Re-enable cats.native when cats-effect supports ScalaNative 0.5
cats.js, cats.jvm, //cats.native,
fileModule.jvm, fileModule.native,
json.js, json.jvm, jsonFabric.js, jsonFabric.jvm, jsonCirce.js, jsonCirce.jvm,
slf4j, slf4j2, log4j, migration, config, slack, logstash
)
.settings(
Expand All @@ -120,7 +120,7 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
libraryDependencies ++= Seq(
"com.outr" %%% "perfolation" % perfolationVersion,
"com.lihaoyi" %%% "sourcecode" % sourcecodeVersion,
"org.scalatest" %% "scalatest" % scalaTestVersion % Test
"org.scalatest" %%% "scalatest" % scalaTestVersion % Test
),
libraryDependencies ++= (
if (scalaVersion.value.startsWith("2.12.")) {
Expand All @@ -134,13 +134,18 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
)
.jvmSettings(
libraryDependencies ++= Seq(
"com.outr" %% "moduload" % moduloadVersion
"com.outr" %%% "moduload" % moduloadVersion
)
)

lazy val coreJS = core.js
lazy val coreJVM = core.jvm
lazy val coreNative = core.native
.jsSettings(
libraryDependencies ++= Seq(
"io.github.cquiroz" %%% "scala-java-time" % "2.5.0" % Test,
"io.github.cquiroz" %%% "scala-java-time-tzdb" % "2.5.0" % Test
)
)
.nativeSettings(
coverageEnabled := false
)

lazy val cats = crossProject(JVMPlatform, JSPlatform) //, NativePlatform)
.crossType(CrossType.Full)
Expand All @@ -149,8 +154,8 @@ lazy val cats = crossProject(JVMPlatform, JSPlatform) //, NativePlatform)
crossScalaVersions := allScalaVersions,
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-effect" % catsEffectVersion,
"org.scalatest" %% "scalatest" % scalaTestVersion % Test,
"org.typelevel" %% "cats-effect-testing-scalatest" % catsEffectTestingVersion % "test"
"org.scalatest" %%% "scalatest" % scalaTestVersion % Test,
"org.typelevel" %%% "cats-effect-testing-scalatest" % catsEffectTestingVersion % "test"
),
libraryDependencies ++= (
if (scalaVersion.value.startsWith("2.12.")) {
Expand All @@ -163,16 +168,12 @@ lazy val cats = crossProject(JVMPlatform, JSPlatform) //, NativePlatform)
)
.dependsOn(core)

lazy val catsJS = cats.js
lazy val catsJVM = cats.jvm
//lazy val catsNative = cats.native

lazy val fileModule = crossProject(JVMPlatform, NativePlatform)
.crossType(CrossType.Full)
.settings(
name := "scribe-file",
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % scalaTestVersion % Test
"org.scalatest" %%% "scalatest" % scalaTestVersion % Test
),
crossScalaVersions := allScalaVersions
)
Expand All @@ -184,99 +185,87 @@ lazy val fileModule = crossProject(JVMPlatform, NativePlatform)
)
.dependsOn(core)

lazy val fileJVM = fileModule.jvm
lazy val fileNative = fileModule.native

lazy val json = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
.settings(
name := "scribe-json",
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % scalaTestVersion % Test
"org.scalatest" %%% "scalatest" % scalaTestVersion % Test
),
crossScalaVersions := allScalaVersions
)
.dependsOn(core)

lazy val jsonJS = json.js
lazy val jsonJVM = json.jvm

lazy val jsonFabric = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
.settings(
name := "scribe-json-fabric",
libraryDependencies ++= Seq(
"org.typelevel" %%% "fabric-io" % fabricVersion,
"org.scalatest" %% "scalatest" % scalaTestVersion % Test
"org.scalatest" %%% "scalatest" % scalaTestVersion % Test
),
crossScalaVersions := allScalaVersions
)
.dependsOn(json)

lazy val jsonFabricJS = jsonFabric.js
lazy val jsonFabricJVM = jsonFabric.jvm

lazy val jsonCirce = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
.settings(
name := "scribe-json-circe",
libraryDependencies ++= Seq(
"io.circe" %% "circe-core" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion,
"io.circe" %% "circe-generic" % circeVersion,
"org.scalatest" %% "scalatest" % scalaTestVersion % Test
"io.circe" %%% "circe-core" % circeVersion,
"io.circe" %%% "circe-parser" % circeVersion,
"io.circe" %%% "circe-generic" % circeVersion,
"org.scalatest" %%% "scalatest" % scalaTestVersion % Test
),
crossScalaVersions := allScalaVersions
)
.dependsOn(json)

lazy val jsonCirceJS = jsonCirce.js
lazy val jsonCirceJVM = jsonCirce.jvm

lazy val slf4j = project.in(file("slf4j"))
.dependsOn(coreJVM)
.dependsOn(core.jvm)
.settings(
name := "scribe-slf4j",
Test / publishArtifact := false,
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.scalatest" %% "scalatest" % scalaTestVersion % Test
"org.scalatest" %%% "scalatest" % scalaTestVersion % Test
),
crossScalaVersions := allScalaVersions
)

lazy val slf4j2 = project.in(file("slf4j2"))
.dependsOn(coreJVM)
.dependsOn(core.jvm)
.settings(
name := "scribe-slf4j2",
Test / publishArtifact := false,
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % slf4j2Version,
"org.scalatest" %% "scalatest" % scalaTestVersion % Test
"org.scalatest" %%% "scalatest" % scalaTestVersion % Test
),
crossScalaVersions := allScalaVersions
)

lazy val log4j = project.in(file("log4j"))
.dependsOn(coreJVM)
.dependsOn(core.jvm)
.settings(
name := "scribe-log4j",
Test / publishArtifact := false,
libraryDependencies ++= Seq(
"org.apache.logging.log4j" % "log4j-api" % log4jVersion,
"org.apache.logging.log4j" % "log4j-core" % log4jVersion,
"org.scalatest" %% "scalatest" % scalaTestVersion % Test
"org.scalatest" %%% "scalatest" % scalaTestVersion % Test
),
crossScalaVersions := allScalaVersions
)

lazy val migration = project.in(file("migration"))
.dependsOn(coreJVM)
.dependsOn(core.jvm)
.settings(
name := "scribe-migration",
Test / publishArtifact := false,
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % scalaTestVersion % Test
"org.scalatest" %%% "scalatest" % scalaTestVersion % Test
),
crossScalaVersions := allScalaVersions
)
Expand All @@ -287,8 +276,8 @@ lazy val config = project.in(file("config"))
name := "scribe-config",
Test / publishArtifact := false,
libraryDependencies ++= Seq(
"com.outr" %% "profig" % profigVersion,
"org.scalatest" %% "scalatest" % scalaTestVersion % Test
"com.outr" %%% "profig" % profigVersion,
"org.scalatest" %%% "scalatest" % scalaTestVersion % Test
),
crossScalaVersions := allScalaVersions
)
Expand All @@ -301,7 +290,7 @@ lazy val slack = project.in(file("slack"))
"com.outr" %% "spice-client-okhttp" % spiceVersion
)
)
.dependsOn(coreJVM)
.dependsOn(core.jvm)

lazy val logstash = project.in(file("logstash"))
.settings(
Expand All @@ -311,10 +300,10 @@ lazy val logstash = project.in(file("logstash"))
"com.outr" %% "spice-client-okhttp" % spiceVersion
)
)
.dependsOn(coreJVM)
.dependsOn(core.jvm)

lazy val benchmarks = project.in(file("benchmarks"))
.dependsOn(fileJVM, catsJVM)
.dependsOn(fileModule.jvm, cats.jvm)
.enablePlugins(JmhPlugin)
.settings(
fork := true,
Expand All @@ -325,11 +314,11 @@ lazy val benchmarks = project.in(file("benchmarks"))
"com.lmax" % "disruptor" % disruptorVersion,
"ch.qos.logback" % "logback-classic" % logbackVersion,
"com.typesafe" % "config" % typesafeConfigVersion,
"com.typesafe.scala-logging" %% "scala-logging" % scalaLoggingVersion,
"com.typesafe.scala-logging" %%% "scala-logging" % scalaLoggingVersion,
"org.tinylog" % "tinylog" % tinyLogVersion,
"org.log4s" %% "log4s" % log4sVersion,
"org.typelevel" %% "log4cats-slf4j" % log4catsVersion,
"co.fs2" %% "fs2-core" % fs2Version
"org.log4s" %%% "log4s" % log4sVersion,
"org.typelevel" %%% "log4cats-slf4j" % log4catsVersion,
"co.fs2" %%% "fs2-core" % fs2Version
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,18 +457,22 @@ class LoggingSpec extends AnyWordSpec with Matchers with Logging {
writer.output.map(_.plainText) should be(List("error"))
}
"use HTMLOutputFormat to log something" in {
val MomentInTime = 1606235160799L
Time.contextualize(MomentInTime) {
val b = new StringBuilder
val writer = new Writer {
override def write(record: LogRecord, output: LogOutput, outputFormat: OutputFormat): Unit = {
outputFormat(output, b.append(_))
sys.props("java.vm.name") match {
case "Scala.js" | "Scala Native" =>
case _ =>
val MomentInTime = 1606235160799L
Time.contextualize(MomentInTime) {
val b = new StringBuilder
val writer = new Writer {
override def write(record: LogRecord, output: LogOutput, outputFormat: OutputFormat): Unit = {
outputFormat(output, b.append(_))
}
}
val logger = Logger().orphan().withHandler(writer = writer, outputFormat = HTMLOutputFormat())
Thread.currentThread().setName("test-thread")
logger.info("Hello, HTML!")
b.toString() should be("""<div class="record"><span style="color: cyan"><strong>2020.11.24&#160;10:26:00:799</strong></span>&#160;<em>test-thread</em>&#160;<span style="color: blue">INFO</span>&#160;<span style="color: green">specs.LoggingSpec.LoggingSpec:473</span><br/>&#160;&#160;&#160;&#160;Hello,&#160;HTML!&#160;&#160;&#160;&#160;</div>""")
}
}
val logger = Logger().orphan().withHandler(writer = writer, outputFormat = HTMLOutputFormat())
Thread.currentThread().setName("test-thread")
logger.info("Hello, HTML!")
b.toString() should be("""<div class="record"><span style="color: cyan"><strong>2020.11.24&#160;10:26:00:799</strong></span>&#160;<em>test-thread</em>&#160;<span style="color: blue">INFO</span>&#160;<span style="color: green">specs.LoggingSpec.LoggingSpec:470</span><br/>&#160;&#160;&#160;&#160;Hello,&#160;HTML!&#160;&#160;&#160;&#160;</div>""")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package spec
package specs

import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
Expand Down
47 changes: 47 additions & 0 deletions core/jvm/src/test/scala/specs/MDCThreadSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package specs

import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import scribe.Logger
import scribe.mdc._
import scribe.writer.CacheWriter

class MDCThreadSpec extends AnyWordSpec with Matchers {
private lazy val writer = new CacheWriter
private lazy val logger = Logger("mdc-test").orphan().withHandler(writer = writer)

"MDC" should {
"verify concurrency access to implicits" in {
implicit val mdc: MDC = MDC.instance
logger.info("Zero")
mdc.context("test" -> "testing") {
logger.info("One")
mdc.context("test" -> "testing2") {
logger.info("Two")
var finished = false
new Thread {
override def run(): Unit = {
logger.info("Three")
finished = true
}
}.start()
while (!finished) {
Thread.sleep(10)
}
}
logger.info("Four")
}
logger.info("Five")
writer.consume { list =>
list.map(r => r.messages.head.logOutput.plainText -> r.data.get("test").map(_())) should be(List(
"Five" -> None,
"Four" -> Some("testing"),
"Three" -> Some("testing2"),
"Two" -> Some("testing2"),
"One" -> Some("testing"),
"Zero" -> None
))
}
}
}
}
32 changes: 0 additions & 32 deletions core/shared/src/test/scala/specs/MDCSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,5 @@ class MDCSpec extends AnyWordSpec with Matchers {
))
}
}
"verify concurrency access to implicits" in {
implicit val mdc: MDC = MDC.instance
logger.info("Zero")
mdc.context("test" -> "testing") {
logger.info("One")
mdc.context("test" -> "testing2") {
logger.info("Two")
var finished = false
new Thread {
override def run(): Unit = {
logger.info("Three")
finished = true
}
}.start()
while (!finished) {
Thread.sleep(10)
}
}
logger.info("Four")
}
logger.info("Five")
writer.consume { list =>
list.map(r => r.messages.head.logOutput.plainText -> r.data.get("test").map(_())) should be(List(
"Five" -> None,
"Four" -> Some("testing"),
"Three" -> Some("testing2"),
"Two" -> Some("testing2"),
"One" -> Some("testing"),
"Zero" -> None
))
}
}
}
}

0 comments on commit 5e6705f

Please sign in to comment.