Skip to content

Commit

Permalink
#1 - Added scala test
Browse files Browse the repository at this point in the history
  • Loading branch information
blondacz committed Apr 23, 2023
1 parent 25e3204 commit 3ee403f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
build/
.gradle/
.idea/
5 changes: 4 additions & 1 deletion lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
plugins {
scala
`java-library`
id("com.github.maiflai.scalatest") version "0.32"

}

repositories {
Expand All @@ -14,5 +16,6 @@ dependencies {
implementation("co.fs2:fs2-io_2.13:3.6.1")


testImplementation("org.scalatest:scalatest_2.13:3.2.14")
testImplementation("org.scalatest:scalatest_2.13:3.2.0")
testRuntimeOnly("com.vladsch.flexmark:flexmark-all:0.35.10")
}
4 changes: 2 additions & 2 deletions lib/src/main/scala/g4s/log/LogReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import cats.effect.std.Queue
import fs2.io.file.{Files, Path}
import fs2.{Pipe, Stream, text}

class LogReporter(path: Path) {
object LogReporter {

def writer: IO[StringFileWriter] = newWriteToFile(path)
def apply(path: Path): IO[StringFileWriter] = newWriteToFile(path)

private def toFile(path: Path): Pipe[IO, String, Unit] =
_.through(text.utf8.encode).through(Files[IO].writeAll(path)).debug()
Expand Down
6 changes: 3 additions & 3 deletions lib/src/test/scala/g4s/log/LogReporterTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import org.scalatest.matchers.should.Matchers
import java.nio.file.Paths

class LogReporterTest extends AnyFreeSpec with Matchers {

def !!! : Nothing = throw new AssertionError("Never expected")
"can write log file" in {
val buildPath = Path.fromNioPath(Paths.get(sys.props.getOrElse("user.dir", ???)))
val buildPath = Path.fromNioPath(Paths.get(sys.props.getOrElse("user.dir", !!!)))

val files = Files[IO]
val logFile = for {
tmp <- files.createTempFile(Some(buildPath.resolve("build")), "perf", "log", None)
w <- new LogReporter(tmp).writer
w <- LogReporter(tmp)
_ <- w.write(Assertion.AllOK)
_ <- w.write(Run(classOf[MyLog], 123L))
_ <- w.write(ScenarioStart("BasicSimulation2", 233))
Expand Down

0 comments on commit 3ee403f

Please sign in to comment.