Skip to content

Commit

Permalink
Merge branch 'develop' into feature/simulator-log
Browse files Browse the repository at this point in the history
  • Loading branch information
Malinskiy authored Mar 27, 2024
2 parents 3edc3e3 + e20eda5 commit ec5c59f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ sealed class TestFilterConfiguration {
@JsonProperty("regex") val regex: Regex? = null,
@JsonProperty("values") val values: List<String>? = null,
@JsonProperty("file") val file: File? = null,
@JsonProperty("subpackages") val subpackages: Boolean = false,
) : TestFilterConfiguration() {
override fun validate() {
var i = 0
Expand All @@ -167,6 +168,7 @@ sealed class TestFilterConfiguration {
if (!regex.toString().contentEquals(other.regex.toString())) return false
if (values != other.values) return false
if (file != other.file) return false
if (subpackages != other.subpackages) return false

return true
}
Expand All @@ -175,6 +177,7 @@ sealed class TestFilterConfiguration {
var result = regex?.hashCode() ?: 0
result = 31 * result + (values?.hashCode() ?: 0)
result = 31 * result + (file?.hashCode() ?: 0)
result = 31 * result + (subpackages.hashCode())
return result
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,15 @@ import com.malinskiy.marathon.config.TestFilterConfiguration

class TestPackageFilter(cnf: TestFilterConfiguration.TestPackageFilterConfiguration) :
SingleValueTestFilter(cnf.regex, cnf.values, cnf.file, { test, values ->
(regex?.matches(test.pkg) ?: true) && (values?.contains(test.pkg) ?: true)
})
(regex?.matches(test.pkg) ?: true) && when(cnf.subpackages) {
true -> (values?.any {
test.pkg == it ||
test.pkg.startsWith("$it$PACKAGE_SEPARATOR")
} ?: true)
false -> (values?.contains(test.pkg) ?: true)
}
}) {
companion object {
const val PACKAGE_SEPARATOR = '.'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,51 @@ import com.malinskiy.marathon.test.Test as MarathonTest

class TestPackageFilterTest {
private val simpleTest = stubTest("com.example")
private val simpleBTest = stubTest("com.example2")
private val complexTest = stubTest("com.example.subpackage")
private val someClass = stubTest("com.sample")
private val simpleClassnameFilter =
TestFilterConfiguration.TestPackageFilterConfiguration(regex = """com\.example.*""".toRegex()).toTestFilter()

val tests = listOf(
simpleTest,
complexTest,
someClass
)

@Test
fun shouldFilter() {
simpleClassnameFilter.filter(tests) shouldBeEqualTo listOf(simpleTest, complexTest)
fun shouldFilterByRegex() {
TestFilterConfiguration.TestPackageFilterConfiguration(regex = """com\.example.*""".toRegex()).toTestFilter()
.filter(tests) shouldBeEqualTo listOf(simpleTest, complexTest)
}

@Test
fun shouldFilterNotByRegex() {
TestFilterConfiguration.TestPackageFilterConfiguration(regex = """com\.example.*""".toRegex()).toTestFilter()
.filterNot(tests) shouldBeEqualTo listOf(someClass)
}

@Test
fun shouldFilterByValues() {
TestFilterConfiguration.TestPackageFilterConfiguration(values = listOf("com.example"), subpackages = false).toTestFilter().filter(tests) shouldBeEqualTo listOf(simpleTest)
}

@Test
fun shouldFilterNotByValues() {
TestFilterConfiguration.TestPackageFilterConfiguration(values = listOf("com.example"), subpackages = false).toTestFilter().filterNot(tests) shouldBeEqualTo listOf(complexTest, someClass)
}

@Test
fun shouldFilterByValuesWithSubpackages() {
TestFilterConfiguration.TestPackageFilterConfiguration(values = listOf("com.example"), subpackages = true).toTestFilter().filter(tests) shouldBeEqualTo listOf(simpleTest, complexTest)
}

@Test
fun shouldFilterByValuesWithSubpackagesByPartialPackageName() {
TestFilterConfiguration.TestPackageFilterConfiguration(values = listOf("com.example"), subpackages = true).toTestFilter().filter(listOf(simpleBTest)) shouldBeEqualTo emptyList()
}

@Test
fun shouldFilterNot() {
simpleClassnameFilter.filterNot(tests) shouldBeEqualTo listOf(someClass)
fun shouldFilterNotByValuesWithSubpackages() {
TestFilterConfiguration.TestPackageFilterConfiguration(values = listOf("com.example"), subpackages = true).toTestFilter().filterNot(tests) shouldBeEqualTo listOf(someClass)
}
}

Expand Down
17 changes: 17 additions & 0 deletions docs/runner/configuration/filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,23 @@ filteringConfiguration:
- "com.example.subpackage"
```
or utilize the package's `subpackages` field to include all subpackages for each entry:
```yaml
filteringConfiguration:
allowlist:
- type: "package"
subpackages: true
values:
- "com.example"
```

:::note

Including subpackages via `subpackages: true` works only when using values or file. It doesn't apply to configuration specified via regex.
This feature is only available in the CLI version of marathon.

:::

### Values file filtering

Or you can supply these packages via a file (be careful with the relative paths: they will be relative to the workdir of the process):
Expand Down

0 comments on commit ec5c59f

Please sign in to comment.