Skip to content

Commit 17d3198

Browse files
committed
Convert from ZIO to Kyo
1 parent c0eb061 commit 17d3198

File tree

124 files changed

+11920
-15567
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+11920
-15567
lines changed

build.sbt

+19-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ val compilerOptions = Set(
2222
ScalacOptions.deprecation,
2323
ScalacOptions.warnValueDiscard,
2424
ScalacOptions.warnNonUnitStatement,
25-
ScalacOptions.languageStrictEquality,
25+
ScalacOptions.other("-explain-cyclic"),
26+
// ScalacOptions.languageStrictEquality,
2627
ScalacOptions.release("11"),
2728
ScalacOptions.advancedKindProjector
2829
)
@@ -485,6 +486,23 @@ lazy val `kyo-caliban` =
485486
)
486487
.jvmSettings(mimaCheck(false))
487488

489+
lazy val `kyo-test` =
490+
crossProject(JVMPlatform, JSPlatform)
491+
.withoutSuffixFor(JVMPlatform)
492+
.crossType(CrossType.Full)
493+
.in(file("kyo-test"))
494+
.dependsOn(`kyo-core`)
495+
.dependsOn(`kyo-combinators`)
496+
.dependsOn(`kyo-zio`)
497+
.dependsOn(`kyo-stm`)
498+
.settings(
499+
`kyo-settings`,
500+
)
501+
.jsSettings(
502+
`js-settings`
503+
)
504+
.jvmSettings(mimaCheck(false))
505+
488506
lazy val `kyo-zio-test` =
489507
crossProject(JVMPlatform, JSPlatform)
490508
.withoutSuffixFor(JVMPlatform)

kyo-core/jvm/src/main/scala/kyo/Process.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package kyo
22

3-
import java.io.*
3+
import java.io.ByteArrayInputStream
4+
import java.io.File
5+
import java.io.InputStream
6+
import java.io.OutputStream
47
import java.lang.Process as JProcess
58
import java.lang.ProcessBuilder.Redirect
69
import java.lang.System as JSystem

kyo-data/shared/src/main/scala/kyo/Ansi.scala

+24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@ import scala.util.control.NonFatal
55
/** Provides ANSI color and formatting utilities for strings.
66
*/
77
object Ansi:
8+
sealed abstract class AnsiCode(val code: String)
9+
sealed abstract class Color(code: String) extends AnsiCode(code)
10+
11+
object Color:
12+
case object Blue extends Color("\u001b[34m")
13+
case object Cyan extends Color("\u001b[36m")
14+
case object Green extends Color("\u001b[32m")
15+
case object Magenta extends Color("\u001b[35m")
16+
case object Red extends Color("\u001b[31m")
17+
case object Yellow extends Color("\u001b[33m")
18+
end Color
19+
20+
sealed abstract class Style(code: String) extends AnsiCode(code)
21+
22+
object Style:
23+
case object Bold extends Style("\u001b[1m")
24+
case object Faint extends Style("\u001b[2m")
25+
case object Underlined extends Style("\u001b[4m")
26+
case object Reversed extends Style("\u001b[7m")
27+
end Style
828

929
extension (str: String)
1030
/** Applies black color to the string. */
@@ -45,9 +65,13 @@ object Ansi:
4565

4666
/** Applies underline formatting to the string. */
4767
def underline: String = s"\u001b[4m$str\u001b[0m"
68+
def faint: String = withAnsi(Style.Faint)
69+
def inverted: String = withAnsi(Style.Reversed)
4870

4971
/** Removes all ANSI escape sequences from the string. */
5072
def stripAnsi: String = str.replaceAll("\u001b\\[[0-9;]*[a-zA-Z]", "")
73+
74+
def withAnsi(code: AnsiCode): String = s"${code.code}$str\u001b[0m"
5175
end extension
5276

5377
object highlight:

kyo-prelude/shared/src/main/scala/kyo/Stream.scala

+11
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,17 @@ object Stream:
567567
}
568568
}
569569

570+
/** Creates a stream by unfolding a seed value as long as f returns Some value. */
571+
def unfold[V, T, S](z: T)(f: T => Option[(V, T)])(using tag: Tag[Emit[Chunk[V]]], frame: Frame): Stream[V, S] =
572+
f(z) match
573+
case Some((v, next)) =>
574+
Stream {
575+
Emit.valueWith(Chunk.from(Seq(v))) {
576+
unfold(next)(f).emit
577+
}
578+
}
579+
case None => Stream.empty
580+
570581
/** A dummy type that can be used as implicit evidence to help the compiler discriminate between overloaded methods.
571582
*/
572583
sealed class Dummy

kyo-test/TODO.md

+375
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package kyo.test
22

3-
import zio.stacktracer.TracingImplicits.disableAutoTrace
4-
import zio.{Duration, Scheduler, Trace, UIO, Unsafe, ZIO}
3+
import kyo.*
54

6-
private[test] trait TestClockPlatformSpecific { self: TestClock.Test =>
5+
private[test] trait TestClockPlatformSpecific:
6+
self: TestClock.Test =>
77

8-
def scheduler(implicit trace: Trace): UIO[Scheduler] =
9-
ZIO.runtime[Any].map { runtime =>
10-
new Scheduler {
11-
def schedule(runnable: Runnable, duration: Duration)(implicit unsafe: Unsafe): Scheduler.CancelToken = {
12-
val fiber =
13-
runtime.unsafe.fork(sleep(duration) *> ZIO.succeed(runnable.run()))
14-
() => runtime.unsafe.run(fiber.interruptAs(zio.FiberId.None)).getOrThrowFiberFailure().isInterrupted
8+
def scheduler(implicit trace: Trace): Scheduler < Async =
9+
Kyo.runtime[Any].map { runtime =>
10+
new Scheduler:
11+
def schedule(runnable: Runnable, duration: Duration)(implicit unsafe: Unsafe): Scheduler.CancelToken =
12+
val fiber =
13+
runtime.unsafe.fork(Kyo.sleep(duration) *> Kyo.pure(runnable.run()))
14+
() => runtime.unsafe.run(fiber.interrupt).getOrThrowFiberFailure().isInterrupted
15+
end schedule
1516
}
16-
}
17-
}
18-
}
17+
end TestClockPlatformSpecific
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
package kyo.test
22

3-
import zio.{Ref, ZIO}
4-
53
// TODO Implement this with appropriate JS filesystem APIs after JVM version is finalized
6-
private[test] object TestDebug {
7-
def print(executionEvent: ExecutionEvent, lock: TestDebugFileLock) =
8-
executionEvent match {
9-
case t: ExecutionEvent.TestStarted =>
10-
write(t.fullyQualifiedName, s"${t.labels.mkString(" - ")} STARTED\n", true, lock)
4+
private[test] object TestDebug:
5+
def print(executionEvent: ExecutionEvent, lock: TestDebugFileLock): Unit < Any =
6+
executionEvent match
7+
case t: ExecutionEvent.TestStarted =>
8+
write(t.fullyQualifiedName, s"${t.labels.mkString(" - ")} STARTED\n", true, lock)
119

12-
case t: ExecutionEvent.Test[_] =>
13-
removeLine(t.fullyQualifiedName, t.labels.mkString(" - ") + " STARTED", lock)
10+
case t: ExecutionEvent.Test[?] =>
11+
removeLine(t.fullyQualifiedName, t.labels.mkString(" - ") + " STARTED", lock)
1412

15-
case _ => ZIO.unit
16-
}
13+
case _ => ()
1714

18-
private def write(
19-
fullyQualifiedTaskName: String,
20-
content: => String,
21-
append: Boolean,
22-
lock: TestDebugFileLock
23-
): ZIO[Any, Nothing, Unit] =
24-
ZIO.unit
15+
private def write(
16+
fullyQualifiedTaskName: String,
17+
content: => String,
18+
append: Boolean,
19+
lock: TestDebugFileLock
20+
): Unit < Any =
21+
()
2522

26-
private def removeLine(fullyQualifiedTaskName: String, searchString: String, lock: TestDebugFileLock) =
27-
ZIO.unit
23+
private def removeLine(fullyQualifiedTaskName: String, searchString: String, lock: TestDebugFileLock): Unit < Any =
24+
()
2825

29-
def createDebugFile(fullyQualifiedTaskName: String): ZIO[Any, Nothing, Unit] =
30-
ZIO.unit
26+
def createDebugFile(fullyQualifiedTaskName: String): Unit < Any =
27+
()
3128

32-
def deleteIfEmpty(fullyQualifiedTaskName: String): ZIO[Any, Nothing, Unit] = ZIO.unit
33-
}
29+
def deleteIfEmpty(fullyQualifiedTaskName: String): Unit < Any = ()
30+
end TestDebug
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
package kyo.test
22

3-
import zio.stacktracer.TracingImplicits.disableAutoTrace
3+
/** `TestPlatform` provides information about the platform tests are being run on to enable platform specific test configuration.
4+
*/
5+
object TestPlatform:
46

5-
/**
6-
* `TestPlatform` provides information about the platform tests are being run on
7-
* to enable platform specific test configuration.
8-
*/
9-
object TestPlatform {
7+
/** Returns whether the current platform is ScalaJS.
8+
*/
9+
final val isJS = true
1010

11-
/**
12-
* Returns whether the current platform is ScalaJS.
13-
*/
14-
final val isJS = true
11+
/** Returns whether the currently platform is the JVM.
12+
*/
13+
final val isJVM = false
1514

16-
/**
17-
* Returns whether the currently platform is the JVM.
18-
*/
19-
final val isJVM = false
20-
21-
/**
22-
* Returns whether the current platform is Scala Native.
23-
*/
24-
final val isNative = false
25-
}
15+
/** Returns whether the current platform is Scala Native.
16+
*/
17+
final val isNative = false
18+
end TestPlatform
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
package kyo.test.results
22

3-
import zio._
4-
53
import java.io.IOException
4+
import kyo.*
65

7-
private[test] trait ResultFileOps {
8-
def write(content: => String, append: Boolean): ZIO[Any, IOException, Unit]
9-
}
10-
11-
private[test] object ResultFileOps {
12-
val live: ZLayer[Any, Nothing, ResultFileOps] =
13-
ZLayer.succeed(
14-
Json()
15-
)
6+
private[test] trait ResultFileOps:
7+
def write(content: => String, append: Boolean): Unit < (Env[Any] & Abort[IOException])
168

17-
private[test] case class Json() extends ResultFileOps {
18-
def write(content: => String, append: Boolean): ZIO[Any, IOException, Unit] =
19-
ZIO.unit
20-
}
9+
private[test] object ResultFileOps:
10+
val live: Layer[ResultFileOps, Any] =
11+
Layer(
12+
Json()
13+
)
2114

22-
}
15+
private[test] case class Json() extends ResultFileOps:
16+
def write(content: => String, append: Boolean): Unit < (Env[Any] & Abort[IOException]) =
17+
()
18+
end ResultFileOps
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
package kyo.test.results
22

3-
import zio._
4-
import zio.test._
3+
import kyo.*
4+
import kyo.test.*
55

6-
private[test] object ResultPrinterJson {
7-
val live: ZLayer[Any, Nothing, ResultPrinter] =
8-
ZLayer.make[ResultPrinter](
9-
ResultSerializer.live,
10-
ResultFileOps.live,
11-
ZLayer.fromFunction(
12-
LiveImpl(_, _)
13-
)
14-
)
6+
private[test] object ResultPrinterJson:
7+
val live: Layer[ResultPrinter, Any] =
8+
Layer.init(
9+
ResultSerializer.live,
10+
ResultFileOps.live,
11+
Layer.from((serializer, resultFileOps) => LiveImpl(serializer, resultFileOps))
12+
)
1513

16-
private case class LiveImpl(serializer: ResultSerializer, resultFileOps: ResultFileOps) extends ResultPrinter {
17-
override def print[E](event: ExecutionEvent.Test[E]): ZIO[Any, Nothing, Unit] =
18-
resultFileOps.write(serializer.render(event), append = true).orDie
19-
}
20-
}
14+
private case class LiveImpl(serializer: ResultSerializer, resultFileOps: ResultFileOps) extends ResultPrinter:
15+
override def print[E](event: ExecutionEvent.Test[E]): Unit < (Env[Any] & Abort[Nothing]) =
16+
resultFileOps.write(serializer.render(event), append = true).orPanic
17+
end ResultPrinterJson

0 commit comments

Comments
 (0)