Reputation: 842
It is easy to get all instances of TestDefinition
in IntegrationTest
:
val tests: Seq[TestDefinition] = (definedTests in IntegrationTest).value
But how do I get all instances of xsbti.api.Definition
in IntegrationTest
? It used to be possible to do this:
val defs: Seq[Definition] = {
val analysis = (compile in IntegrationTest).value
analysis.apis.internal.values.flatMap(_.source.api.definitions)
}
(for example, for filtering tests based on the suite annotations: say, @RequiresCassandra
or @RequiresCluster
and so on). But analysis.apis
has been removed--not sure when, but it's absent in SBT 1.3.8. I haven't found any documentation on what to use instead.
One of SBT's chief strengths, compared to such XML-based tools like Maven, is the ability to define build settings programmatically. It should be possible to filter tests based on anything in the test code itself, not only on test names. I can't believe something so useful—something that really places SBT above competitors—could be just removed.
Any suggestions?
Upvotes: 2
Views: 92
Reputation: 48410
Tests.allDefs
returns Definition
s given CompileAnalysis
. For example,
val analysis: CompileAnalysis = (compile in IntegrationTest).value
val definitions: Seq[Definition] = Tests.allDefs(analysis)
val annotations: Seq[Annotation] = definitions.flatMap(_.annotations())
There was a change back in 2016 from
val compile = TaskKey[Analysis]("compile", "Compiles sources.", APlusTask)
to
val compile = TaskKey[CompileAnalysis]("compile", "Compiles sources.", APlusTask)
where
trait Analysis extends CompileAnalysis {
...
val apis: APIs
...
}
so now we have to cast to Analysis
analysis match { case analysis: Analysis => ... }
which is what allDefs
does.
Upvotes: 2