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] Experimenting with stabilizing builds #1250

Closed
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 build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ lazy val disciplineDependencies = Seq(
lazy val testingDependencies = Seq(
libraryDependencies += "org.typelevel" %%% "catalysts-platform" % "0.0.2",
libraryDependencies += "org.typelevel" %%% "catalysts-macros" % "0.0.2" % "test",
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.0.0-M8" % "test")
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.0.0-M7" % "test")


/**
Expand Down
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
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.3")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.2.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.8.4")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.11")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.8")
addSbtPlugin("com.github.tkawachi" % "sbt-doctest" % "0.3.5")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
6 changes: 5 additions & 1 deletion scripts/travis-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@ sbt_cmd="sbt ++$TRAVIS_SCALA_VERSION"

coverage="$sbt_cmd coverage validateJVM coverageReport && codecov"

run_cmd="$coverage && $sbt_cmd validate && $sbt_cmd $publish_cmd"
valJS="$sbt_cmd validateJS"

valJVM="$sbt_cmd validateJVM"

run_cmd="$coverage && $sbt_cmd clean && $valJS && $valJVM && $sbt_cmd $publish_cmd"
eval $run_cmd
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
24 changes: 12 additions & 12 deletions tests/src/test/scala/cats/tests/NonEmptyVectorTests.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package cats
package tests

import catalysts.Platform
//import catalysts.Platform

import cats.kernel.laws.{GroupLaws, OrderLaws}

import cats.data.NonEmptyVector
import cats.laws.discipline.{ComonadTests, SemigroupKTests, FoldableTests, SerializableTests, TraverseTests, ReducibleTests, MonadRecTests}
import cats.laws.discipline.arbitrary._

import scala.util.Properties
//import scala.util.Properties

class NonEmptyVectorTests extends CatsSuite {
// Lots of collections here.. telling ScalaCheck to calm down a bit
Expand Down Expand Up @@ -243,16 +243,16 @@ class NonEmptyVectorTests extends CatsSuite {
NonEmptyVector(1, Vector.empty).toVector.toString should === ("Vector(1)")
}

test("Cannot create a new NonEmptyVector from constructor") {
if(Platform.isJvm) {
if (!Properties.versionNumberString.startsWith("2.10")) {
// A bug in scala 2.10 allows private constructors to be accessed.
// We should still ensure that on scala 2.11 and up we cannot construct the
// object directly. see: https://issues.scala-lang.org/browse/SI-6601
"val bad: NonEmptyVector[Int] = new NonEmptyVector(Vector(1))" shouldNot compile
}
}
}
//test("Cannot create a new NonEmptyVector from constructor") {
// if(Platform.isJvm) {
// if (!Properties.versionNumberString.startsWith("2.10")) {
// // A bug in scala 2.10 allows private constructors to be accessed.
// // We should still ensure that on scala 2.11 and up we cannot construct the
// // object directly. see: https://issues.scala-lang.org/browse/SI-6601
// "val bad: NonEmptyVector[Int] = new NonEmptyVector(Vector(1))" shouldNot compile
// }
// }
//}

test("Cannot create a new NonEmptyVector from apply with an empty vector") {
"val bad: NonEmptyVector[Int] = NonEmptyVector(Vector(1))" shouldNot compile
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