Skip to content

Commit

Permalink
bugfix: Fixed test suite discovery with the presence of companion obj…
Browse files Browse the repository at this point in the history
…ect. (#5030)

* Fixed test suite discovery with the presence of companion object.
  • Loading branch information
xydrolase authored Mar 8, 2023
1 parent 34b3cc8 commit 784494b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@ final class TestSuitesProvider(
currentTarget.testSymbols
.readOnlySnapshot()
.toList
// sort the symbols lexically so that symbols with the same fullyQualifiedName
// will be grouped, and the class will come before companion object (i.e.
// `a.b.WordSpec#` < `a.b.WordSpec.`). This ensures that the class is put into the cache
// instead of the companion object.
.sortBy { case (symbol, _) => symbol }
.foldLeft(List.empty[TestEntry]) {
case (entries, (symbol, testSymbolInfo)) =>
val fullyQualifiedName =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,67 @@ class TestSuitesProviderSuite extends BaseLspSuite("testSuitesFinderSuite") {
},
)

checkEvents(
"scalatest-any-word-spec-with-companion-object",
List("org.scalatest::scalatest:3.2.13"),
s"""|
|/app/src/main/scala/a/b/WordSpec.scala
|package a.b
|import org.scalatest.wordspec.AnyWordSpec
|
|class WordSpec extends AnyWordSpec {
| import WordSpec._
| "A Set" when {
| "empty" should {
| "have size 0" in {
| assert(foo == "bar")
| assert(Set.empty.size == 0)
| }
| }
| }
|}
|
|object WordSpec {
def foo: String = "bar"
|}
|""".stripMargin,
file = "app/src/main/scala/a/b/WordSpec.scala",
expected = () => {
val fcqn = "a.b.WordSpec"
val className = "WordSpec"
val symbol = "a/b/WordSpec#"
val file = "app/src/main/scala/a/b/WordSpec.scala"
List(
BuildTargetUpdate(
"app",
targetUri,
List[TestExplorerEvent](
AddTestSuite(
fcqn,
className,
symbol,
QuickLocation(
classUriFor(file),
(3, 6, 3, 14),
).toLsp,
canResolveChildren = true,
),
AddTestCases(
fcqn,
className,
List(
TestCaseEntry(
"A Set when empty should have size 0",
QuickLocation(classUriFor(file), (7, 6, 7, 19)).toLsp,
)
).asJava,
),
).asJava,
)
)
},
)

checkEvents(
"scalatest-any-flat-spec",
List("org.scalatest::scalatest:3.2.13"),
Expand Down

0 comments on commit 784494b

Please sign in to comment.