Skip to content

Commit

Permalink
Fix withClassName filter
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelpasterz committed Oct 12, 2020
1 parent 425e668 commit 80d7b57
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
20 changes: 14 additions & 6 deletions test_runner/src/main/kotlin/ftl/filter/TestFilters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,20 @@ object TestFilters {
}
)

private fun withClassName(classNames: List<String>): TestFilter = TestFilter(
describe = "withClassName (${classNames.joinToString(", ")})",
shouldRun = { testMethod ->
withPackageName(classNames).shouldRun(testMethod)
}
)
private fun withClassName(classNames: List<String>): TestFilter {
val splittedClassNames = classNames.map { it.split("#") }
return TestFilter(
describe = "withClassName (${classNames.joinToString(", ")})",
shouldRun = { testMethod ->
val splittedName = testMethod.testName.split("#")
splittedClassNames.any { className ->
// className.size == 1 => foo.bar.TestClass1
// className.size != 1 => foo.bar.TestClass1#testMethod1
splittedName[0] == className[0] && (className.size == 1 || splittedName[1] == className[1])
}
}
)
}

private fun withAnnotation(annotations: List<String>): TestFilter = TestFilter(
describe = "withAnnotation (${annotations.joinToString(", ")})",
Expand Down
36 changes: 36 additions & 0 deletions test_runner/src/test/kotlin/ftl/filter/TestFiltersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,42 @@ class TestFiltersTest {
assertThat(filter.shouldRun(BAR_PACKAGE)).isFalse()
assertThat(filter.shouldRun(BAR_CLASSNAME)).isTrue()
}

@Test
fun `withClassName should correctly filter classes with similar name`() {
// test-targets:
// - class foo.bar.Class1
// should filter foo.bar.Class11, foo.bar.Class101 ...
// the same is applicable for methods

val filter = fromTestTargets(
listOf(
"class anyPackage_1.anyClass_1",
"class anyPackage_3.anyClass_3#anyMethod_3"
)
)

val tests = listOf(
TargetsHelper(pack = "anyPackage_1", cl = "anyClass_1", m = "anyMethod_1", annotation = "Foo"),
TargetsHelper(pack = "anyPackage_1", cl = "anyClass_1", m = "anyMethod_2", annotation = "Foo"),
TargetsHelper(pack = "anyPackage_1", cl = "anyClass_12", m = "anyMethod_1", annotation = "Bar"),
TargetsHelper(pack = "anyPackage_1", cl = "anyClass_12", m = "anyMethod_12", annotation = "Bar"),
TargetsHelper(pack = "anyPackage_3", cl = "anyClass_3", m = "anyMethod_3", annotation = "Bar"),
TargetsHelper(pack = "anyPackage_3", cl = "anyClass_3", m = "anyMethod_32", annotation = "Bar"),
TargetsHelper(pack = "anyPackage_3", cl = "anyClass_32", m = "anyMethod_3", annotation = "Bar"),
TargetsHelper(pack = "anyPackage_3", cl = "anyClass_32", m = "anyMethod_32", annotation = "Bar")
).map { getDefaultTestMethod(it.fullView, it.annotation) }

val expected = listOf(
"anyPackage_1.anyClass_1#anyMethod_1",
"anyPackage_1.anyClass_1#anyMethod_2",
"anyPackage_3.anyClass_3#anyMethod_3"
)

val result = tests.withFilter(filter)

assertThat(result).isEqualTo(expected)
}
}

private fun getDefaultTestMethod(testName: String, annotation: String) =
Expand Down

0 comments on commit 80d7b57

Please sign in to comment.