Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sksamuel committed Oct 2, 2022
1 parent 4815d79 commit b1cb6b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.kotest.core.test.TestCase
import io.kotest.core.test.TestResult
import io.kotest.engine.listener.TestEngineListener
import io.kotest.engine.spec.SpecExtensions
import io.kotest.engine.tags.isActive
import io.kotest.engine.tags.isPotentiallyActive
import io.kotest.engine.tags.parse
import io.kotest.engine.tags.runtimeTagExpression

Expand All @@ -27,7 +27,7 @@ class InlineTagSpecInterceptor(
fn: suspend (Spec) -> Result<Map<TestCase, TestResult>>
): Result<Map<TestCase, TestResult>> {
val alltags = spec.tags() + spec.appliedTags()
val active = projectConfiguration.runtimeTagExpression().parse().isActive(alltags)
val active = projectConfiguration.runtimeTagExpression().parse().isPotentiallyActive(alltags)
return if (active) fn(spec) else {
val reason = "Ignored due to tags in spec: ${alltags.joinToString(", ")}"
runCatching { listener.specIgnored(spec::class, reason) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,24 @@ fun Expression?.isPotentiallyActive(kclass: KClass<out Spec>, conf: ProjectConfi
val tags = kclass.tags(conf.tagInheritance)
if (tags.isEmpty()) return true

return isPotentiallyActive(tags.toSet()) ?: true
return isPotentiallyActive(tags.toSet())
}

internal fun Expression.isPotentiallyActive(tags: Set<Tag>): Boolean? {
/**
* Returns true if the given [Spec] class could contain an active test based on further tags.
* Returns false if the spec has been explicitly excluded and should not be instantiated.
*/
internal fun Expression?.isPotentiallyActive(tags: Set<Tag>): Boolean {

// nothing is excluded if the expression is null
if (this == null) return true
if (tags.isEmpty()) return true

return when (this) {
is Expression.Or -> left.isPotentiallyActive(tags) ?: true || right.isPotentiallyActive(tags) ?: true
is Expression.And -> left.isPotentiallyActive(tags) ?: true && right.isPotentiallyActive(tags) ?: true
is Expression.Not -> expr.isPotentiallyActive(tags)?.not()
is Expression.Identifier -> if (tags.map { it.name }.contains(ident)) true else null
is Expression.Or -> left.isPotentiallyActive(tags) || right.isPotentiallyActive(tags)
is Expression.And -> left.isPotentiallyActive(tags) && right.isPotentiallyActive(tags)
is Expression.Not -> !expr.isPotentiallyActive(tags)
is Expression.Identifier -> tags.map { it.name }.contains(ident)
}
}

Expand Down

0 comments on commit b1cb6b1

Please sign in to comment.