Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Do not merge] Don't run stack-safety tests for JS #1246

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion free/src/test/scala/cats/free/FreeApplicativeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FreeApplicativeTests extends CatsSuite {
checkAll("FreeApplicative[Option, ?]", ApplicativeTests[FreeApplicative[Option, ?]].applicative[Int, Int, Int])
checkAll("Applicative[FreeApplicative[Option, ?]]", SerializableTests.serializable(Applicative[FreeApplicative[Option, ?]]))

test("toString is stack-safe") {
slowTest("toString is stack-safe") {
val r = FreeApplicative.pure[List, Int](333)
val rr = (1 to 1000000).foldLeft(r)((r, _) => r.map(_ + 1))
rr.toString.length should be > 0
Expand Down
6 changes: 3 additions & 3 deletions free/src/test/scala/cats/free/FreeTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FreeTests extends CatsSuite {
checkAll("Free[Option, ?]", MonadRecTests[Free[Option, ?]].monadRec[Int, Int, Int])
checkAll("MonadRec[Free[Option, ?]]", SerializableTests.serializable(MonadRec[Free[Option, ?]]))

test("toString is stack-safe") {
slowTest("toString is stack-safe") {
val r = Free.pure[List, Int](333)
val rr = (1 to 1000000).foldLeft(r)((r, _) => r.map(_ + 1))
rr.toString.length should be > 0
Expand Down Expand Up @@ -50,14 +50,14 @@ class FreeTests extends CatsSuite {
}
}

test("tailRecM is stack safe") {
slowTest("tailRecM is stack safe") {
val n = 50000
val fa = MonadRec[Free[Option, ?]].tailRecM(0)(i =>
Free.pure[Option, Int Xor Int](if (i < n) Xor.Left(i+1) else Xor.Right(i)))
fa should === (Free.pure[Option, Int](n))
}

test("foldMap is stack safe") {
slowTest("foldMap is stack safe") {
trait FTestApi[A]
case class TB(i: Int) extends FTestApi[Int]

Expand Down
13 changes: 13 additions & 0 deletions tests/src/test/scala/cats/tests/CatsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ trait CatsSuite extends FunSuite with Matchers with GeneratorDrivenPropertyCheck
// with scalactic's equality
override def catsSyntaxEq[A: Eq](a: A): EqOps[A] = new EqOps[A](a)

/**
* Declare a test that will not run in scala.js tests.
*
* In general, we want our tests to run in all target environments, but
* certain tests (especially those with heavy trampolining) seem to be leading
* to resource issues in the JS builds, causing them to sporadically fail.
*
* See https://github.com/typelevel/cats/issues/1242
*/
def slowTest(testName: String)(testFun: => Unit): Unit =
if (Platform.isJs) ()
else test(testName)(testFun)

def even(i: Int): Boolean = i % 2 == 0

val evenPf: PartialFunction[Int, Int] = { case i if even(i) => i }
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/scala/cats/tests/FoldableTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class FoldableTestsAdditional extends CatsSuite {
larger.value should === (large.map(_ + 1))
}

test("Foldable[List].foldM stack safety") {
slowTest("Foldable[List].foldM stack safety") {
def nonzero(acc: Long, x: Long): Option[Long] =
if (x == 0) None else Some(acc + x)

Expand Down
18 changes: 9 additions & 9 deletions tests/src/test/scala/cats/tests/MonadRecInstancesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,39 @@ class MonadRecInstancesTests extends CatsSuite {
res should === (M.pure(n))
}

test("tailRecM stack-safety for Id") {
slowTest("tailRecM stack-safety for Id") {
tailRecMStackSafety[Id]
}

test("tailRecM stack-safety for Option") {
slowTest("tailRecM stack-safety for Option") {
tailRecMStackSafety[Option]
}

test("tailRecM stack-safety for OptionT") {
slowTest("tailRecM stack-safety for OptionT") {
tailRecMStackSafety[OptionT[Option, ?]]
}

test("tailRecM stack-safety for Either") {
slowTest("tailRecM stack-safety for Either") {
tailRecMStackSafety[Either[String, ?]]
}

test("tailRecM stack-safety for Xor") {
slowTest("tailRecM stack-safety for Xor") {
tailRecMStackSafety[String Xor ?]
}

test("tailRecM stack-safety for XorT") {
slowTest("tailRecM stack-safety for XorT") {
tailRecMStackSafety[XorT[Option, String, ?]]
}

test("tailRecM stack-safety for List") {
slowTest("tailRecM stack-safety for List") {
tailRecMStackSafety[List]
}

test("tailRecM stack-safety for Eval") {
slowTest("tailRecM stack-safety for Eval") {
tailRecMStackSafety[Eval]
}

test("tailRecM stack-safety for StateT") {
slowTest("tailRecM stack-safety for StateT") {
import StateTTests._ // import implicit Eq[StateT[...]]
tailRecMStackSafety[StateT[Option, Int, ?]]
}
Expand Down
4 changes: 2 additions & 2 deletions tests/src/test/scala/cats/tests/ReducibleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.scalacheck.Arbitrary

class ReducibleTestsAdditional extends CatsSuite {

test("Reducible[NonEmptyList].reduceLeftM stack safety") {
slowTest("Reducible[NonEmptyList].reduceLeftM stack safety") {
def nonzero(acc: Long, x: Long): Option[Long] =
if (x == 0) None else Some(acc + x)

Expand All @@ -20,7 +20,7 @@ class ReducibleTestsAdditional extends CatsSuite {
abstract class ReducibleCheck[F[_]: Reducible](name: String)(implicit ArbFInt: Arbitrary[F[Int]]) extends FoldableCheck[F](name) {
def range(start: Long, endInclusive: Long): F[Long]

test(s"Reducible[$name].reduceLeftM stack safety") {
slowTest(s"Reducible[$name].reduceLeftM stack safety") {
def nonzero(acc: Long, x: Long): Option[Long] =
if (x == 0) None else Some(acc + x)

Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/scala/cats/tests/StateTTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class StateTTests extends CatsSuite {
add1.run(1).value should === (2 -> 1)
}

test("traversing state is stack-safe"){
slowTest("traversing state is stack-safe"){
val ns = (0 to 100000).toList
val x = ns.traverseU(_ => add1)
x.runS(0).value should === (100001)
Expand Down