Skip to content

Commit

Permalink
Refactor + change comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelpasterz committed Oct 13, 2020
1 parent 713aabd commit ace858e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
15 changes: 9 additions & 6 deletions test_runner/src/main/kotlin/ftl/filter/TestFilters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,18 @@ object TestFilters {
)

private fun withClassName(classNames: List<String>): TestFilter {
val splittedClassNames = classNames.map { it.split("#") }
// splits foo.bar.TestClass1#testMethod1 into [foo.bar.TestClass1, testMethod1]
fun String.extractClassAndTestNames() = split("#")

val classFilters = classNames.map { it.extractClassAndTestNames() }
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])
val testMethodName = testMethod.testName.extractClassAndTestNames()
classFilters.any { filter ->
// When filter.size == 1 all test methods from the class should run therefore we do not compare method names
// When filter.size != 1 only particular test from the class should be launched and we need to compare method names as well
testMethodName[0] == filter[0] && (filter.size == 1 || testMethodName[1] == filter[1])
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ internal fun InstrumentationTestContext.getFlankTestMethods(
.filter(testFilter.shouldRun)
.filterNot(parameterizedClasses::belong)
.map(TestMethod::toFlankTestMethod).toList()
.plus(parameterizedClasses
.filter { testFilter.shouldRun(TestMethod(it, emptyList())) }
.map(String::toFlankTestMethod))
.plus(parameterizedClasses.onlyShouldRun(testFilter))
}

private fun List<String>.belong(method: TestMethod) = any { className -> method.testName.startsWith(className) }

private fun List<String>.onlyShouldRun(filter: TestFilter) = this
.filter { filter.shouldRun(TestMethod(it, emptyList())) }
.map { FlankTestMethod("class $it", ignored = false, isParameterizedClass = true) }

private fun TestMethod.toFlankTestMethod() = FlankTestMethod(
testName = "class $testName",
ignored = annotations.any { it.name in ignoredAnnotations }
Expand All @@ -88,8 +90,6 @@ private val ignoredAnnotations = listOf(
"android.support.test.filters.Suppress"
)

private fun String.toFlankTestMethod() = FlankTestMethod("class $this", ignored = false, isParameterizedClass = true)

@VisibleForTesting
internal fun InstrumentationTestContext.getParametrizedClasses(): List<String> =
DexParser.readDexFiles(test.local).fold(emptyList()) { accumulator, file: DexFile ->
Expand Down

0 comments on commit ace858e

Please # to comment.