-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Split root project into `kyoJVM` and `kyoJS`. The JVM project is selected by default, this way the regular development cycle is faster but there's the downside that we might not catch issues in JS before CI. It seems a reasonable tradeoff since it's possible to run the tests manually by selecting the `kyoJS` project. - Avoid the dependency on `kyo-core` tests in other modules. All other modules end up stuck waiting for the core tests to compile because of the dependency. I had to duplicate some of the code in `KyoTest` into the other modules to achieve that. - Move `scalafmt` from the build to a commit hook. - Remove `-Wunused:all` compiler option. It significantly increases the compilation times for tests. We can attempt to add it back once we're on Scala 3.5, which seems to [improve build times](#342 (comment)) with the option enabled. Results with a cold JVM: **Main** ``` $ sbt ";clean;compile" [success] Total time: 24 s, completed May 30, 2024, 1:58:13 PM $ sbt ";clean;test:compile" [success] Total time: 58 s, completed May 30, 2024, 1:59:58 PM $ sbt ";clean;test" [success] Total time: 88 s (01:28), completed May 30, 2024, 2:01:45 PM ``` **This PR (default `kyoJVM` only)** ``` $ sbt ";clean;compile" [success] Total time: 14 s, completed May 30, 2024, 1:54:29 PM $ sbt ";clean;test:compile" [success] Total time: 27 s, completed May 30, 2024, 1:55:51 PM $ sbt ";clean;test" [success] Total time: 39 s, completed May 30, 2024, 1:56:59 PM ``` I won't close #342 since there's always opportunity to optimize the build.
- Loading branch information
Showing
20 changed files
with
265 additions
and
114 deletions.
There are no files selected for viewing
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,8 @@ | ||
#!/bin/sh | ||
echo "Running pre-commit hook to format Scala source files" | ||
sbt scalafmtAll | ||
if ! git diff --exit-code --quiet | ||
then | ||
echo "Formatting changes detected. Please stage the changes and commit again." | ||
exit 1 | ||
fi |
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
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
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,16 @@ | ||
package kyoTest | ||
|
||
import kyo.* | ||
import kyo.internal.BaseKyoTest | ||
import org.scalatest.NonImplicitAssertions | ||
import org.scalatest.freespec.AsyncFreeSpec | ||
import scala.concurrent.ExecutionContext | ||
import scala.language.implicitConversions | ||
|
||
abstract class KyoTest extends AsyncFreeSpec with BaseKyoTest with NonImplicitAssertions: | ||
|
||
type Assertion = org.scalatest.compatible.Assertion | ||
def success = succeed | ||
|
||
override given executionContext: ExecutionContext = kyo.internal.Platform.executionContext | ||
end KyoTest |
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,16 @@ | ||
package kyoTest | ||
|
||
import kyo.* | ||
import kyo.internal.BaseKyoTest | ||
import org.scalatest.NonImplicitAssertions | ||
import org.scalatest.freespec.AsyncFreeSpec | ||
import scala.concurrent.ExecutionContext | ||
import scala.language.implicitConversions | ||
|
||
abstract class KyoTest extends AsyncFreeSpec with BaseKyoTest with NonImplicitAssertions: | ||
|
||
type Assertion = org.scalatest.compatible.Assertion | ||
def success = succeed | ||
|
||
override given executionContext: ExecutionContext = kyo.internal.Platform.executionContext | ||
end KyoTest |
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
2 changes: 1 addition & 1 deletion
2
.../js/src/test/scala/kyoTest/Platform.scala → ...rc/main/scala/kyo/internal/Platform.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
2 changes: 1 addition & 1 deletion
2
...jvm/src/test/scala/kyoTest/Platform.scala → ...rc/main/scala/kyo/internal/Platform.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
56 changes: 56 additions & 0 deletions
56
kyo-core/shared/src/main/scala/kyo/internal/BaseKyoTest.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,56 @@ | ||
package kyo.internal | ||
|
||
import kyo.* | ||
import scala.concurrent.Future | ||
import scala.language.implicitConversions | ||
import scala.util.Try | ||
|
||
trait BaseKyoTest: | ||
|
||
type Assertion | ||
|
||
def success: Assertion | ||
|
||
given tryCanEqual[T]: CanEqual[Try[T], Try[T]] = CanEqual.derived | ||
given eitherCanEqual[T, U]: CanEqual[Either[T, U], Either[T, U]] = CanEqual.derived | ||
given throwableCanEqual: CanEqual[Throwable, Throwable] = CanEqual.derived | ||
|
||
def retry[S](f: => Boolean < S): Boolean < S = | ||
def loop(): Boolean < S = | ||
f.map { | ||
case true => true | ||
case false => loop() | ||
} | ||
loop() | ||
end retry | ||
|
||
def timeout = | ||
if kyo.internal.Platform.isDebugEnabled then | ||
Duration.Infinity | ||
else | ||
5.seconds | ||
|
||
// given Conversion[Assertion, Future[Assertion]] = Future.successful(_) | ||
|
||
def runJVM( | ||
v: => Assertion < KyoApp.Effects | ||
)(using Flat[Assertion]): Future[Assertion] = | ||
if kyo.internal.Platform.isJVM then | ||
run(v) | ||
else | ||
Future.successful(success) | ||
|
||
def runJS( | ||
v: => Assertion < KyoApp.Effects | ||
)(using Flat[Assertion]): Future[Assertion] = | ||
if kyo.internal.Platform.isJS then | ||
run(v) | ||
else | ||
Future.successful(success) | ||
|
||
def run( | ||
v: => Assertion < KyoApp.Effects | ||
)(using Flat[Assertion]): Future[Assertion] = | ||
IOs.run(KyoApp.runFiber(timeout)(v).toFuture).map(_.get)(using Platform.executionContext) | ||
|
||
end BaseKyoTest |
Oops, something went wrong.