Skip to content

Commit

Permalink
Merge pull request #13 from zainab-ali/fix-tests
Browse files Browse the repository at this point in the history
Fix CI pipeline
  • Loading branch information
Baccata authored Mar 13, 2024
2 parents 7d431a5 + 03d98b2 commit 1e57875
Show file tree
Hide file tree
Showing 22 changed files with 71 additions and 56 deletions.
6 changes: 6 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ project.git = true
project.excludeFilters = [
".*-scala-3.*"
]

fileOverride {
"glob:**/scala-3/**" {
runner.dialect = scala3
}
}
35 changes: 22 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sbt.librarymanagement.Configurations.ScalaDocTool

// https://typelevel.org/sbt-typelevel/faq.html#what-is-a-base-version-anyway
ThisBuild / tlBaseVersion := "0.0" // your current series x.y

Expand Down Expand Up @@ -25,18 +27,19 @@ ThisBuild / crossScalaVersions := Seq(scala212, scala213, "3.3.1")
ThisBuild / scalaVersion := scala213 // the default Scala

val Version = new {
val catsEffect = "3.5.2"
val catsLaws = "2.9.0"
val discipline = "1.5.1"
val expecty = "0.16.0"
val fs2 = "3.5.0"
val junit = "4.13.2"
val portableReflect = "1.1.2"
val scalaJavaTime = "2.4.0"
val scalacheck = "1.17.0"
val scalajsMacroTask = "1.1.1"
val scalajsStubs = "1.1.0"
val testInterface = "1.0"
val catsEffect = "3.5.2"
val catsLaws = "2.9.0"
val discipline = "1.5.1"
val expecty = "0.16.0"
val fs2 = "3.5.0"
val junit = "4.13.2"
val portableReflect = "1.1.2"
val scalaJavaTime = "2.4.0"
val scalacheck = "1.17.0"
val scalajsMacroTask = "1.1.1"
val scalajsStubs = "1.1.0"
val testInterface = "1.0"
val scalacCompatAnnotation = "0.1.4"
}

lazy val root = tlCrossRootProject.aggregate(core,
Expand All @@ -55,7 +58,8 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
"org.typelevel" %%% "cats-effect" % Version.catsEffect,
"com.eed3si9n.expecty" %%% "expecty" % Version.expecty,
// https://github.com/portable-scala/portable-scala-reflect/issues/23
"org.portable-scala" %%% "portable-scala-reflect" % Version.portableReflect cross CrossVersion.for3Use2_13
"org.portable-scala" %%% "portable-scala-reflect" % Version.portableReflect cross CrossVersion.for3Use2_13,
"org.typelevel" %% "scalac-compat-annotation" % Version.scalacCompatAnnotation
)
)

Expand Down Expand Up @@ -106,6 +110,11 @@ lazy val frameworkNative = framework.native
lazy val coreCats = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.in(file("modules/core-cats"))
.dependsOn(core)
.settings(
libraryDependencies ++= Seq(
"junit" % "junit" % Version.junit % ScalaDocTool
)
)
.settings(name := "cats-core")

lazy val coreCatsJS = coreCats.js
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.junit.runner

import org.typelevel.scalaccompat.annotation.unused

/**
* Stub used for cross-compilation
*/
class RunWith[T](cls: Class[T]) extends scala.annotation.StaticAnnotation
class RunWith[T](@unused cls: Class[T])
extends scala.annotation.StaticAnnotation
4 changes: 2 additions & 2 deletions modules/core/js/src/main/scala/weaver/PlatformCompat.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package weaver

import org.typelevel.scalaccompat.annotation.unused
private[weaver] object PlatformCompat {
val platform: Platform = Platform.JS

def getClassLoader(clazz: java.lang.Class[_]): ClassLoader =
def getClassLoader(@unused clazz: java.lang.Class[_]): ClassLoader =
new ClassLoader() {}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package weaver
package junit

import org.typelevel.scalaccompat.annotation.unused

import weaver.TestStatus._
import weaver.internals.Reflection

import org.junit.runner.Description
import org.junit.runner.notification.RunNotifier

class WeaverRunner(cls: Class[_], dummy: Boolean)
class WeaverRunner(cls: Class[_], @unused dummy: Boolean)
extends org.junit.runner.Runner {

type F[A] = Any
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.junit.runner
import org.typelevel.scalaccompat.annotation.unused

/**
* Stub used for cross-compilation
*/
class RunWith[T](cls: Class[T]) extends scala.annotation.StaticAnnotation
class RunWith[T](@unused cls: Class[T])
extends scala.annotation.StaticAnnotation
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package weaver
import org.typelevel.scalaccompat.annotation.unused

private[weaver] object PlatformCompat {
val platform: Platform = Platform.Native

def getClassLoader(clazz: java.lang.Class[_]): ClassLoader =
def getClassLoader(@unused clazz: java.lang.Class[_]): ClassLoader =
new ClassLoader() {}
}
3 changes: 0 additions & 3 deletions modules/core/shared/src/main/scala-3/weaver/Expect.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package weaver

import cats.data.{ NonEmptyList, ValidatedNel }
import cats.syntax.all._

import com.eed3si9n.expecty._
import internals._

Expand Down
2 changes: 1 addition & 1 deletion modules/core/shared/src/main/scala/weaver/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ object Test {

def apply[F[_]](name: String, f: F[Expectations])(
implicit F: EffectCompat[F]
): F[TestOutcome] = apply(name, (_: Log[F]) => f)
): F[TestOutcome] = apply[F](name, (_: Log[F]) => f)

}
6 changes: 3 additions & 3 deletions modules/core/shared/src/main/scala/weaver/suites.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import cats.effect.{ Async, Resource }
import cats.syntax.all._

import fs2.Stream
import org.junit.runner.RunWith
import org.portablescala.reflect.annotation.EnableReflectiveInstantiation
import org.junit.runner.RunWith

// Just a non-parameterized marker trait to help SBT's test detection logic.
@EnableReflectiveInstantiation
Expand Down Expand Up @@ -131,13 +131,13 @@ abstract class MutableFSuite[F[_]] extends RunnableSuite[F] {
}

def pureTest(name: TestName)(run : => Expectations) : Unit = registerTest(name)(_ => Test(name.name, effectCompat.effect.delay(run)))
def loggedTest(name: TestName)(run: Log[F] => F[Expectations]) : Unit = registerTest(name)(_ => Test(name.name, log => run(log)))
def loggedTest(name: TestName)(run: Log[F] => F[Expectations]) : Unit = registerTest(name)(_ => Test[F](name.name, log => run(log)))
def test(name: TestName) : PartiallyAppliedTest = new PartiallyAppliedTest(name)

class PartiallyAppliedTest(name : TestName) {
def apply(run: => F[Expectations]) : Unit = registerTest(name)(_ => Test(name.name, run))
def apply(run : Res => F[Expectations]) : Unit = registerTest(name)(res => Test(name.name, run(res)))
def apply(run : (Res, Log[F]) => F[Expectations]) : Unit = registerTest(name)(res => Test(name.name, log => run(res, log)))
def apply(run : (Res, Log[F]) => F[Expectations]) : Unit = registerTest(name)(res => Test[F](name.name, log => run(res, log)))

// this alias helps using pattern matching on `Res`
def usingRes(run : Res => F[Expectations]) : Unit = apply(run)
Expand Down
8 changes: 4 additions & 4 deletions modules/framework-cats/jvm/src/test/scala/MetaJVM.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ object MetaJVM {
}
}

abstract class LazyAccessSequential(global: GlobalRead, index: Int)
abstract class LazyAccessSequential(global: GlobalRead)
extends IOSuite {
type Res = LazyState
def sharedResource: Resource[IO, Res] = {
Expand All @@ -157,10 +157,10 @@ object MetaJVM {

// Using sleeps to force sequential runs of suites
class LazyAccessSequential0(global: GlobalRead)
extends LazyAccessSequential(global, 0)
extends LazyAccessSequential(global)
class LazyAccessSequential1(global: GlobalRead)
extends LazyAccessSequential(global, 1)
extends LazyAccessSequential(global)
class LazyAccessSequential2(global: GlobalRead)
extends LazyAccessSequential(global, 2)
extends LazyAccessSequential(global)

}
6 changes: 3 additions & 3 deletions modules/framework-cats/shared/src/test/scala/Meta.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package weaver
package framework
package test

import scala.annotation.nowarn
import org.typelevel.scalaccompat.annotation._

import cats.effect._

Expand All @@ -14,7 +14,7 @@ object Meta {

object Boom extends Error("Boom") with scala.util.control.NoStackTrace

@nowarn("cat=w-flag-dead-code")
@nowarn2("cat=w-flag-dead-code")
object CrashingSuite extends SimpleIOSuite {
throw Boom
}
Expand Down Expand Up @@ -102,7 +102,7 @@ object Meta {
override implicit protected def effectCompat: UnsafeRun[IO] =
SetTimeUnsafeRun

loggedTest("erroring with causes") { log =>
loggedTest("erroring with causes") { _ =>
throw CustomException(
"surfaced error",
CustomException("first cause",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package framework
import cats.data.Chain
import cats.effect.Resource
import cats.syntax.all._
import org.typelevel.scalaccompat.annotation.unused

private[weaver] trait DogFoodCompat[F[_]] { self: DogFood[F] =>

Expand All @@ -15,7 +16,7 @@ private[weaver] trait DogFoodCompat[F[_]] { self: DogFood[F] =>
runner: WeaverRunner[F],
eventHandler: sbt.testing.EventHandler,
logger: sbt.testing.Logger,
maxParallelism: Int)(tasks: List[sbt.testing.Task]): F[Unit] = {
@unused maxParallelism: Int)(tasks: List[sbt.testing.Task]): F[Unit] = {
tasks.traverse { task =>
self.framework.unsafeRun.fromFuture {
task.asInstanceOf[AsyncTask].executeFuture(eventHandler, Array(logger))
Expand Down
5 changes: 3 additions & 2 deletions modules/framework/js-native/src/main/scala/RunnerCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package weaver
package framework

import java.nio.ByteBuffer
import org.typelevel.scalaccompat.annotation.unused

import scala.collection.mutable.ListBuffer
import scala.concurrent.Future
Expand Down Expand Up @@ -138,7 +139,7 @@ trait RunnerCompat[F[_]] { self: sbt.testing.Runner =>
}
}

def finaliseError(outcomes: Ref[
def finaliseError(@unused outcomes: Ref[
F,
Chain[TestOutcome]]): Throwable => F[Unit] = { error =>
val outcome =
Expand Down Expand Up @@ -177,7 +178,7 @@ trait RunnerCompat[F[_]] { self: sbt.testing.Runner =>
}

private[weaver] object ReadWriter {
class Reader(bytes: ByteBuffer, private var pt: Int) {
class Reader(bytes: ByteBuffer, @unused private var pt: Int) {
def readString() = {
val stringSize = bytes.getInt()
val ar = new Array[Byte](stringSize)
Expand Down
5 changes: 2 additions & 3 deletions modules/framework/jvm/src/main/scala/DogFoodCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import cats.effect.Resource
import cats.effect.implicits._

import sbt.testing._
import org.typelevel.scalaccompat.annotation.unused

private[weaver] trait DogFoodCompat[F[_]] { self: DogFood[F] =>

Expand All @@ -13,13 +14,11 @@ private[weaver] trait DogFoodCompat[F[_]] { self: DogFood[F] =>
def blocker: BlockerCompat[F]

def runTasksCompat(
runner: WeaverRunner[F],
@unused runner: WeaverRunner[F],
eventHandler: EventHandler,
logger: Logger,
maxParallelism: Int)(tasks: List[sbt.testing.Task]): F[Unit] = {

effect.void {
@scala.annotation.nowarn("msg=implicit numeric widening")
val r = tasks.toVector.parTraverseN[F, Unit](maxParallelism) { task =>
blocker.block(discard[Array[Task]](task.execute(eventHandler,
Array(logger))))
Expand Down
11 changes: 6 additions & 5 deletions modules/framework/jvm/src/main/scala/RunnerCompat.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package weaver
package framework
import org.typelevel.scalaccompat.annotation.unused

import java.io.PrintStream
import java.util.concurrent.ConcurrentLinkedQueue
Expand Down Expand Up @@ -37,7 +38,7 @@ trait RunnerCompat[F[_]] { self: sbt.testing.Runner =>
}

// Required on js
def receiveMessage(msg: String): Option[String] = None
def receiveMessage(@unused msg: String): Option[String] = None

// Flag meant to be raised if build-tool call `done`
protected val isDone: AtomicBoolean = new AtomicBoolean(false)
Expand All @@ -57,9 +58,9 @@ trait RunnerCompat[F[_]] { self: sbt.testing.Runner =>
val stillRunning = new AtomicInteger(0)
val waitForResourcesShutdown = new java.util.concurrent.Semaphore(0)

val tasksAndSuites = taskDefs.toList.map { taskDef =>
taskDef -> suiteLoader(taskDef)
}.collect { case (taskDef, Some(suite)) => (taskDef, suite) }
val tasksAndSuites = (taskDefs.toList.mapFilter { taskDef =>
suiteLoader(taskDef).tupleLeft(taskDef)
})

def makeTasks(
taskDef: TaskDef,
Expand Down Expand Up @@ -240,7 +241,7 @@ trait RunnerCompat[F[_]] { self: sbt.testing.Runner =>
.productR(broker.send(TestFinished(outcome))),
finalizer)
}
)).handleErrorWith { case scala.util.control.NonFatal(_) =>
)).recoverWith { case scala.util.control.NonFatal(_) =>
effect.unit // avoid non-fatal errors propagating up
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract class DogFood[F[_]](
for {
eventHandler <- effect.delay(new MemoryEventHandler())
logger <- effect.delay(new MemoryLogger())
_ <- getTasks(suites, logger).use { case (runner, tasks) =>
_ <- getTasks(suites).use { case (runner, tasks) =>
runTasks(runner, eventHandler, logger, maxParallelism)(tasks.toList)
}
_ <- patience.fold(effect.unit)(framework.unsafeRun.sleep)
Expand Down Expand Up @@ -71,8 +71,8 @@ abstract class DogFood[F[_]](
}

private def getTasks(
suites: Seq[Fingerprinted],
logger: Logger): Resource[F, (WeaverRunner[F], Array[sbt.testing.Task])] = {
suites: Seq[Fingerprinted]
): Resource[F, (WeaverRunner[F], Array[sbt.testing.Task])] = {
val acquire = Sync[F].delay {
val cl = PlatformCompat.getClassLoader(this.getClass())
framework.weaverRunner(Array(), Array(), cl, None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import scala.reflect.ClassTag
import cats.effect.Sync

import weaver.internals.Reflection._
import weaver.{ EffectSuite, GlobalResourceF }

import sbt.testing.{ Fingerprint, SubclassFingerprint, TaskDef }

Expand Down Expand Up @@ -59,6 +58,7 @@ abstract class WeaverFingerprints[F[_]](implicit F: Sync[F]) {
loadModule(taskDef.fullyQualifiedName(), classLoader)
val init = cast(module)(GlobalResourcesInitClass)
Some(GlobalResourcesRef(init))
case _ => None
}

}
Expand All @@ -76,7 +76,7 @@ abstract class WeaverFingerprints[F[_]](implicit F: Sync[F]) {
/**
* A fingerprint that searches only for classes extending
* [[weaver.EffectSuite]]. that have a constructor that takes a single
* [[weaver.GlobalResources.Read]] parameter.
* [[weaver.GlobalResourceF.Read]] parameter.
*/
object ResourceSharingSuiteFingerprint extends WeaverFingerprint {
def isModule() = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package framework

import java.io.PrintStream

import weaver.{ Platform, discard }

import sbt.testing.{ Framework => BaseFramework, Runner => BaseRunner, _ }

class WeaverFramework[F[_]](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import scala.concurrent.duration._
import cats.effect.Outcome._
import cats.effect.testkit.TestControl
import cats.effect.{ IO, Ref }
import cats.syntax.all._

import weaver.TestStatus

import org.scalacheck.Gen

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package scalacheck
import scala.concurrent.duration._

import cats.effect.IO
import cats.syntax.all._

import org.scalacheck.Gen

Expand Down
Loading

0 comments on commit 1e57875

Please sign in to comment.