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

Refactor CompletenessTest to support adding completeness tests for other classes #174

Merged
merged 8 commits into from
Aug 31, 2015

Conversation

zsxwing
Copy link
Member

@zsxwing zsxwing commented Aug 23, 2015

Single was added to RxJava recently. It would be better if we could also test its completeness when adding it to RxScala.

This PR refactors CompletenessTest to support testing completeness of other classes easily, including:

  • Add CompletenessKit as a basic trait for classes that we want to test completeness. Most of codes are from the old CompletenessTest.scala.
  • Add ObservableCompletenessKit.scala, TestSchedulerCompletenessKit.scala, TestSubscriberCompletenessKit.scala and BlockingObservableCompletenessKit.scala to demonstrate how to use CompletenessKit.
  • Move the codes used to generate the completeness table to CompletenessTables.scala and change it to support to output tables for all CompletenessKits. Run sbt 'test:run rx.lang.scala.completeness.CompletenessTest' to see these tables.
  • Move all classes for completeness to the completeness package.

@@ -16,6 +16,8 @@ scalaVersion in ThisBuild := "2.11.6"

crossScalaVersions in ThisBuild := Seq("2.10.5", "2.11.6")

parallelExecution in Test := false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabled parallel execution because I encounter some weird exception without this line, e.g.,

[info] - checkScalaMethodPresenceVerbose *** FAILED ***
[info]   java.lang.ClassNotFoundException: o .lang.scala.Observ
[info]   at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[info]   at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[info]   at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[info]   at java.lang.Class.forName0(Native Method)
[info]   at java.lang.Class.forName(Class.java:348)
[info]   at scala.reflect.runtime.JavaMirrors$JavaMirror.javaClass(JavaMirrors.scala:500)
[info]   at scala.reflect.runtime.SymbolLoaders$TopClassCompleter.complete(SymbolLoaders.scala:32)
[info]   at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1231)
[info]   at scala.reflect.internal.Types$TypeRef.thisInfo(Types.scala:2407)
[info]   at scala.reflect.internal.Types$TypeRef.baseClasses(Types.scala:2412)

I guess some reflection APIs are not thread-safe (or a bug?). So if running multiple CompletenessKit at the same time, it will crash.

However, since RxScala's unit tests are pretty fast, disabling it hurts nothing.

@zsxwing
Copy link
Member Author

zsxwing commented Aug 23, 2015

BTW, SBT 0.13.8 supports cross-version for Scala sources:

Cross-version support for Scala sources
When crossPaths setting is set to true (it is true by default), sbt 0.13.8 will include
src/main/scala-/ to the Compile compilation in addition to
src/main/scala. For example, it will include src/main/scala-2.11/ for Scala 2.11.5, and
src/main/scala-2.9.3 for Scala 2.9.3.

We can upgrade SBT to 0.13.8 and move these completeness tests to the scala-2.11 folder. So that we can fix the deprecation warnings and enable -Xfatal-warnings. It's safe to run completeness tests only in Scala 2.11.

for ((javaM, scalaM) <- c) {
println(s""" %-${len}s -> %s,""".format("\"" + javaM + "\"", "\"" + scalaM + "\""))
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several methods (including this one) are deleted here but not added to anywhere. I would like to keep them, because they might be useful for maintenance in the future.

@samuelgruetter
Copy link
Collaborator

sbt 0.13.8 + -Xfatal-warnings sounds nice, let's do that [until we get some "unfixable" warnings ;-)]

@samuelgruetter
Copy link
Collaborator

Nice re-design 👍
I only had a few nitpicky remarks to add ;-)

@zsxwing
Copy link
Member Author

zsxwing commented Aug 25, 2015

@samuelgruetter just sent more commits to address your comments.

This reverts commit bdae1eb.

Reason: It throws a ClassCastException for the following example (which is
accepted by the compiler):

class Fruit
class Apple extends Fruit
class Pear extends Fruit {
  def printMe: Unit = println(this)
}
val apples: Observable[Apple] = Observable.just(new Apple) ++ Observable.never
apples.toBlocking.mostRecent(new Pear).take(1).foreach(_.printMe)
println("done")
@zsxwing
Copy link
Member Author

zsxwing commented Aug 29, 2015

Merged your fix.

@samuelgruetter
Copy link
Collaborator

LGTM

zsxwing added a commit that referenced this pull request Aug 31, 2015
Refactor CompletenessTest to support adding completeness tests for other classes
@zsxwing zsxwing merged commit a6d959c into ReactiveX:0.x Aug 31, 2015
@zsxwing zsxwing deleted the completeness-kit branch August 31, 2015 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants