diff --git a/main-actions/src/main/scala/sbt/Tests.scala b/main-actions/src/main/scala/sbt/Tests.scala index e0dbbffa9..97a3b2452 100644 --- a/main-actions/src/main/scala/sbt/Tests.scala +++ b/main-actions/src/main/scala/sbt/Tests.scala @@ -9,6 +9,7 @@ import sbt.internal.inc.Analysis import TaskExtra._ import sbt.internal.util.FeedbackProvidedException import xsbti.api.Definition +import xsbti.api.ClassLike import xsbti.compile.CompileAnalysis import ConcurrentRestrictions.Tag @@ -385,7 +386,11 @@ object Tests { defined(subclasses, d.baseClasses, d.isModule) ++ defined(annotations, d.annotations, d.isModule) - val discovered = Discovery(firsts(subclasses), firsts(annotations))(definitions) + val discovered = Discovery(firsts(subclasses), firsts(annotations))(definitions.filter { + case c: ClassLike => + c.topLevel + case _ => false + }) // TODO: To pass in correct explicitlySpecified and selectors val tests = for ((df, di) <- discovered; fingerprint <- toFingerprints(di)) yield new TestDefinition(df.name, fingerprint, false, Array(new SuiteSelector)) diff --git a/notes/1.0.3/nested-tests.md b/notes/1.0.3/nested-tests.md new file mode 100644 index 000000000..c34f3d41f --- /dev/null +++ b/notes/1.0.3/nested-tests.md @@ -0,0 +1,16 @@ +### Bug fixes + +In 0.13.x, zinc would discover only top-level objects and classes +containing tests, and pass them to the test framework. In 1.x, +however, zinc can discover also nested objects and classes; that +causes the "name" of a ClassLike to no longer be usable for reflection. + +Version 1.0.3 filters out nested objects/classes from the list, +restoring compatibility with 0.13. A zinc extension of ClassLike +will probably be introduced in 1.1 or 1.2, in order to provide +the test framework with enough information to deal with nested +classes. + +[@cunei]: https://github.com/cunei +[3583]: https://github.com/sbt/sbt/issues/3583 + diff --git a/sbt/src/sbt-test/tests/nested-tests/build.sbt b/sbt/src/sbt-test/tests/nested-tests/build.sbt new file mode 100644 index 000000000..2e47706f6 --- /dev/null +++ b/sbt/src/sbt-test/tests/nested-tests/build.sbt @@ -0,0 +1,8 @@ +libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.13.5" % "test" + +version := "0.0.1" +name := "broken" +organization := "org.catastrophe" +//scalaVersion := "2.10.6" +scalaVersion := "2.12.3" + diff --git a/sbt/src/sbt-test/tests/nested-tests/src/test/scala/q/X.scala b/sbt/src/sbt-test/tests/nested-tests/src/test/scala/q/X.scala new file mode 100644 index 000000000..6c80f0bce --- /dev/null +++ b/sbt/src/sbt-test/tests/nested-tests/src/test/scala/q/X.scala @@ -0,0 +1,25 @@ +package q + +// +// On 1.0.3+ this test will say: +// [info] + Nesting.startsWith: OK, passed 100 tests. +// [info] Passed: Total 1, Failed 0, Errors 0, Passed 1 +// +// On 1.0.0 to 1.0.2 it will crash with: +// [error] java.lang.ClassNotFoundException: q.X.Y$ +// + +import org.scalacheck.{Prop, Properties} +import Prop.forAll + +class U extends Properties("Nesting") +object X extends U { + property("startsWith") = forAll { (a: String, b: String) => + (a+b).startsWith(a) + } + object Y extends U { + property("endsWith") = forAll { (a: String, b: String) => + (a+b).endsWith(b) + } + } +} diff --git a/sbt/src/sbt-test/tests/nested-tests/test b/sbt/src/sbt-test/tests/nested-tests/test new file mode 100644 index 000000000..c8987ae90 --- /dev/null +++ b/sbt/src/sbt-test/tests/nested-tests/test @@ -0,0 +1,2 @@ +> test +