-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kamil Podsiadlo
committed
Dec 3, 2021
1 parent
db5c049
commit 495e0bf
Showing
3 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
tests/unit/src/test/scala/tests/testProvider/DiscoverTestClassesSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package tests | ||
|
||
import scala.concurrent.Future | ||
|
||
import scala.meta.internal.metals.MetalsEnrichments._ | ||
import scala.meta.internal.metals.ServerCommands | ||
import scala.meta.internal.metals.testProvider.TestDiscovery | ||
import scala.meta.internal.metals.testProvider.TestDiscoveryResult | ||
|
||
class DiscoverTestClassesSuite extends BaseLspSuite("discoverTests") { | ||
|
||
test("test-classes") { | ||
for { | ||
_ <- Future.successful(cleanWorkspace()) | ||
_ <- initialize(s"""|/metals.json | ||
|{ | ||
| "app": { | ||
| "libraryDependencies" : [ "org.scalameta::munit:0.7.29", "org.scalatest::scalatest:3.2.1" ], | ||
| "scalaVersion": "2.13.6" | ||
| } | ||
|} | ||
|/app/src/main/scala/foo/bar/MyTestSuite.scala | ||
|package foo.bar | ||
|abstract class AbstractTestSuite1 extends munit.FunSuite | ||
| | ||
|class MunitTestSuite extends AbstractTestSuite1 { | ||
| test("foo") {} | ||
|} | ||
|""".stripMargin) | ||
_ <- server.server.compilations.compilationFinished( | ||
workspace.resolve("app/src/main/scala/foo/bar/MyTestSuite.scala") | ||
) | ||
_ <- server.executeCommand(ServerCommands.CascadeCompile) | ||
_ <- server.didOpen("app/src/main/scala/foo/bar/MyTestSuite.scala") | ||
_ <- server.didSave("app/src/main/scala/foo/bar/MyTestSuite.scala")( | ||
identity | ||
) | ||
res <- server.testClasses("app/src/main/scala/foo/bar/MyTestSuite.scala") | ||
} yield { | ||
val obtained = res.map(TestDiscoveryWrapper(_)) | ||
val expected = List( | ||
TestDiscoveryWrapper( | ||
"app", | ||
List( | ||
TestDiscoveryResultWrapper.Package( | ||
"foo", | ||
List( | ||
TestDiscoveryResultWrapper.Package( | ||
"bar", | ||
List( | ||
TestDiscoveryResultWrapper.TestClass( | ||
"foo.bar.MunitTestSuite", | ||
"MunitTestSuite" | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
|
||
assertEquals(expected, obtained) | ||
} | ||
} | ||
} | ||
|
||
final case class TestDiscoveryWrapper( | ||
targetName: String, | ||
discovered: List[TestDiscoveryResultWrapper] | ||
) | ||
object TestDiscoveryWrapper { | ||
def apply(discovery: TestDiscovery): TestDiscoveryWrapper = | ||
TestDiscoveryWrapper( | ||
discovery.targetName, | ||
discovery.discovered.asScala | ||
.map(x => TestDiscoveryResultWrapper(x)) | ||
.toList | ||
) | ||
} | ||
|
||
sealed trait TestDiscoveryResultWrapper | ||
object TestDiscoveryResultWrapper { | ||
def apply(result: TestDiscoveryResult): TestDiscoveryResultWrapper = | ||
result match { | ||
case pkg: TestDiscoveryResult.Package => Package(pkg) | ||
case test: TestDiscoveryResult.TestClass => TestClass(test) | ||
} | ||
final case class Package private ( | ||
prefix: String, | ||
children: List[TestDiscoveryResultWrapper] | ||
) extends TestDiscoveryResultWrapper | ||
object Package { | ||
def apply(pkg: TestDiscoveryResult.Package): Package = | ||
Package( | ||
pkg.prefix, | ||
pkg.children.asScala.map(TestDiscoveryResultWrapper(_)).toList | ||
) | ||
} | ||
|
||
final case class TestClass private ( | ||
fullyQualifiedName: String, | ||
className: String | ||
) extends TestDiscoveryResultWrapper | ||
object TestClass { | ||
def apply(test: TestDiscoveryResult.TestClass): TestClass = | ||
TestClass(test.fullyQualifiedName, test.className) | ||
} | ||
} |