From 53ea3596eccf652b91e6dce423ee7ac048cccf33 Mon Sep 17 00:00:00 2001 From: Antonio Cunei Date: Thu, 26 Oct 2017 00:30:03 +0200 Subject: [PATCH 1/4] Interim fix for #3583, for 1.0.3 In 0.13.x, zinc would discover only top-level objects and classes containing tests 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. This change 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. This patch unblocks https://github.com/sbt/sbt-standalone-build/issues/15 --- main-actions/src/main/scala/sbt/Tests.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main-actions/src/main/scala/sbt/Tests.scala b/main-actions/src/main/scala/sbt/Tests.scala index e0dbbffa9..d7b8dcac5 100644 --- a/main-actions/src/main/scala/sbt/Tests.scala +++ b/main-actions/src/main/scala/sbt/Tests.scala @@ -385,7 +385,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)) From b19bd33dc07c55d2da1dcefee838eef22983e5e0 Mon Sep 17 00:00:00 2001 From: Antonio Cunei Date: Thu, 26 Oct 2017 01:21:14 +0200 Subject: [PATCH 2/4] Missing import --- main-actions/src/main/scala/sbt/Tests.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/main-actions/src/main/scala/sbt/Tests.scala b/main-actions/src/main/scala/sbt/Tests.scala index d7b8dcac5..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 From 24a463cc6ba286ca0fca9e36b5f3b142ba90e09b Mon Sep 17 00:00:00 2001 From: Antonio Cunei Date: Thu, 26 Oct 2017 01:46:28 +0200 Subject: [PATCH 3/4] Add scripted test for nested test classes/objects --- sbt/src/sbt-test/tests/nested-tests/build.sbt | 8 ++++++ .../nested-tests/src/test/scala/q/X.scala | 25 +++++++++++++++++++ sbt/src/sbt-test/tests/nested-tests/test | 2 ++ 3 files changed, 35 insertions(+) create mode 100644 sbt/src/sbt-test/tests/nested-tests/build.sbt create mode 100644 sbt/src/sbt-test/tests/nested-tests/src/test/scala/q/X.scala create mode 100644 sbt/src/sbt-test/tests/nested-tests/test 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 + From c60a5a204eebbf3dd462553acd2d2d29add6799d Mon Sep 17 00:00:00 2001 From: Antonio Cunei Date: Thu, 26 Oct 2017 01:57:56 +0200 Subject: [PATCH 4/4] Release notes for the fix to #3583 --- notes/1.0.3/nested-tests.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 notes/1.0.3/nested-tests.md 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 +